diff --git a/config/examples/ppc_config.xml b/config/examples/ppc_config.xml
index 19dc043..d720d7d 100644
--- a/config/examples/ppc_config.xml
+++ b/config/examples/ppc_config.xml
@@ -68,7 +68,7 @@
-
+
diff --git a/drivers/pci.c b/drivers/pci.c
index 4bc02c9..df078e9 100644
--- a/drivers/pci.c
+++ b/drivers/pci.c
@@ -141,11 +141,15 @@ static void dump_reg_property(const char* description, int nreg, u32 *reg)
static unsigned long pci_bus_addr_to_host_addr(int space, uint32_t ba)
{
- if (space == IO_SPACE) {
+ PCI_DPRINTF("%s space=%d ba=0x%"PRIx32"\n", __func__, space, ba);
+ switch (space) {
+ case CONFIGURATION_SPACE:
+ return arch->cfg_addr;
+ case IO_SPACE:
return arch->io_base + (unsigned long)ba;
- } else if (space == MEMORY_SPACE_32) {
+ case MEMORY_SPACE_32:
return arch->host_pci_base + (unsigned long)ba;
- } else {
+ default:
/* Return unaltered to aid debugging property values */
return (unsigned long)ba;
}
@@ -376,7 +380,7 @@ static ucell ob_pci_map(uint32_t ba, ucell size) {
phys = pci_bus_addr_to_host_addr(space_code,
ba & ~mask);
-
+ PCI_DPRINTF("%s: phys=0x"FMT_plx" size="FMT_ucell"\n", __func__, phys, size);
#if defined(CONFIG_OFMEM)
ofmem_claim_phys(phys, size, 0);
@@ -408,20 +412,10 @@ static void ob_pci_unmap(ucell virt, ucell size) {
static void
ob_pci_bus_map_in(int *idx)
{
- uint32_t ba;
- ucell size;
- ucell virt;
-
PCI_DPRINTF("ob_pci_bar_map_in idx=%p\n", idx);
-
- size = POP();
- POP();
- POP();
- ba = POP();
-
- virt = ob_pci_map(ba, size);
-
- PUSH(virt);
+ fword(".s");
+ fword("pci-map-in");
+ fword(".s");
}
static void
@@ -459,7 +453,7 @@ NODE_METHODS(ob_pci_bus_node) = {
{ "close", ob_pci_close },
{ "decode-unit", ob_pci_decode_unit },
{ "encode-unit", ob_pci_encode_unit },
- { "pci-map-in", ob_pci_bus_map_in },
+ { "map-in", ob_pci_bus_map_in },
{ "dma-alloc", ob_pci_dma_alloc },
{ "dma-free", ob_pci_dma_free },
{ "dma-map-in", ob_pci_dma_map_in },
@@ -473,7 +467,7 @@ static void
ob_pci_bridge_map_in(int *idx)
{
/* As per the IEEE-1275 PCI specification, chain up to the parent */
- call_parent_method("pci-map-in");
+ call_parent_method("map-in");
}
NODE_METHODS(ob_pci_bridge_node) = {
@@ -481,7 +475,7 @@ NODE_METHODS(ob_pci_bridge_node) = {
{ "close", ob_pci_close },
{ "decode-unit", ob_pci_decode_unit },
{ "encode-unit", ob_pci_encode_unit },
- { "pci-map-in", ob_pci_bridge_map_in },
+ { "map-in", ob_pci_bridge_map_in },
{ "dma-alloc", ob_pci_dma_alloc },
{ "dma-free", ob_pci_dma_free },
{ "dma-map-in", ob_pci_dma_map_in },
diff --git a/drivers/pci.fs b/drivers/pci.fs
index a7b56e1..98956a9 100644
--- a/drivers/pci.fs
+++ b/drivers/pci.fs
@@ -37,4 +37,44 @@
then
;
+: pci-map-in ( addr.lo addr.mid addr.hi size -- virt )
+ \ Ignore everything but addr.hi and find assigned addr for BAR
+ drop nip nip
+ my-self swap \ Save my-self and set it to 0 because decode-phys below
+ 0 to my-self \ seems to be confused by it. This should not be needed
+ " assigned-addresses" active-package get-package-property 0= if
+ begin
+ decode-phys ( bar prop prop-len phys.lo phys.mid phys.hi )
+ dup 0fffffff and 6 pick 0fffffff and = if
+ 2drop -rot
+ decode-int drop decode-int drop 2drop
+ ( bar addr.lo )
+ \ Now translate addr.lo, FIXME this is wrong
+ \ maybe we should look at parent's ranges instead?
+ over 18 rshift 3 and 1 = if
+ " reg" active-package parent get-package-property 0= if
+ ( bar addr.lo prop prop-len reg.addr reg.size )
+ decode-int -rot decode-int 3drop
+ +
+ then
+ then
+ nip swap to my-self
+ exit
+ else
+ 3drop \ no match, try next
+ then
+ \ Drop the size as we don't need it
+ decode-int drop decode-int drop
+ dup 0=
+ until
+ 3drop
+ to my-self
+ -1 \ not found
+ else
+ drop
+ to my-self
+ -1 \ could not find assigned-addresses
+ then
+ ;
+
[THEN]
diff --git a/drivers/vga.fs b/drivers/vga.fs
index 53dcff0..f3ffda7 100644
--- a/drivers/vga.fs
+++ b/drivers/vga.fs
@@ -146,14 +146,14 @@ defer vbe-iow!
: map-fb ( -- )
cfg-bar0 pci-bar>pci-addr if \ ( pci-addr.lo pci-addr.mid pci-addr.hi size )
- " pci-map-in" $call-parent
+ " map-in" $call-parent
to fb-addr
then
;
: map-mmio ( -- )
cfg-bar2 pci-bar>pci-addr if \ ( pci-addr.lo pci-addr.mid pci-addr.hi size )
- " pci-map-in" $call-parent
+ " map-in" $call-parent
to mmio-addr
then
;
diff --git a/forth/device/other.fs b/forth/device/other.fs
index 1bed9b8..0ff34b6 100644
--- a/forth/device/other.fs
+++ b/forth/device/other.fs
@@ -58,21 +58,27 @@ defer (poke)
\ 5.3.7.2 Device-register access
: rb@ ( addr -- byte )
+ ioc@
;
: rw@ ( waddr -- w )
+ iow@
;
: rl@ ( qaddr -- quad )
+ iol@
;
: rb! ( byte addr -- )
+ ioc!
;
: rw! ( w waddr -- )
+ iow!
;
: rl! ( quad qaddr -- )
+ iol!
;
: rx@ ( oaddr - o )
diff --git a/forth/util/pci.fs b/forth/util/pci.fs
index 57ded62..fc2675e 100644
--- a/forth/util/pci.fs
+++ b/forth/util/pci.fs
@@ -86,7 +86,11 @@ hex
drop
cr cr
;
-
+
+: config-b! pci-c! ; : config-b@ pci-c@ ;
+: config-b! pci-w! ; : config-b@ pci-w@ ;
+: config-b! pci-l! ; : config-b@ pci-l@ ;
+
\ : test-pci
\ 0 2 0 dump-pci-device
\ ;