X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=usb%2Fcore%2Fcore.c;h=a6c84fb2a7dd13aa3409feb94592fa69071052a1;hb=34b9e07b8eafbaef3c81dd850cdaee8610efa1f1;hp=5583c751629ab5b3b49f88a1064c219b33c88b24;hpb=6dfbb32b3c0be5f9a47fb094f378d76f53b0b4b2;p=ppcskel.git diff --git a/usb/core/core.c b/usb/core/core.c index 5583c75..a6c84fb 100644 --- a/usb/core/core.c +++ b/usb/core/core.c @@ -31,8 +31,17 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader. + plugmii core + +Copyright (C) 2009 Bernhard Urban +Copyright (C) 2009 Sebastian Falbesoner + +# This code is licensed to you under the terms of the GNU GPL, version 2; +# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +*/ -//#include #include "core.h" #include "../host/host.h" #include "usb.h" @@ -45,12 +54,12 @@ /** * Initialize USB stack. */ -void usb_init() +void usb_init(u32 reg) { core.drivers = list_create(); core.devices = list_create(); core.nextaddress = 1; - hcdi_init(); + hcdi_init(reg); } /** @@ -86,15 +95,19 @@ void usb_periodic() * for the core. usb_add_device expected that * the device answers to address zero. */ -struct usb_device *usb_add_device() +struct usb_device *usb_add_device(u8 lowspeed, u32 reg) { struct usb_device *dev = (struct usb_device *) malloc(sizeof(struct usb_device)); dev->conf = (struct usb_conf *) malloc(sizeof(struct usb_conf)); dev->address = 0; - /* send at first time only 8 bytes */ - dev->bMaxPacketSize0 = 8; + dev->fullspeed = lowspeed ? 0 : 1; + /* send at first time only 8 bytes for lowspeed devices + * 64 bytes for fullspeed + */ + dev->bMaxPacketSize0 = lowspeed ? 8 : 64; + dev->ohci = reg; - dev->epSize[0] = 64; + dev->epSize[0] = 8; dev->epSize[1] = 64; dev->epSize[2] = 64; @@ -102,207 +115,151 @@ struct usb_device *usb_add_device() dev->epTogl[1] = 0; dev->epTogl[2] = 0; -#define LEN 128 - u8 buf[LEN]; - memset(buf, 0, sizeof(buf)); - s8 ret; - memset(buf, 0, sizeof(buf)); - ret = usb_get_desc_dev_simple(dev, buf, sizeof(buf)); -#ifdef _DU_CORE_ADD - printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc_simple(ret: %d):\n", buf, ret); - hexdump(buf, sizeof(buf)); -#endif + ret = usb_get_desc_dev_simple(dev); if(ret < 0) { return (void*) -1; } - /* set MaxPacketSize */ - +//#define WTF +#ifdef WTF + volatile u8 wzf = 11; + if(0 == wzf) { + printf("WTF WTF WTF WTF padding??? WTFWTF WTF\n"); + printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF TF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF WTF TF WTF padding??? WTF WTWTF\n"); + printf("TF WTF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF WTF WTF WT padding??? WTF WF WTF\n"); + printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF WTF WTF WTF padding??? WT WTF WTF\n"); + printf("WTF WTF WTF WTF pdding??? WTF WTF WTF\n"); + printf("WTF WTF WTF WTF paddin??? WTF WTF WTF\n"); + printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF WTF WTF WTF padding?? WT WTF WTF\n"); + printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n"); + printf("WTF WTF WTF WTF padding??? WTFWTF WTF\n"); + } +#endif u8 address = usb_next_address(); ret = usb_set_address(dev, address); dev->address = address; -#ifdef _DU_CORE_ADD printf("set address to %d\n", dev->address); -#endif - - memset(buf, 0, sizeof(buf)); - ret = usb_get_desc_dev(dev, buf, sizeof(buf)); -#ifdef _DU_CORE_ADD - printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc(ret: %d):\n", buf, ret); - hexdump(buf, sizeof(buf)); -#endif - - char *man, *prod, *serial; - if(dev->iManufacturer) { - memset(buf, 0, sizeof(buf)); - man = usb_get_string_simple(dev, dev->iManufacturer, buf, sizeof(buf)); - } else { - man = (char*) malloc(11); - memset(man, '\0', sizeof(man)); - strlcpy(man, "no String", 10); - } - if(dev->iProduct) { - memset(buf, 0, sizeof(buf)); - prod = usb_get_string_simple(dev, dev->iProduct, buf, sizeof(buf)); - } else { - prod = (char*) malloc(11); - memset(prod, '\0', sizeof(prod)); - strlcpy(prod, "no String", 10); - } - if(dev->iSerialNumber) { - memset(buf, 0, sizeof(buf)); - serial = usb_get_string_simple(dev, dev->iSerialNumber, buf, sizeof(buf)); - } else { - serial = (char*) malloc(11); - memset(serial, '\0', sizeof(serial)); - strlcpy(serial, "no String", 10); - } - - - printf( "bLength 0x%02X\n" - "bDescriptorType 0x%02X\n" - "bcdUSB 0x%02X\n" - "bDeviceClass 0x%02X\n" - "bDeviceSubClass 0x%02X\n" - "bDeviceProtocoll 0x%02X\n" - "idVendor 0x%04X\n" - "idProduct 0x%04X\n" - "bcdDevice 0x%04X\n" - "iManufacturer(0x%02X): \"%s\"\n" - "iProduct(0x%02X): \"%s\"\n" - "iSerialNumber(0x%02X): \"%s\"\n" - "bNumConfigurations 0x%02X\n", dev->bLength, dev->bDeviceClass, - dev->bcdUSB, dev->bDescriptorType, dev->bDeviceSubClass, - dev->bDeviceProtocoll, dev->idVendor, dev->idProduct, dev->bcdDevice, - dev->iManufacturer, man, - dev->iProduct, prod, - dev->iSerialNumber, serial, - dev->bNumConfigurations); - - memset(buf, 0, sizeof(buf)); - /* in the most cases usb devices have just one configuration descriptor */ - ret = usb_get_desc_configuration(dev, 0, buf, sizeof(buf)); - printf("=============\nbuf: 0x%08X\nafter usb_get_desc_configuration(ret: %d):\n", buf, ret); - hexdump(buf, sizeof(buf)); - - printf("interfaces: %d\n", dev->conf->bNumInterfaces); - u8 i; - for(i = 1; i <= dev->conf->bNumInterfaces; i++) { - memset(buf, 0, sizeof(buf)); - ret = usb_get_desc_interface(dev, i, buf, sizeof(buf)); - printf("=============\nbuf: 0x%08X\nafter usb_get_desc_interface_%d(ret: %d):\n", buf, i, ret); - hexdump(buf, sizeof(buf)); - } - - - - /* - usb_get_descriptor(dev, DEVICE, 0, buf, 8); - memset(buf, 0, 8); - usb_get_descriptor(dev, DEVICE, 0, buf, size >= buf[0] ? buf[0] : size); - */ -#if 0 - memset(buf, 0, sizeof(buf)); - usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, 8, buf, 0); - printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf); - hexdump(buf, sizeof(buf)); - - memset(buf, 0, sizeof(buf)); - usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, buf[0], buf, 0); - printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf); - hexdump(buf, sizeof(buf)); - - memset(buf, 0, sizeof(buf)); - usb_get_string_simple(dev, 1, buf); - printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf); - hexdump(buf, sizeof(buf)); -#endif - -#if 0 - u8 devdescr_size; - - /* setup real ep0 fifo size */ - dev->bMaxPacketSize0 = (u8) buf[7]; - if(!(u8)buf[7]) { - printf("FU\n"); - return (void*)1; - } - - /* save real length of device descriptor */ - devdescr_size = (u8) buf[0]; - - /* define new adress */ - memset(buf, 0, sizeof(buf)); - usb_control_msg(dev, 0x00, SET_ADDRESS, address, 0, 0, buf, 8, 0); - dev->address = address; - printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf); - hexdump(buf, sizeof(buf)); - printf("address: %d\n", address); - - - /* get complete device descriptor */ - memset(buf, 0, sizeof(buf)); - usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE<<8, 0, devdescr_size, buf, 8, 0); - printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf); - hexdump(buf, sizeof(buf)); - - /* save only really neccessary values for this small usbstack */ -#endif - -#if 0 - memset(buf, 0, sizeof(buf)); - usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (STRING<<8)|2, 0, 0x1a, buf, 8, 0); - hexdump(buf, sizeof(buf)); - printf("String Descriptor [1]: "); - u8 i; - for (i=2; i on demand mit - // entprechenden funktionen - // hier muss man noch mehr abholen, konfigurationene, interfaces und endpunkte + /* print device info */ + lsusb(dev); -#if 0 /* add device to device list */ - element *tmp = (element *) malloc(sizeof(element)); + struct element *tmp = (struct element *) malloc(sizeof(struct element)); tmp->data = (void *) dev; list_add_tail(core.devices, tmp); usb_probe_driver(); -#endif return dev; } +void lsusb(struct usb_device *dev) +{ + printf("=== Device Descriptor === \n"); + printf("bLength 0x%02X\n", dev->bLength); + printf("bDescriptorType 0x%02X\n", dev->bDeviceClass); + printf("bcdUSB 0x%04X\n", dev->bcdUSB); + printf("bDeviceClass 0x%02X\n", dev->bDeviceClass); + printf("bDeviceSubClass 0x%02X\n", dev->bDeviceSubClass); + printf("bDeviceProtocoll 0x%02X\n", dev->bDeviceProtocoll); + printf("bMaxPacketSize 0x%02X\n", dev->bMaxPacketSize0); + printf("idVendor 0x%04X\n", dev->idVendor); + printf("idProduct 0x%04X\n", dev->idProduct); + printf("bcdDevice 0x%04X\n", dev->bcdDevice); + printf("iManufacturer(0x%02X): \"%s\"\n", dev->iManufacturer, dev->iManufacturer ? usb_get_string_simple(dev, dev->iManufacturer) : "no String"); + printf("iProduct(0x%02X): \"%s\"\n", dev->iProduct, dev->iProduct ? usb_get_string_simple(dev, dev->iProduct) : "no String"); + printf("iSerialNumber(0x%02X): \"%s\"\n", dev->iSerialNumber, dev->iSerialNumber ? usb_get_string_simple(dev, dev->iSerialNumber) : "no String"); + printf("bNumConfigurations 0x%02X\n", dev->bNumConfigurations); + + u8 c, i, e; + struct usb_conf *conf = dev->conf; + for(c=0; c <= dev->bNumConfigurations; c++) { + printf(" === Configuration Descriptor %d ===\n", c+1); + printf(" bLength 0x%02X\n", conf->bLength); + printf(" bDescriptorType 0x%02X\n", conf->bDescriptorType); + printf(" wTotalLength 0x%04X\n", conf->wTotalLength); + printf(" bNumInterfaces 0x%02X\n", conf->bNumInterfaces); + printf(" bConfigurationValue 0x%02X\n", conf->bConfigurationValue); + printf(" iConfiguration (0x%02X): \"%s\"\n", conf->iConfiguration, conf->iConfiguration ? usb_get_string_simple(dev, conf->iConfiguration) : "no String"); + printf(" bmAttributes 0x%02X\n", conf->bmAttributes); + printf(" bMaxPower 0x%02X\n", conf->bMaxPower); + + struct usb_intf *ifs = conf->intf; + for(i=1; i <= conf->bNumInterfaces; i++) { + printf(" === Interface Descriptor %d ===\n", i); + printf(" bLength 0x%02X\n", ifs->bLength); + printf(" bDescriptorType 0x%02X\n", ifs->bDescriptorType); + printf(" bInterfaceNumber 0x%02X\n", ifs->bInterfaceNumber); + printf(" bAlternateSetting 0x%02X\n", ifs->bAlternateSetting); + printf(" bNumEndpoints 0x%02X\n", ifs->bNumEndpoints); + printf(" bInterfaceClass 0x%02X\n", ifs->bInterfaceClass); + printf(" bInterfaceSubClass 0x%02X\n", ifs->bInterfaceSubClass); + printf(" bInterfaceProtocol 0x%02X\n", ifs->bInterfaceProtocol); + printf(" iInterface (0x%02X): \"%s\"\n", ifs->iInterface, ifs->iInterface ? usb_get_string_simple(dev, ifs->iInterface) : "no String"); + + struct usb_endp *ed = ifs->endp; + for(e=1; e <= ifs->bNumEndpoints; e++) { + printf(" === Endpoint Descriptor %d ===\n", e); + printf(" bLength 0x%02X\n", ed->bLength); + printf(" bDescriptorType 0x%02X\n", ed->bDescriptorType); + printf(" bEndpointAddress 0x%02X\n", ed->bEndpointAddress); + printf(" bmAttributes 0x%02X\n", ed->bmAttributes); + printf(" wMaxPacketSize 0x%02X\n", ed->wMaxPacketSize); + printf(" bInterval 0x%02X\n", ed->bInterval); + + ed = ed->next; + } //endpoint + + ifs = ifs->next; + } //interface + + conf = conf->next; + } //configuration +} + /** * Find currently detached device and remove * data structures */ -u8 usb_remove_device(struct usb_device * dev) +u8 usb_remove_device(struct usb_device *dev) { - // FIXME!!!! dieser quatsch ist nur temporaer - free(core.devices->head); - free(core.devices); - core.devices = list_create(); + /* trigger driver for this device */ + struct usb_driver *drv; + struct element *iterator = core.drivers->head; + while (iterator != NULL) { + drv = (struct usb_driver *) iterator->data; + if(drv->data && !memcmp(drv->data, dev, sizeof(struct usb_device))) { + drv->remove(); + break; + } + iterator = iterator->next; + } + + /* remove from device list */ + struct element *tmp = (struct element *) malloc(sizeof(struct element)); + tmp->data = (void *) dev; + list_delete_element(core.devices, tmp); + + printf("REMOVED\n"); + return 1; } /** * Register new driver at usb stack. */ -u8 usb_register_driver(struct usb_driver * dev) +u8 usb_register_driver(struct usb_driver *dev) { /* add driver to driver list */ struct element *tmp = (struct element *) malloc(sizeof(struct element)); @@ -310,7 +267,6 @@ u8 usb_register_driver(struct usb_driver * dev) tmp->next = NULL; list_add_tail(core.drivers, tmp); - /** * first check to find a suitable device * (root hub drivers need this call here) @@ -394,7 +350,7 @@ u16 usb_submit_irp(struct usb_irp *irp) togl = togl ? 0 : 1; /**** send token ****/ - hcdi_enqueue(td); + hcdi_enqueue(td, irp->dev->ohci); /***************** Data Stage ***********************/ /** @@ -452,7 +408,7 @@ u16 usb_submit_irp(struct usb_irp *irp) } /**** send token ****/ - hcdi_enqueue(td); + hcdi_enqueue(td, irp->dev->ohci); /* pruefe ob noch weitere Pakete vom Device abgeholt werden muessen */ restlength = restlength - irp->epsize; @@ -479,60 +435,41 @@ u16 usb_submit_irp(struct usb_irp *irp) td->pid = USB_PID_IN; } /**** send token ****/ - hcdi_enqueue(td); + hcdi_enqueue(td, irp->dev->ohci); free(td); break; case USB_BULK: - core.stdout("bulk\r\n"); - //u8 runloop=1; - //u16 restlength = irp->len; - //char * td_buf_ptr=irp->buffer; - - /* schleife die die tds generiert */ - while (runloop) { - + case USB_INTR: + while (runloop && (restlength > 0)) { td = usb_create_transfer_descriptor(irp); - td->endpoint = td->endpoint & 0x7F; /* clear direction bit */ - /* max packet size for given endpoint */ td->actlen = irp->epsize; - /* Generate In Packet */ - if (irp->endpoint & 0x80) - td->pid = USB_PID_IN; - else - /* Generate Out Packet */ - td->pid = USB_PID_OUT; + td->pid = irp->endpoint & 0x80 ? USB_PID_IN : USB_PID_OUT; /* stop loop if all bytes are send */ - if (restlength <= irp->epsize) { + if (restlength < irp->epsize) { runloop = 0; td->actlen = restlength; } td->buffer = td_buf_ptr; /* move pointer for next packet */ - td_buf_ptr = td_buf_ptr + irp->epsize; + td_buf_ptr += irp->epsize; td->togl = togl; - if (togl == 0) - togl = 1; - else - togl = 0; - /**** send token ****/ - hcdi_enqueue(td); + togl = togl ? 0 : 1; + + /**** send token ****/ + hcdi_enqueue(td, irp->dev->ohci); + restlength = restlength - irp->epsize; free(td); } - /* next togl */ - //if(td->pid == USB_PID_OUT) { - //if(togl==0) togl=1; else togl=0; - //} - irp->dev->epTogl[(irp->endpoint & 0x7F)] = togl; - break; + irp->dev->epTogl[(irp->endpoint & 0x7F)] = togl; } - hcdi_fire(); + hcdi_fire(irp->dev->ohci); return 1; } @@ -548,10 +485,12 @@ struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp * (struct usb_transfer_descriptor *) malloc(sizeof(struct usb_transfer_descriptor)); td->devaddress = irp->dev->address; - td->endpoint = irp->endpoint; + td->endpoint = irp->endpoint & 0x7F; td->iso = 0; td->state = USB_TRANSFER_DESCR_NONE; td->maxp = irp->epsize; + td->fullspeed = irp->dev->fullspeed; + td->type = irp->type; return td; }