The decode-unit and encode-unit methods should be static methods which can be called without an active instance. But decode-unit has to insert the bus number in phys.hi which is available when the device node is created. Instead of trying to get the bus-range property of the current device, which fails if this method is called from a different package, add a small forth wrapper that adds the bus number so the C function does not need to care about it.
Signed-off-by: BALATON Zoltan balaton@eik.bme.hu --- Found how to move eval to is-pci-bus so this supersedes the previous version.
drivers/pci.c | 10 ++++------ drivers/pci.fs | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/pci.c b/drivers/pci.c index 55b959c..28e7321 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -182,7 +182,6 @@ ob_pci_decode_unit(int *idx) ucell hi, mid, lo; const char *arg = pop_fstr_copy(); int dev, fn, reg, ss, n, p, t; - int bus, len; char *ptr;
PCI_DPRINTF("ob_pci_decode_unit idx=%p\n", idx); @@ -274,9 +273,7 @@ ob_pci_decode_unit(int *idx) } free((char*)arg);
- bus = get_int_property(get_cur_dev(), "bus-range", &len); - - hi = n | p | t | (ss << 24) | (bus << 16) | (dev << 11) | (fn << 8) | reg; + hi = n | p | t | (ss << 24) | (dev << 11) | (fn << 8) | reg;
PUSH(lo); PUSH(mid); @@ -412,7 +409,7 @@ ob_pci_bus_map_in(int *idx) }
NODE_METHODS(ob_pci_bus_node) = { - { "decode-unit", ob_pci_decode_unit }, + { "pci-decode-unit", ob_pci_decode_unit }, { "encode-unit", ob_pci_encode_unit }, { "pci-map-in", ob_pci_bus_map_in }, }; @@ -427,7 +424,7 @@ ob_pci_bridge_map_in(int *idx) }
NODE_METHODS(ob_pci_bridge_node) = { - { "decode-unit", ob_pci_decode_unit }, + { "pci-decode-unit", ob_pci_decode_unit }, { "encode-unit", ob_pci_encode_unit }, { "pci-map-in", ob_pci_bridge_map_in }, }; @@ -1772,6 +1769,7 @@ static phandle_t ob_configure_pci_device(const char* parent_path, } else { BIND_NODE_METHODS(phandle, ob_pci_bus_node); } + PUSH(*bus_num); fword("is-pci-bus"); break; } diff --git a/drivers/pci.fs b/drivers/pci.fs index 3c3752e..52d956a 100644 --- a/drivers/pci.fs +++ b/drivers/pci.fs @@ -38,7 +38,8 @@ ;
\ Install methods for a pci bus node -: is-pci-bus +: is-pci-bus ( bus-num -- ) + s" : decode-unit pci-decode-unit lbsplit nip ( bus-num ) literal swap bljoin ; " evaluate \ 'is-open' will be called by pci.c " dma-alloc" is-call-parent " dma-free" is-call-parent