summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board-qemu/slof/pci-phb.fs3
-rw-r--r--lib/libusb/usb-core.c2
-rw-r--r--lib/libusb/usb-ehci.c65
-rw-r--r--slof/allocator.c2
-rw-r--r--slof/fs/alloc-mem-debug.fs2
-rw-r--r--slof/fs/alloc-mem.fs65
6 files changed, 124 insertions, 15 deletions
diff --git a/board-qemu/slof/pci-phb.fs b/board-qemu/slof/pci-phb.fs
index 4b002c6..db04f58 100644
--- a/board-qemu/slof/pci-phb.fs
+++ b/board-qemu/slof/pci-phb.fs
@@ -12,7 +12,7 @@
\ PAPR PCI host bridge.
-0 VALUE phb-debug?
+1 VALUE phb-debug?
." Populating " pwd cr
@@ -92,6 +92,7 @@ setup-puid
dup fff and IF
." Warning: dma-alloc got unaligned memory!" cr
THEN
+ phb-debug? IF cr ." dma-alloc returned: " .s cr THEN
;
: dma-free ( virt size -- )
diff --git a/lib/libusb/usb-core.c b/lib/libusb/usb-core.c
index 6c40913..82cf887 100644
--- a/lib/libusb/usb-core.c
+++ b/lib/libusb/usb-core.c
@@ -14,7 +14,7 @@
#include "usb-core.h"
#undef DEBUG
-//#define DEBUG
+#define DEBUG
#ifdef DEBUG
#define dprintf(_x ...) printf(_x)
#else
diff --git a/lib/libusb/usb-ehci.c b/lib/libusb/usb-ehci.c
index d38690c..662c2d2 100644
--- a/lib/libusb/usb-ehci.c
+++ b/lib/libusb/usb-ehci.c
@@ -18,13 +18,52 @@
#include "paflof.h"
#undef EHCI_DEBUG
-//#define EHCI_DEBUG
+#define EHCI_DEBUG
#ifdef EHCI_DEBUG
#define dprintf(_x ...) printf(_x)
#else
#define dprintf(_x ...)
#endif
+static void __dma_map_out_t(const char *f, int l, long address, void *devaddr, long size)
+{
+ printf("!%s! %s %u: %lx -> %p (%lu bytes)\n", __func__, f, l, address, devaddr, size);
+ SLOF_dma_map_out(address, devaddr, size);
+}
+#define SLOF_dma_map_out(a, b, c) __dma_map_out_t(__func__, __LINE__, (a), (b), (c))
+
+static long __dma_map_in(const char *f, int l, void *virt, long size, int cacheable)
+{
+ long ret = SLOF_dma_map_in(virt, size, cacheable);
+ printf("!%s! %s %u: %p -> %lx (%lu bytes) c=%u\n", __func__, f, l, virt, ret, size, cacheable);
+ return ret;
+}
+#define SLOF_dma_map_in(v, s, c) __dma_map_in(__func__, __LINE__, (v), (s), (c))
+
+static void *__dma_alloc(const char *f, int l, long size)
+{
+ void *ret = SLOF_dma_alloc(size);
+ printf("!%s! %s %u: %p (%lu bytes)\n", __func__, f, l, ret, size);
+ return ret;
+}
+#define SLOF_dma_alloc(s) __dma_alloc(__func__, __LINE__, (s))
+
+static void *__alloc_mem(const char *f, int l, long size)
+{
+ void *ret = SLOF_alloc_mem(size);
+ printf("!%s! %s %u: %p (%lu bytes)\n", __func__, f, l, ret, size);
+ return ret;
+}
+#define SLOF_alloc_mem(s) __alloc_mem(__func__, __LINE__, (s))
+
+static void *__alloc_mem_aligned(const char *f, int l, long align, long size)
+{
+ void *ret = SLOF_alloc_mem_aligned(align, size);
+ printf("!%s! %s %u: %p (%lu bytes, %lu align)\n", __func__, f, l, ret, size, align);
+ return ret;
+}
+#define SLOF_alloc_mem_aligned(a, s) __alloc_mem_aligned(__func__, __LINE__, (a), (s))
+
#ifdef EHCI_DEBUG
static void dump_ehci_regs(struct ehci_hcd *ehcd)
{
@@ -38,7 +77,8 @@ static void dump_ehci_regs(struct ehci_hcd *ehcd)
dprintf("\n - HCIVERSION %04X", read_reg16(&cap_regs->hciversion));
dprintf("\n - HCSPARAMS %08X", read_reg32(&cap_regs->hcsparams));
dprintf("\n - HCCPARAMS %08X", read_reg32(&cap_regs->hccparams));
- dprintf("\n - HCSP_PORTROUTE %016llX", read_reg64(&cap_regs->portroute));
+ //dprintf("\n - HCSP_PORTROUTE32 %08X", read_reg32(&cap_regs->portroute));
+ //dprintf("\n - HCSP_PORTROUTE %016llX", read_reg64(&cap_regs->portroute));
dprintf("\n");
dprintf("\n - USBCMD %08X", read_reg32(&op_regs->usbcmd));
@@ -96,12 +136,19 @@ static int ehci_hcd_init(struct ehci_hcd *ehcd)
int i;
long fl_phys = 0, qh_intr_phys = 0, qh_async_phys;
+ SLOF_dma_alloc(0x1000);
+
/* Reset the host controller */
time = SLOF_GetTimer() + 250;
usbcmd = read_reg32(&ehcd->op_regs->usbcmd);
write_reg32(&ehcd->op_regs->usbcmd, (usbcmd & ~(CMD_PSE | CMD_ASE)) | CMD_HCRESET);
- while (time > SLOF_GetTimer())
+ while (time > SLOF_GetTimer()) {
+// SLOF_dma_alloc(0x1000);
cpu_relax();
+ }
+
+ SLOF_dma_alloc(0x1000);
+
usbcmd = read_reg32(&ehcd->op_regs->usbcmd);
if (usbcmd & CMD_HCRESET) {
printf("usb-ehci: reset failed\n");
@@ -232,13 +279,21 @@ static void ehci_init(struct usb_hcd_dev *hcidev)
printf(" EHCI: Initializing\n");
dprintf("%s: device base address %p\n", __func__, hcidev->base);
- ehcd = SLOF_alloc_mem(sizeof(*ehcd));
+ SLOF_alloc_mem(0x10);
+ SLOF_alloc_mem(0x100);
+ SLOF_alloc_mem(0x1000);
+ SLOF_alloc_mem(0x1000);
+ SLOF_dma_alloc(0x1000);
+
+ ehcd = SLOF_alloc_mem(0x1000);//sizeof(*ehcd));
if (!ehcd) {
printf("usb-ehci: Unable to allocate memory\n");
return;
}
memset(ehcd, 0, sizeof(*ehcd));
+ SLOF_dma_alloc(0x1000);
+
hcidev->nextaddr = 1;
hcidev->priv = ehcd;
ehcd->hcidev = hcidev;
@@ -246,6 +301,8 @@ static void ehci_init(struct usb_hcd_dev *hcidev)
ehcd->op_regs = (struct ehci_op_regs *)(hcidev->base +
read_reg8(&ehcd->cap_regs->caplength));
#ifdef EHCI_DEBUG
+ SLOF_dma_alloc(0x1000);
+
dump_ehci_regs(ehcd);
#endif
ehci_hcd_init(ehcd);
diff --git a/slof/allocator.c b/slof/allocator.c
index 279b50b..6528934 100644
--- a/slof/allocator.c
+++ b/slof/allocator.c
@@ -19,7 +19,7 @@
#include <helpers.h>
#undef DEBUG
-//#define DEBUG
+#define DEBUG
#ifdef DEBUG
#define dprintf(_x ...) do { printf ("%s: ", __func__); printf(_x); } while (0);
#else
diff --git a/slof/fs/alloc-mem-debug.fs b/slof/fs/alloc-mem-debug.fs
index d4ca70b..da885f4 100644
--- a/slof/fs/alloc-mem-debug.fs
+++ b/slof/fs/alloc-mem-debug.fs
@@ -102,7 +102,7 @@ malloced-blocks max-malloced-blocks 2 * cells erase
\ Enable these for verbose debug messages:
-#if 0
+#if 1
: alloc-mem
cr ." alloc-mem with len=" dup .
alloc-mem
diff --git a/slof/fs/alloc-mem.fs b/slof/fs/alloc-mem.fs
index 59381a7..a8c811f 100644
--- a/slof/fs/alloc-mem.fs
+++ b/slof/fs/alloc-mem.fs
@@ -28,16 +28,67 @@ heads (max-heads#) cells erase
\ Allocate a memory block
: alloc-mem ( len -- a-addr )
- dup 0= IF EXIT THEN
+ ." alloc-mem IN " dup . ." heap " heap-start . ." .." heap-end . ." maxh#=" (max-heads#) . cr
+ d# __LINE__ .d ." : " .s cr
+ dup 0= IF
+ ." alloc-mem RET1 " dup . cr
+ EXIT
+ THEN
+ d# __LINE__ .d ." : " .s cr
1 over log2 3 max ( len 1 log_len )
- dup (max-heads#) >= IF cr ." Out of internal memory." cr 3drop 0 EXIT THEN
+ dup (max-heads#) >= IF
+ cr ." Out of internal memory." cr
+ 3drop 0
+ ." alloc-mem RET2 " dup . cr
+ EXIT
+ THEN
+
+ d# __LINE__ .d ." : " .s cr
lshift >r ( len R: 1<<log_len )
- size>head dup @ IF
- dup @ dup >r @ swap ! r> r> drop EXIT
+ size>head
+ d# __LINE__ .d ." : " .s cr
+ dup
+ @
+ d# __LINE__ .d ." : " .s cr
+ IF
+ dup @
+ dup >r @
+ swap !
+ r> r>
+ drop
+ d# __LINE__ .d ." : " .s cr
+ ." alloc-mem RET3 " dup . cr
+ EXIT
THEN ( headptr R: 1<<log_len)
- r@ 2* recurse dup ( headptr a-addr2 a-addr2 R: 1<<log_len)
- dup 0= IF r> 2drop 2drop 0 EXIT THEN
- r> + >r 0 over ! swap ! r>
+
+ r@
+ d# __LINE__ .d ." : " .s cr
+ 2*
+ ." (rec) "
+ d# __LINE__ .d ." : " .s cr
+ recurse
+ dup ( headptr a-addr2 a-addr2 R: 1<<log_len)
+ d# __LINE__ .d ." : " .s cr
+ dup 0= IF
+ r>
+ 2drop
+ 2drop
+ 0
+ d# __LINE__ .d ." : " .s cr
+ ." alloc-mem RET4 " dup . cr
+ EXIT
+ THEN
+ r>
+ d# __LINE__ .d ." : " .s cr
+ +
+ >r
+ 0
+ d# __LINE__ .d ." : " .s cr
+ over !
+ swap !
+ r>
+ d# __LINE__ .d ." : " .s cr
+ ." alloc-mem RET5 " dup . cr
;