Commit ac611340c9e21f3f9f1247a23de08d8764174b83

Authored by aurel32
1 parent 465c9f06

Adds SM501 usb host emulation feature.

It makes usb keyboard available for sh4/r2d system emulation.

The changes for "hw/usb-ohci.c" are as follows.
 - 'localmem_base' is introduced as OHCIState struct member.
   SM501 has a local memory, and it is used to pass and receive data with
   OHCI driver.  OHCI driver accesses it with SH4 physical memory address,
   and SM501 accesses it with SM501 local address.  'localmem_base' holds
   where the SM501 local memory is mapped into SH4 physical address space.
 - Memory access functions modified to adjust address with 'localmem_base'.
   The functions are, ohci_read_*(), ohci_put_*(), and ohci_copy_*().
 - ohci_read_hcca() and ohci_put_hcca() are introduced for more consistent
   implementation.

For other source files, it does,
 - introduces usb_ohci_init_sm501().
 - adds irq argument for SM501 initialization, to emulate USB interrupts.

Signed-off-by: Shin-ichiro KAWASAKI <kawasaki@juno.dti.ne.jp>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7188 c046a42c-6fe2-441c-8c8c-71466251a162
hw/devices.h
@@ -74,5 +74,10 @@ qemu_irq *tc6393xb_gpio_in_get(struct tc6393xb_s *s); @@ -74,5 +74,10 @@ qemu_irq *tc6393xb_gpio_in_get(struct tc6393xb_s *s);
74 qemu_irq tc6393xb_l3v_get(struct tc6393xb_s *s); 74 qemu_irq tc6393xb_l3v_get(struct tc6393xb_s *s);
75 75
76 /* sm501.c */ 76 /* sm501.c */
77 -void sm501_init(uint32_t base, uint32_t local_mem_bytes, CharDriverState *chr); 77 +void sm501_init(uint32_t base, uint32_t local_mem_bytes, qemu_irq irq,
  78 + CharDriverState *chr);
  79 +
  80 +/* usb-ohci.c */
  81 +void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base,
  82 + int num_ports, int devfn, qemu_irq irq);
78 #endif 83 #endif
hw/r2d.c
@@ -222,7 +222,7 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, @@ -222,7 +222,7 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size,
222 irq = r2d_fpga_init(0x04000000, sh7750_irl(s)); 222 irq = r2d_fpga_init(0x04000000, sh7750_irl(s));
223 pci = sh_pci_register_bus(r2d_pci_set_irq, r2d_pci_map_irq, irq, 0, 4); 223 pci = sh_pci_register_bus(r2d_pci_set_irq, r2d_pci_map_irq, irq, 0, 4);
224 224
225 - sm501_init(0x10000000, SM501_VRAM_SIZE, serial_hds[2]); 225 + sm501_init(0x10000000, SM501_VRAM_SIZE, irq[SM501], serial_hds[2]);
226 226
227 /* onboard CF (True IDE mode, Master only). */ 227 /* onboard CF (True IDE mode, Master only). */
228 if ((i = drive_get_index(IF_IDE, 0, 0)) != -1) 228 if ((i = drive_get_index(IF_IDE, 0, 0)) != -1)
hw/sm501.c
@@ -1055,7 +1055,8 @@ static void sm501_update_display(void *opaque) @@ -1055,7 +1055,8 @@ static void sm501_update_display(void *opaque)
1055 sm501_draw_crt(s); 1055 sm501_draw_crt(s);
1056 } 1056 }
1057 1057
1058 -void sm501_init(uint32_t base, uint32_t local_mem_bytes, CharDriverState *chr) 1058 +void sm501_init(uint32_t base, uint32_t local_mem_bytes, qemu_irq irq,
  1059 + CharDriverState *chr)
1059 { 1060 {
1060 SM501State * s; 1061 SM501State * s;
1061 int sm501_system_config_index; 1062 int sm501_system_config_index;
@@ -1089,6 +1090,10 @@ void sm501_init(uint32_t base, uint32_t local_mem_bytes, CharDriverState *chr) @@ -1089,6 +1090,10 @@ void sm501_init(uint32_t base, uint32_t local_mem_bytes, CharDriverState *chr)
1089 cpu_register_physical_memory(base + MMIO_BASE_OFFSET + SM501_DC, 1090 cpu_register_physical_memory(base + MMIO_BASE_OFFSET + SM501_DC,
1090 0x1000, sm501_disp_ctrl_index); 1091 0x1000, sm501_disp_ctrl_index);
1091 1092
  1093 + /* bridge to usb host emulation module */
  1094 + usb_ohci_init_sm501(base + MMIO_BASE_OFFSET + SM501_USB_HOST, base,
  1095 + 2, -1, irq);
  1096 +
1092 /* bridge to serial emulation module */ 1097 /* bridge to serial emulation module */
1093 if (chr) 1098 if (chr)
1094 serial_mm_init(base + MMIO_BASE_OFFSET + SM501_UART0, 2, 1099 serial_mm_init(base + MMIO_BASE_OFFSET + SM501_UART0, 2,
hw/usb-ohci.c
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 #include "usb.h" 32 #include "usb.h"
33 #include "pci.h" 33 #include "pci.h"
34 #include "pxa.h" 34 #include "pxa.h"
  35 +#include "devices.h"
35 36
36 //#define DEBUG_OHCI 37 //#define DEBUG_OHCI
37 /* Dump packet contents. */ 38 /* Dump packet contents. */
@@ -60,7 +61,8 @@ typedef struct OHCIPort { @@ -60,7 +61,8 @@ typedef struct OHCIPort {
60 61
61 enum ohci_type { 62 enum ohci_type {
62 OHCI_TYPE_PCI, 63 OHCI_TYPE_PCI,
63 - OHCI_TYPE_PXA 64 + OHCI_TYPE_PXA,
  65 + OHCI_TYPE_SM501,
64 }; 66 };
65 67
66 typedef struct { 68 typedef struct {
@@ -108,6 +110,9 @@ typedef struct { @@ -108,6 +110,9 @@ typedef struct {
108 uint32_t hreset; 110 uint32_t hreset;
109 uint32_t htest; 111 uint32_t htest;
110 112
  113 + /* SM501 local memory offset */
  114 + target_phys_addr_t localmem_base;
  115 +
111 /* Active packets. */ 116 /* Active packets. */
112 uint32_t old_ctl; 117 uint32_t old_ctl;
113 USBPacket usb_packet; 118 USBPacket usb_packet;
@@ -425,10 +430,13 @@ static void ohci_reset(void *opaque) @@ -425,10 +430,13 @@ static void ohci_reset(void *opaque)
425 } 430 }
426 431
427 /* Get an array of dwords from main memory */ 432 /* Get an array of dwords from main memory */
428 -static inline int get_dwords(uint32_t addr, uint32_t *buf, int num) 433 +static inline int get_dwords(OHCIState *ohci,
  434 + uint32_t addr, uint32_t *buf, int num)
429 { 435 {
430 int i; 436 int i;
431 437
  438 + addr += ohci->localmem_base;
  439 +
432 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { 440 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
433 cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0); 441 cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
434 *buf = le32_to_cpu(*buf); 442 *buf = le32_to_cpu(*buf);
@@ -438,10 +446,13 @@ static inline int get_dwords(uint32_t addr, uint32_t *buf, int num) @@ -438,10 +446,13 @@ static inline int get_dwords(uint32_t addr, uint32_t *buf, int num)
438 } 446 }
439 447
440 /* Put an array of dwords in to main memory */ 448 /* Put an array of dwords in to main memory */
441 -static inline int put_dwords(uint32_t addr, uint32_t *buf, int num) 449 +static inline int put_dwords(OHCIState *ohci,
  450 + uint32_t addr, uint32_t *buf, int num)
442 { 451 {
443 int i; 452 int i;
444 453
  454 + addr += ohci->localmem_base;
  455 +
445 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { 456 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
446 uint32_t tmp = cpu_to_le32(*buf); 457 uint32_t tmp = cpu_to_le32(*buf);
447 cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1); 458 cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
@@ -451,10 +462,13 @@ static inline int put_dwords(uint32_t addr, uint32_t *buf, int num) @@ -451,10 +462,13 @@ static inline int put_dwords(uint32_t addr, uint32_t *buf, int num)
451 } 462 }
452 463
453 /* Get an array of words from main memory */ 464 /* Get an array of words from main memory */
454 -static inline int get_words(uint32_t addr, uint16_t *buf, int num) 465 +static inline int get_words(OHCIState *ohci,
  466 + uint32_t addr, uint16_t *buf, int num)
455 { 467 {
456 int i; 468 int i;
457 469
  470 + addr += ohci->localmem_base;
  471 +
458 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { 472 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
459 cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0); 473 cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
460 *buf = le16_to_cpu(*buf); 474 *buf = le16_to_cpu(*buf);
@@ -464,10 +478,13 @@ static inline int get_words(uint32_t addr, uint16_t *buf, int num) @@ -464,10 +478,13 @@ static inline int get_words(uint32_t addr, uint16_t *buf, int num)
464 } 478 }
465 479
466 /* Put an array of words in to main memory */ 480 /* Put an array of words in to main memory */
467 -static inline int put_words(uint32_t addr, uint16_t *buf, int num) 481 +static inline int put_words(OHCIState *ohci,
  482 + uint32_t addr, uint16_t *buf, int num)
468 { 483 {
469 int i; 484 int i;
470 485
  486 + addr += ohci->localmem_base;
  487 +
471 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { 488 for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
472 uint16_t tmp = cpu_to_le16(*buf); 489 uint16_t tmp = cpu_to_le16(*buf);
473 cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1); 490 cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
@@ -476,40 +493,63 @@ static inline int put_words(uint32_t addr, uint16_t *buf, int num) @@ -476,40 +493,63 @@ static inline int put_words(uint32_t addr, uint16_t *buf, int num)
476 return 1; 493 return 1;
477 } 494 }
478 495
479 -static inline int ohci_read_ed(uint32_t addr, struct ohci_ed *ed) 496 +static inline int ohci_read_ed(OHCIState *ohci,
  497 + uint32_t addr, struct ohci_ed *ed)
480 { 498 {
481 - return get_dwords(addr, (uint32_t *)ed, sizeof(*ed) >> 2); 499 + return get_dwords(ohci, addr, (uint32_t *)ed, sizeof(*ed) >> 2);
482 } 500 }
483 501
484 -static inline int ohci_read_td(uint32_t addr, struct ohci_td *td) 502 +static inline int ohci_read_td(OHCIState *ohci,
  503 + uint32_t addr, struct ohci_td *td)
485 { 504 {
486 - return get_dwords(addr, (uint32_t *)td, sizeof(*td) >> 2); 505 + return get_dwords(ohci, addr, (uint32_t *)td, sizeof(*td) >> 2);
487 } 506 }
488 507
489 -static inline int ohci_read_iso_td(uint32_t addr, struct ohci_iso_td *td) 508 +static inline int ohci_read_iso_td(OHCIState *ohci,
  509 + uint32_t addr, struct ohci_iso_td *td)
490 { 510 {
491 - return (get_dwords(addr, (uint32_t *)td, 4) &&  
492 - get_words(addr + 16, td->offset, 8)); 511 + return (get_dwords(ohci, addr, (uint32_t *)td, 4) &&
  512 + get_words(ohci, addr + 16, td->offset, 8));
493 } 513 }
494 514
495 -static inline int ohci_put_ed(uint32_t addr, struct ohci_ed *ed) 515 +static inline int ohci_read_hcca(OHCIState *ohci,
  516 + uint32_t addr, struct ohci_hcca *hcca)
496 { 517 {
497 - return put_dwords(addr, (uint32_t *)ed, sizeof(*ed) >> 2); 518 + cpu_physical_memory_rw(addr + ohci->localmem_base,
  519 + (uint8_t *)hcca, sizeof(*hcca), 0);
  520 + return 1;
498 } 521 }
499 522
500 -static inline int ohci_put_td(uint32_t addr, struct ohci_td *td) 523 +static inline int ohci_put_ed(OHCIState *ohci,
  524 + uint32_t addr, struct ohci_ed *ed)
501 { 525 {
502 - return put_dwords(addr, (uint32_t *)td, sizeof(*td) >> 2); 526 + return put_dwords(ohci, addr, (uint32_t *)ed, sizeof(*ed) >> 2);
503 } 527 }
504 528
505 -static inline int ohci_put_iso_td(uint32_t addr, struct ohci_iso_td *td) 529 +static inline int ohci_put_td(OHCIState *ohci,
  530 + uint32_t addr, struct ohci_td *td)
506 { 531 {
507 - return (put_dwords(addr, (uint32_t *)td, 4) &&  
508 - put_words(addr + 16, td->offset, 8)); 532 + return put_dwords(ohci, addr, (uint32_t *)td, sizeof(*td) >> 2);
  533 +}
  534 +
  535 +static inline int ohci_put_iso_td(OHCIState *ohci,
  536 + uint32_t addr, struct ohci_iso_td *td)
  537 +{
  538 + return (put_dwords(ohci, addr, (uint32_t *)td, 4) &&
  539 + put_words(ohci, addr + 16, td->offset, 8));
  540 +}
  541 +
  542 +static inline int ohci_put_hcca(OHCIState *ohci,
  543 + uint32_t addr, struct ohci_hcca *hcca)
  544 +{
  545 + cpu_physical_memory_rw(addr + ohci->localmem_base,
  546 + (uint8_t *)hcca, sizeof(*hcca), 1);
  547 + return 1;
509 } 548 }
510 549
511 /* Read/Write the contents of a TD from/to main memory. */ 550 /* Read/Write the contents of a TD from/to main memory. */
512 -static void ohci_copy_td(struct ohci_td *td, uint8_t *buf, int len, int write) 551 +static void ohci_copy_td(OHCIState *ohci, struct ohci_td *td,
  552 + uint8_t *buf, int len, int write)
513 { 553 {
514 uint32_t ptr; 554 uint32_t ptr;
515 uint32_t n; 555 uint32_t n;
@@ -518,16 +558,17 @@ static void ohci_copy_td(struct ohci_td *td, uint8_t *buf, int len, int write) @@ -518,16 +558,17 @@ static void ohci_copy_td(struct ohci_td *td, uint8_t *buf, int len, int write)
518 n = 0x1000 - (ptr & 0xfff); 558 n = 0x1000 - (ptr & 0xfff);
519 if (n > len) 559 if (n > len)
520 n = len; 560 n = len;
521 - cpu_physical_memory_rw(ptr, buf, n, write); 561 + cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, n, write);
522 if (n == len) 562 if (n == len)
523 return; 563 return;
524 ptr = td->be & ~0xfffu; 564 ptr = td->be & ~0xfffu;
525 buf += n; 565 buf += n;
526 - cpu_physical_memory_rw(ptr, buf, len - n, write); 566 + cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, len - n, write);
527 } 567 }
528 568
529 /* Read/Write the contents of an ISO TD from/to main memory. */ 569 /* Read/Write the contents of an ISO TD from/to main memory. */
530 -static void ohci_copy_iso_td(uint32_t start_addr, uint32_t end_addr, 570 +static void ohci_copy_iso_td(OHCIState *ohci,
  571 + uint32_t start_addr, uint32_t end_addr,
531 uint8_t *buf, int len, int write) 572 uint8_t *buf, int len, int write)
532 { 573 {
533 uint32_t ptr; 574 uint32_t ptr;
@@ -537,12 +578,12 @@ static void ohci_copy_iso_td(uint32_t start_addr, uint32_t end_addr, @@ -537,12 +578,12 @@ static void ohci_copy_iso_td(uint32_t start_addr, uint32_t end_addr,
537 n = 0x1000 - (ptr & 0xfff); 578 n = 0x1000 - (ptr & 0xfff);
538 if (n > len) 579 if (n > len)
539 n = len; 580 n = len;
540 - cpu_physical_memory_rw(ptr, buf, n, write); 581 + cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, n, write);
541 if (n == len) 582 if (n == len)
542 return; 583 return;
543 ptr = end_addr & ~0xfffu; 584 ptr = end_addr & ~0xfffu;
544 buf += n; 585 buf += n;
545 - cpu_physical_memory_rw(ptr, buf, len - n, write); 586 + cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, len - n, write);
546 } 587 }
547 588
548 static void ohci_process_lists(OHCIState *ohci, int completion); 589 static void ohci_process_lists(OHCIState *ohci, int completion);
@@ -579,7 +620,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -579,7 +620,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
579 620
580 addr = ed->head & OHCI_DPTR_MASK; 621 addr = ed->head & OHCI_DPTR_MASK;
581 622
582 - if (!ohci_read_iso_td(addr, &iso_td)) { 623 + if (!ohci_read_iso_td(ohci, addr, &iso_td)) {
583 printf("usb-ohci: ISO_TD read error at %x\n", addr); 624 printf("usb-ohci: ISO_TD read error at %x\n", addr);
584 return 0; 625 return 0;
585 } 626 }
@@ -621,7 +662,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -621,7 +662,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
621 i = OHCI_BM(iso_td.flags, TD_DI); 662 i = OHCI_BM(iso_td.flags, TD_DI);
622 if (i < ohci->done_count) 663 if (i < ohci->done_count)
623 ohci->done_count = i; 664 ohci->done_count = i;
624 - ohci_put_iso_td(addr, &iso_td); 665 + ohci_put_iso_td(ohci, addr, &iso_td);
625 return 0; 666 return 0;
626 } 667 }
627 668
@@ -696,7 +737,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -696,7 +737,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
696 } 737 }
697 738
698 if (len && dir != OHCI_TD_DIR_IN) { 739 if (len && dir != OHCI_TD_DIR_IN) {
699 - ohci_copy_iso_td(start_addr, end_addr, ohci->usb_buf, len, 0); 740 + ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, len, 0);
700 } 741 }
701 742
702 if (completion) { 743 if (completion) {
@@ -732,7 +773,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -732,7 +773,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
732 /* Writeback */ 773 /* Writeback */
733 if (dir == OHCI_TD_DIR_IN && ret >= 0 && ret <= len) { 774 if (dir == OHCI_TD_DIR_IN && ret >= 0 && ret <= len) {
734 /* IN transfer succeeded */ 775 /* IN transfer succeeded */
735 - ohci_copy_iso_td(start_addr, end_addr, ohci->usb_buf, ret, 1); 776 + ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, ret, 1);
736 OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC, 777 OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
737 OHCI_CC_NOERROR); 778 OHCI_CC_NOERROR);
738 OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, ret); 779 OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, ret);
@@ -788,7 +829,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -788,7 +829,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
788 if (i < ohci->done_count) 829 if (i < ohci->done_count)
789 ohci->done_count = i; 830 ohci->done_count = i;
790 } 831 }
791 - ohci_put_iso_td(addr, &iso_td); 832 + ohci_put_iso_td(ohci, addr, &iso_td);
792 return 1; 833 return 1;
793 } 834 }
794 835
@@ -818,7 +859,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) @@ -818,7 +859,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
818 #endif 859 #endif
819 return 1; 860 return 1;
820 } 861 }
821 - if (!ohci_read_td(addr, &td)) { 862 + if (!ohci_read_td(ohci, addr, &td)) {
822 fprintf(stderr, "usb-ohci: TD read error at %x\n", addr); 863 fprintf(stderr, "usb-ohci: TD read error at %x\n", addr);
823 return 0; 864 return 0;
824 } 865 }
@@ -859,7 +900,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) @@ -859,7 +900,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
859 } 900 }
860 901
861 if (len && dir != OHCI_TD_DIR_IN && !completion) { 902 if (len && dir != OHCI_TD_DIR_IN && !completion) {
862 - ohci_copy_td(&td, ohci->usb_buf, len, 0); 903 + ohci_copy_td(ohci, &td, ohci->usb_buf, len, 0);
863 } 904 }
864 } 905 }
865 906
@@ -918,7 +959,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) @@ -918,7 +959,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
918 } 959 }
919 if (ret >= 0) { 960 if (ret >= 0) {
920 if (dir == OHCI_TD_DIR_IN) { 961 if (dir == OHCI_TD_DIR_IN) {
921 - ohci_copy_td(&td, ohci->usb_buf, ret, 1); 962 + ohci_copy_td(ohci, &td, ohci->usb_buf, ret, 1);
922 #ifdef DEBUG_PACKET 963 #ifdef DEBUG_PACKET
923 dprintf(" data:"); 964 dprintf(" data:");
924 for (i = 0; i < ret; i++) 965 for (i = 0; i < ret; i++)
@@ -987,7 +1028,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) @@ -987,7 +1028,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
987 i = OHCI_BM(td.flags, TD_DI); 1028 i = OHCI_BM(td.flags, TD_DI);
988 if (i < ohci->done_count) 1029 if (i < ohci->done_count)
989 ohci->done_count = i; 1030 ohci->done_count = i;
990 - ohci_put_td(addr, &td); 1031 + ohci_put_td(ohci, addr, &td);
991 return OHCI_BM(td.flags, TD_CC) != OHCI_CC_NOERROR; 1032 return OHCI_BM(td.flags, TD_CC) != OHCI_CC_NOERROR;
992 } 1033 }
993 1034
@@ -1005,7 +1046,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion) @@ -1005,7 +1046,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion)
1005 return 0; 1046 return 0;
1006 1047
1007 for (cur = head; cur; cur = next_ed) { 1048 for (cur = head; cur; cur = next_ed) {
1008 - if (!ohci_read_ed(cur, &ed)) { 1049 + if (!ohci_read_ed(ohci, cur, &ed)) {
1009 fprintf(stderr, "usb-ohci: ED read error at %x\n", cur); 1050 fprintf(stderr, "usb-ohci: ED read error at %x\n", cur);
1010 return 0; 1051 return 0;
1011 } 1052 }
@@ -1046,7 +1087,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion) @@ -1046,7 +1087,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion)
1046 } 1087 }
1047 } 1088 }
1048 1089
1049 - ohci_put_ed(cur, &ed); 1090 + ohci_put_ed(ohci, cur, &ed);
1050 } 1091 }
1051 1092
1052 return active; 1093 return active;
@@ -1087,7 +1128,7 @@ static void ohci_frame_boundary(void *opaque) @@ -1087,7 +1128,7 @@ static void ohci_frame_boundary(void *opaque)
1087 OHCIState *ohci = opaque; 1128 OHCIState *ohci = opaque;
1088 struct ohci_hcca hcca; 1129 struct ohci_hcca hcca;
1089 1130
1090 - cpu_physical_memory_rw(ohci->hcca, (uint8_t *)&hcca, sizeof(hcca), 0); 1131 + ohci_read_hcca(ohci, ohci->hcca, &hcca);
1091 1132
1092 /* Process all the lists at the end of the frame */ 1133 /* Process all the lists at the end of the frame */
1093 if (ohci->ctl & OHCI_CTL_PLE) { 1134 if (ohci->ctl & OHCI_CTL_PLE) {
@@ -1131,7 +1172,7 @@ static void ohci_frame_boundary(void *opaque) @@ -1131,7 +1172,7 @@ static void ohci_frame_boundary(void *opaque)
1131 ohci_sof(ohci); 1172 ohci_sof(ohci);
1132 1173
1133 /* Writeback HCCA */ 1174 /* Writeback HCCA */
1134 - cpu_physical_memory_rw(ohci->hcca, (uint8_t *)&hcca, sizeof(hcca), 1); 1175 + ohci_put_hcca(ohci, ohci->hcca, &hcca);
1135 } 1176 }
1136 1177
1137 /* Start sending SOF tokens across the USB bus, lists are processed in 1178 /* Start sending SOF tokens across the USB bus, lists are processed in
@@ -1620,7 +1661,8 @@ static CPUWriteMemoryFunc *ohci_writefn[3]={ @@ -1620,7 +1661,8 @@ static CPUWriteMemoryFunc *ohci_writefn[3]={
1620 }; 1661 };
1621 1662
1622 static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, 1663 static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn,
1623 - qemu_irq irq, enum ohci_type type, const char *name) 1664 + qemu_irq irq, enum ohci_type type,
  1665 + const char *name, uint32_t localmem_base)
1624 { 1666 {
1625 int i; 1667 int i;
1626 1668
@@ -1641,6 +1683,7 @@ static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, @@ -1641,6 +1683,7 @@ static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn,
1641 } 1683 }
1642 1684
1643 ohci->mem = cpu_register_io_memory(0, ohci_readfn, ohci_writefn, ohci); 1685 ohci->mem = cpu_register_io_memory(0, ohci_readfn, ohci_writefn, ohci);
  1686 + ohci->localmem_base = localmem_base;
1644 ohci->name = name; 1687 ohci->name = name;
1645 1688
1646 ohci->irq = irq; 1689 ohci->irq = irq;
@@ -1687,7 +1730,7 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) @@ -1687,7 +1730,7 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn)
1687 ohci->pci_dev.config[0x3d] = 0x01; /* interrupt pin 1 */ 1730 ohci->pci_dev.config[0x3d] = 0x01; /* interrupt pin 1 */
1688 1731
1689 usb_ohci_init(&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0], 1732 usb_ohci_init(&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0],
1690 - OHCI_TYPE_PCI, ohci->pci_dev.name); 1733 + OHCI_TYPE_PCI, ohci->pci_dev.name, 0);
1691 1734
1692 pci_register_io_region((struct PCIDevice *)ohci, 0, 256, 1735 pci_register_io_region((struct PCIDevice *)ohci, 0, 256,
1693 PCI_ADDRESS_SPACE_MEM, ohci_mapfunc); 1736 PCI_ADDRESS_SPACE_MEM, ohci_mapfunc);
@@ -1699,7 +1742,19 @@ void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, @@ -1699,7 +1742,19 @@ void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn,
1699 OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); 1742 OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState));
1700 1743
1701 usb_ohci_init(ohci, num_ports, devfn, irq, 1744 usb_ohci_init(ohci, num_ports, devfn, irq,
1702 - OHCI_TYPE_PXA, "OHCI USB"); 1745 + OHCI_TYPE_PXA, "OHCI USB", 0);
1703 1746
1704 cpu_register_physical_memory(base, 0x1000, ohci->mem); 1747 cpu_register_physical_memory(base, 0x1000, ohci->mem);
1705 } 1748 }
  1749 +
  1750 +void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base,
  1751 + int num_ports, int devfn, qemu_irq irq)
  1752 +{
  1753 + OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState));
  1754 +
  1755 + usb_ohci_init(ohci, num_ports, devfn, irq,
  1756 + OHCI_TYPE_SM501, "OHCI USB", localmem_base);
  1757 +
  1758 + cpu_register_physical_memory(mmio_base, 0x1000, ohci->mem);
  1759 +}
  1760 +