From e3850e3c60ac379edf9d6fad436eeeca5718aa3a Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 16 Sep 2009 05:47:29 +0200 Subject: [PATCH] attempt to get some TDs through the HC -> fail :( --- bootmii_ppc.h | 1 + usb/core/core.c | 4 +++ usb/host/ohci.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++- usb/host/ohci.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) diff --git a/bootmii_ppc.h b/bootmii_ppc.h index b5210f8..4f69d44 100644 --- a/bootmii_ppc.h +++ b/bootmii_ppc.h @@ -118,6 +118,7 @@ void exception_init(void); void gecko_init(void); int printf(const char *fmt, ...); +void hexdump(void *d, int len); // Debug: blink the tray led. diff --git a/usb/core/core.c b/usb/core/core.c index e3dffb2..94abe68 100644 --- a/usb/core/core.c +++ b/usb/core/core.c @@ -107,7 +107,10 @@ usb_device *usb_add_device() * GET Descriptor Request, when device address = 0 */ usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, 64, buf, 8, 0); + printf("===========\nafter usb control msg:\n"); + hexdump(buf, sizeof(buf)); +#if 0 dev->bMaxPacketSize0 = (u8) buf[7] ? (u8) buf[7] : 1; //dirty? /* setup real ep0 fifo size */ devdescr_size = (u8) buf[0]; /* save real length of device descriptor */ @@ -155,6 +158,7 @@ usb_device *usb_add_device() list_add_tail(core.devices, tmp); usb_probe_driver(); +#endif return dev; } diff --git a/usb/host/ohci.c b/usb/host/ohci.c index 35fb456..0dea4b1 100644 --- a/usb/host/ohci.c +++ b/usb/host/ohci.c @@ -13,10 +13,36 @@ Copyright (C) 2009 Sebastian Falbesoner #include "../../hollywood.h" #include "../../irq.h" #include "../../string.h" +#include "../../malloc.h" #include "ohci.h" #include "host.h" static struct ohci_hcca hcca_oh0; +static struct endpoint_descriptor *dummyconfig; + +static struct endpoint_descriptor *allocate_endpoint() +{ + struct endpoint_descriptor *ep; + ep = (struct endpoint_descriptor *)calloc(sizeof(struct endpoint_descriptor), 16); + ep->flags = OHCI_ENDPOINT_GENERAL_FORMAT; + ep->headp = ep->tailp = ep->nexted = 0; + return ep; +} + +static struct general_td *allocate_general_td(size_t bsize) +{ + struct general_td *td; + td = (struct general_td *)calloc(sizeof(struct general_td), 16); + td->flags = 0; + td->nexttd = 0; + if(bsize == 0) { + td->cbp = td->be = 0; + } else { + td->cbp = (u32)malloc(bsize); + td->be = td->cbp + bsize - 1; + } + return td; +} static void dbg_op_state() { @@ -41,6 +67,45 @@ static void dbg_op_state() * Enqueue a transfer descriptor. */ u8 hcdi_enqueue(usb_transfer_descriptor *td) { + printf("===========================\ndone head (vor sync): 0x%08X\n", hcca_oh0.done_head); + sync_before_read(&hcca_oh0, 256); + printf("done head (nach sync): 0x%08X\n", hcca_oh0.done_head); + + struct general_td *tmptd = allocate_general_td(sizeof(td->buffer)); + (void) memcpy((void*) tmptd->cbp, td->buffer, sizeof(td->buffer)); + + printf("tmptd hexump (before):\n"); + hexdump((void*) tmptd, sizeof(tmptd)); + printf("tmptd-cbp hexump (before):\n"); + hexdump((void*) (tmptd->cbp), sizeof(tmptd->cbp)); + + sync_after_write((void*) (tmptd->cbp), sizeof(tmptd->cbp)); + sync_after_write(tmptd, sizeof(tmptd)); + + dummyconfig->headp = virt_to_phys(tmptd); + sync_after_write(dummyconfig, 64); + + printf("+++++++++++++++++++++++++++++\n"); + udelay(2000); + udelay(2000); + udelay(2000); + udelay(2000); + udelay(2000); + udelay(2000); + udelay(2000); + udelay(2000); + + sync_before_read(tmptd, sizeof(tmptd)); + printf("tmptd hexump (after):\n"); + hexdump((void*) tmptd, sizeof(tmptd)); + + sync_before_read((void*) (tmptd->cbp), sizeof(tmptd->cbp)); + printf("tmptd-cbp hexump (after):\n"); + hexdump((void*) (tmptd->cbp), sizeof(tmptd->cbp)); + + printf("done head (vor sync): 0x%08X\n", hcca_oh0.done_head); + sync_before_read(&hcca_oh0, 256); + printf("done head (nach sync): 0x%08X\n", hcca_oh0.done_head); return 0; } @@ -53,6 +118,7 @@ u8 hcdi_dequeue(usb_transfer_descriptor *td) { void hcdi_init() { + dummyconfig = allocate_endpoint(); printf("ohci-- init\n"); dbg_op_state(); @@ -91,7 +157,8 @@ void hcdi_init() /* Tell the controller where the control and bulk lists are * The lists are empty now. */ - write32(OHCI0_HC_CTRL_HEAD_ED, 0); + sync_after_write(dummyconfig, 64); + write32(OHCI0_HC_CTRL_HEAD_ED, virt_to_phys(dummyconfig)); write32(OHCI0_HC_BULK_HEAD_ED, 0); /* set hcca adress */ diff --git a/usb/host/ohci.h b/usb/host/ohci.h index cbbc457..f240978 100644 --- a/usb/host/ohci.h +++ b/usb/host/ohci.h @@ -136,5 +136,75 @@ struct ohci_hcca { u8 what [4]; /* spec only identifies 252 bytes :) */ } ALIGNED(256); +struct endpoint_descriptor { + u32 flags; + u32 tailp; + u32 headp; + u32 nexted; +} ALIGNED(16); + +#define OHCI_ENDPOINT_ADDRESS_MASK 0x0000007f +#define OHCI_ENDPOINT_GET_DEVICE_ADDRESS(s) ((s) & 0x7f) +#define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s) (s) +#define OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(s) (((s) >> 7) & 0xf) +#define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s) ((s) << 7) +#define OHCI_ENDPOINT_DIRECTION_MASK 0x00001800 +#define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR 0x00000000 +#define OHCI_ENDPOINT_DIRECTION_OUT 0x00000800 +#define OHCI_ENDPOINT_DIRECTION_IN 0x00001000 +#define OHCI_ENDPOINT_LOW_SPEED 0x00002000 +#define OHCI_ENDPOINT_FULL_SPEED 0x00000000 +#define OHCI_ENDPOINT_SKIP 0x00004000 +#define OHCI_ENDPOINT_GENERAL_FORMAT 0x00000000 +#define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT 0x00008000 +#define OHCI_ENDPOINT_MAX_PACKET_SIZE_MASK (0x7ff << 16) +#define OHCI_ENDPOINT_GET_MAX_PACKET_SIZE(s) (((s) >> 16) & 0x07ff) +#define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s) ((s) << 16) +#define OHCI_ENDPOINT_HALTED 0x00000001 +#define OHCI_ENDPOINT_TOGGLE_CARRY 0x00000002 +#define OHCI_ENDPOINT_HEAD_MASK 0xfffffffc + + +struct general_td { + u32 flags; + u32 cbp; + u32 nexttd; + u32 be; +} ALIGNED(16); + +#define OHCI_TD_BUFFER_ROUNDING 0x00040000 +#define OHCI_TD_DIRECTION_PID_MASK 0x00180000 +#define OHCI_TD_DIRECTION_PID_SETUP 0x00000000 +#define OHCI_TD_DIRECTION_PID_OUT 0x00080000 +#define OHCI_TD_DIRECTION_PID_IN 0x00100000 +#define OHCI_TD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) +#define OHCI_TD_SET_DELAY_INTERRUPT(x) ((x) << 21) +#define OHCI_TD_INTERRUPT_MASK 0x00e00000 +#define OHCI_TD_TOGGLE_CARRY 0x00000000 +#define OHCI_TD_TOGGLE_0 0x02000000 +#define OHCI_TD_TOGGLE_1 0x03000000 +#define OHCI_TD_TOGGLE_MASK 0x03000000 +#define OHCI_TD_GET_ERROR_COUNT(x) (((x) >> 26) & 3) +#define OHCI_TD_GET_CONDITION_CODE(x) ((x) >> 28) +#define OHCI_TD_SET_CONDITION_CODE(x) ((x) << 28) +#define OHCI_TD_CONDITION_CODE_MASK 0xf0000000 + +#define OHCI_TD_INTERRUPT_IMMEDIATE 0x00 +#define OHCI_TD_INTERRUPT_NONE 0x07 + +#define OHCI_TD_CONDITION_NO_ERROR 0x00 +#define OHCI_TD_CONDITION_CRC_ERROR 0x01 +#define OHCI_TD_CONDITION_BIT_STUFFING 0x02 +#define OHCI_TD_CONDITION_TOGGLE_MISMATCH 0x03 +#define OHCI_TD_CONDITION_STALL 0x04 +#define OHCI_TD_CONDITION_NO_RESPONSE 0x05 +#define OHCI_TD_CONDITION_PID_CHECK_FAILURE 0x06 +#define OHCI_TD_CONDITION_UNEXPECTED_PID 0x07 +#define OHCI_TD_CONDITION_DATA_OVERRUN 0x08 +#define OHCI_TD_CONDITION_DATA_UNDERRUN 0x09 +#define OHCI_TD_CONDITION_BUFFER_OVERRUN 0x0c +#define OHCI_TD_CONDITION_BUFFER_UNDERRUN 0x0d +#define OHCI_TD_CONDITION_NOT_ACCESSED 0x0f + #endif -- 2.25.1