diff options
author | Helge Deller <deller@gmx.de> | 2023-10-14 12:38:33 +0200 |
---|---|---|
committer | Helge Deller <deller@gmx.de> | 2023-10-14 13:39:42 +0200 |
commit | 387a165d2bcd2c9993a17cea68d70439137909c2 (patch) | |
tree | 03f55fdb450d9db45155ef274390fc5fbe1b219e | |
parent | 44b627c88bb8c08f0a859311f16afd69188ad653 (diff) | |
download | seabios-hppa-387a165d2bcd2c9993a17cea68d70439137909c2.zip seabios-hppa-387a165d2bcd2c9993a17cea68d70439137909c2.tar.gz seabios-hppa-387a165d2bcd2c9993a17cea68d70439137909c2.tar.bz2 |
parisc/usb: Fix usb host for big-endian machines (like parisc)
Signed-off-by: Helge Deller <deller@gmx.de>
-rw-r--r-- | src/hw/usb-ohci.c | 91 | ||||
-rw-r--r-- | src/hw/usb.c | 14 |
2 files changed, 54 insertions, 51 deletions
diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index 90f60e6..f8a8067 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -126,7 +126,7 @@ static void ohci_waittick(struct ohci_regs *regs) { barrier(); - struct ohci_hcca *hcca = (void*)regs->hcca; + struct ohci_hcca *hcca = (void*)readl(®s->hcca); u32 startframe = hcca->frame_no; u32 end = timer_calc(1000 * 5); for (;;) { @@ -153,7 +153,7 @@ ohci_free_pipes(struct usb_ohci_s *cntl) u32 *pos = &cntl->regs->ed_controlhead; for (;;) { - struct ohci_ed *next = (void*)*pos; + struct ohci_ed *next = (void*)le32_to_cpu(*pos); if (!next) break; struct ohci_pipe *pipe = container_of(next, struct ohci_pipe, ed); @@ -200,7 +200,7 @@ start_ohci(struct usb_ohci_s *cntl, struct ohci_hcca *hcca) // Init memory writel(&cntl->regs->ed_controlhead, 0); writel(&cntl->regs->ed_bulkhead, 0); - writel(&cntl->regs->hcca, (u32)hcca); + writel(&cntl->regs->hcca, cpu_to_le32((u32)hcca)); // Init fminterval u32 fi = oldfminterval & 0x3fff; @@ -243,10 +243,10 @@ configure_ohci(void *data) } memset(hcca, 0, sizeof(*hcca)); memset(intr_ed, 0, sizeof(*intr_ed)); - intr_ed->hwINFO = ED_SKIP; + intr_ed->hwINFO = cpu_to_le32(ED_SKIP); int i; for (i=0; i<ARRAY_SIZE(hcca->int_table); i++) - hcca->int_table[i] = (u32)intr_ed; + hcca->int_table[i] = cpu_to_le32((u32)intr_ed); int ret = start_ohci(cntl, hcca); if (ret) @@ -318,9 +318,10 @@ ohci_desc2pipe(struct ohci_pipe *pipe, struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc) { usb_desc2pipe(&pipe->pipe, usbdev, epdesc); - pipe->ed.hwINFO = (ED_SKIP | usbdev->devaddr | (pipe->pipe.ep << 7) + pipe->ed.hwINFO = cpu_to_le32( + (ED_SKIP | usbdev->devaddr | (pipe->pipe.ep << 7) | (epdesc->wMaxPacketSize << 16) - | (usbdev->speed ? ED_LOWSPEED : 0)); + | (usbdev->speed ? ED_LOWSPEED : 0))); struct usb_ohci_s *cntl = container_of( usbdev->hub->cntl, struct usb_ohci_s, usb); pipe->regs = cntl->regs; @@ -348,37 +349,37 @@ ohci_alloc_intr_pipe(struct usbdevice_s *usbdev goto err; memset(pipe, 0, sizeof(*pipe)); ohci_desc2pipe(pipe, usbdev, epdesc); - pipe->ed.hwINFO &= ~ED_SKIP; + pipe->ed.hwINFO &= cpu_to_le32(~ED_SKIP); pipe->data = data; pipe->count = count; pipe->tds = tds; struct ohci_ed *ed = &pipe->ed; - ed->hwHeadP = (u32)&tds[0]; - ed->hwTailP = (u32)&tds[count-1]; + ed->hwHeadP = cpu_to_le32((u32)&tds[0]); + ed->hwTailP = cpu_to_le32((u32)&tds[count-1]); int i; for (i=0; i<count-1; i++) { - tds[i].hwINFO = TD_DP_IN | TD_T_TOGGLE | TD_CC; - tds[i].hwCBP = (u32)data + maxpacket * i; - tds[i].hwNextTD = (u32)&tds[i+1]; - tds[i].hwBE = tds[i].hwCBP + maxpacket - 1; + tds[i].hwINFO = cpu_to_le32(TD_DP_IN | TD_T_TOGGLE | TD_CC); + tds[i].hwCBP = cpu_to_le32((u32)data + maxpacket * i); + tds[i].hwNextTD = cpu_to_le32((u32)&tds[i+1]); + tds[i].hwBE = cpu_to_le32(le32_to_cpu(tds[i].hwCBP) + maxpacket - 1); } // Add to interrupt schedule. - struct ohci_hcca *hcca = (void*)cntl->regs->hcca; + struct ohci_hcca *hcca = (void*)readl(&cntl->regs->hcca); if (frameexp == 0) { // Add to existing interrupt entry. - struct ohci_ed *intr_ed = (void*)hcca->int_table[0]; + struct ohci_ed *intr_ed = (void*)le32_to_cpu(hcca->int_table[0]); ed->hwNextED = intr_ed->hwNextED; barrier(); - intr_ed->hwNextED = (u32)ed; + intr_ed->hwNextED = cpu_to_le32((u32)ed); } else { int startpos = 1<<(frameexp-1); ed->hwNextED = hcca->int_table[startpos]; barrier(); for (i=startpos; i<ARRAY_SIZE(hcca->int_table); i+=ms) - hcca->int_table[i] = (u32)ed; + hcca->int_table[i] = cpu_to_le32((u32)ed); } return &pipe->pipe; @@ -433,7 +434,7 @@ ohci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe head = &cntl->regs->ed_bulkhead; pipe->ed.hwNextED = *head; barrier(); - *head = (u32)&pipe->ed; + *head = cpu_to_le32((u32)&pipe->ed); return &pipe->pipe; } @@ -442,12 +443,13 @@ wait_ed(struct ohci_ed *ed, int timeout) { u32 end = timer_calc(timeout); for (;;) { - if ((ed->hwHeadP & ~(ED_C|ED_H)) == ed->hwTailP) + if ((le32_to_cpu(ed->hwHeadP) & ~(ED_C|ED_H)) == le32_to_cpu(ed->hwTailP)) return 0; if (timer_check(end)) { warn_timeout(); - dprintf(1, "ohci ed info=%x tail=%x head=%x next=%x\n" - , ed->hwINFO, ed->hwTailP, ed->hwHeadP, ed->hwNextED); + dprintf(1, "ohci ed info=%x tail=%x head=%x next=%x\n", + le32_to_cpu(ed->hwINFO), le32_to_cpu(ed->hwTailP), + le32_to_cpu(ed->hwHeadP), le32_to_cpu(ed->hwNextED)); return -1; } yield(); @@ -464,7 +466,7 @@ ohci_send_pipe(struct usb_pipe *p, int dir, const void *cmd ASSERT32FLAT(); if (! CONFIG_USB_OHCI) return -1; - dprintf(7, "ohci_send_pipe %p\n", p); + dprintf(7, "ohci_send_pipe %p cmd=%p datasize = %d XXXXXXXXXXXXXXX\n", p, cmd, datasize); struct ohci_pipe *pipe = container_of(p, struct ohci_pipe, pipe); // Allocate tds on stack (with required alignment) @@ -477,10 +479,10 @@ ohci_send_pipe(struct usb_pipe *p, int dir, const void *cmd u32 toggle = 0, statuscmd = OHCI_BLF; if (cmd) { // Send setup pid on control transfers - td->hwINFO = TD_DP_SETUP | TD_T_DATA0 | TD_CC; - td->hwCBP = (u32)cmd; - td->hwNextTD = (u32)&td[1]; - td->hwBE = (u32)cmd + USB_CONTROL_SETUP_SIZE - 1; + td->hwINFO = cpu_to_le32(TD_DP_SETUP | TD_T_DATA0 | TD_CC); + td->hwCBP = cpu_to_le32((u32)cmd); + td->hwNextTD = cpu_to_le32((u32)&td[1]); + td->hwBE = cpu_to_le32((u32)cmd + USB_CONTROL_SETUP_SIZE - 1); td++; toggle = TD_T_DATA1; statuscmd = OHCI_CLF; @@ -496,10 +498,10 @@ ohci_send_pipe(struct usb_pipe *p, int dir, const void *cmd int transfer = dataend - dest; if (transfer > maxtransfer) transfer = ALIGN_DOWN(maxtransfer, maxpacket); - td->hwINFO = (dir ? TD_DP_IN : TD_DP_OUT) | toggle | TD_CC; - td->hwCBP = dest; - td->hwNextTD = (u32)&td[1]; - td->hwBE = dest + transfer - 1; + td->hwINFO = cpu_to_le32((dir ? TD_DP_IN : TD_DP_OUT) | toggle | TD_CC); + td->hwCBP = cpu_to_le32(dest); + td->hwNextTD = cpu_to_le32((u32)&td[1]); + td->hwBE = cpu_to_le32(dest + transfer - 1); td++; dest += transfer; } @@ -509,24 +511,25 @@ ohci_send_pipe(struct usb_pipe *p, int dir, const void *cmd warn_noalloc(); return -1; } - td->hwINFO = (dir ? TD_DP_OUT : TD_DP_IN) | TD_T_DATA1 | TD_CC; + td->hwINFO = cpu_to_le32((dir ? TD_DP_OUT : TD_DP_IN) | TD_T_DATA1 | TD_CC); td->hwCBP = 0; - td->hwNextTD = (u32)&td[1]; + td->hwNextTD = cpu_to_le32((u32)&td[1]); td->hwBE = 0; td++; } // Transfer data - pipe->ed.hwHeadP = (u32)tds | (pipe->ed.hwHeadP & ED_C); - pipe->ed.hwTailP = (u32)td; + pipe->ed.hwHeadP = cpu_to_le32((u32)tds | (le32_to_cpu(pipe->ed.hwHeadP) & ED_C)); + pipe->ed.hwTailP = cpu_to_le32((u32)td); barrier(); - pipe->ed.hwINFO &= ~ED_SKIP; + pipe->ed.hwINFO &= cpu_to_le32(~ED_SKIP); writel(&pipe->regs->cmdstatus, statuscmd); int ret = wait_ed(&pipe->ed, usb_xfer_time(p, datasize)); - pipe->ed.hwINFO |= ED_SKIP; + pipe->ed.hwINFO |= cpu_to_le32(ED_SKIP); if (ret) ohci_waittick(pipe->regs); + dprintf(7, "ohci_send_pipe ENDE XXXXXXXXXXXXXXX ret=%d\n", ret); return ret; } @@ -539,8 +542,8 @@ ohci_poll_intr(struct usb_pipe *p, void *data) struct ohci_pipe *pipe = container_of(p, struct ohci_pipe, pipe); struct ohci_td *tds = GET_LOWFLAT(pipe->tds); - struct ohci_td *head = (void*)(GET_LOWFLAT(pipe->ed.hwHeadP) & ~(ED_C|ED_H)); - struct ohci_td *tail = (void*)GET_LOWFLAT(pipe->ed.hwTailP); + struct ohci_td *head = (void*)(le32_to_cpu(GET_LOWFLAT(pipe->ed.hwHeadP)) & ~(ED_C|ED_H)); + struct ohci_td *tail = (void*)le32_to_cpu(GET_LOWFLAT(pipe->ed.hwTailP)); int count = GET_LOWFLAT(pipe->count); int pos = (tail - tds + 1) % count; struct ohci_td *next = &tds[pos]; @@ -556,13 +559,13 @@ ohci_poll_intr(struct usb_pipe *p, void *data) memcpy_far(GET_SEG(SS), data, SEG_LOW, LOWFLAT2LOW(intrdata), maxpacket); // Reenable this td. - SET_LOWFLAT(tail->hwINFO, TD_DP_IN | TD_T_TOGGLE | TD_CC); + SET_LOWFLAT(tail->hwINFO, cpu_to_le32(TD_DP_IN | TD_T_TOGGLE | TD_CC)); intrdata = pipedata + maxpacket * (tail-tds); - SET_LOWFLAT(tail->hwCBP, (u32)intrdata); - SET_LOWFLAT(tail->hwNextTD, (u32)next); - SET_LOWFLAT(tail->hwBE, (u32)intrdata + maxpacket - 1); + SET_LOWFLAT(tail->hwCBP, cpu_to_le32((u32)intrdata)); + SET_LOWFLAT(tail->hwNextTD, cpu_to_le32((u32)next)); + SET_LOWFLAT(tail->hwBE, cpu_to_le32((u32)intrdata + maxpacket - 1)); barrier(); - SET_LOWFLAT(pipe->ed.hwTailP, (u32)next); + SET_LOWFLAT(pipe->ed.hwTailP, cpu_to_le32((u32)next)); return 0; } diff --git a/src/hw/usb.c b/src/hw/usb.c index 38a866a..7d3e452 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -227,9 +227,9 @@ get_device_info8(struct usb_pipe *pipe, struct usb_device_descriptor *dinfo) struct usb_ctrlrequest req; req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req.bRequest = USB_REQ_GET_DESCRIPTOR; - req.wValue = USB_DT_DEVICE<<8; + req.wValue = cpu_to_le16(USB_DT_DEVICE<<8); req.wIndex = 0; - req.wLength = 8; + req.wLength = cpu_to_le16(8); return usb_send_default_control(pipe, &req, dinfo); } @@ -241,9 +241,9 @@ get_device_config(struct usb_pipe *pipe) struct usb_ctrlrequest req; req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req.bRequest = USB_REQ_GET_DESCRIPTOR; - req.wValue = USB_DT_CONFIG<<8; + req.wValue = cpu_to_le16(USB_DT_CONFIG<<8); req.wIndex = 0; - req.wLength = sizeof(cfg); + req.wLength = cpu_to_le16(sizeof(cfg)); int ret = usb_send_default_control(pipe, &req, &cfg); if (ret) return NULL; @@ -253,7 +253,7 @@ get_device_config(struct usb_pipe *pipe) warn_noalloc(); return NULL; } - req.wLength = cfg.wTotalLength; + req.wLength = cpu_to_le16(cfg.wTotalLength); ret = usb_send_default_control(pipe, &req, config); if (ret || config->wTotalLength != cfg.wTotalLength) { free(config); @@ -269,7 +269,7 @@ set_configuration(struct usb_pipe *pipe, u16 val) struct usb_ctrlrequest req; req.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req.bRequest = USB_REQ_SET_CONFIGURATION; - req.wValue = val; + req.wValue = cpu_to_le16(val); req.wIndex = 0; req.wLength = 0; return usb_send_default_control(pipe, &req, NULL); @@ -313,7 +313,7 @@ usb_set_address(struct usbdevice_s *usbdev) struct usb_ctrlrequest req; req.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req.bRequest = USB_REQ_SET_ADDRESS; - req.wValue = cntl->maxaddr + 1; + req.wValue = cpu_to_le16(cntl->maxaddr + 1); req.wIndex = 0; req.wLength = 0; int ret = usb_send_default_control(usbdev->defpipe, &req, NULL); |