Revision f1698408 hw/usb-ohci.c
b/hw/usb-ohci.c | ||
---|---|---|
30 | 30 |
#include "qemu-timer.h" |
31 | 31 |
#include "usb.h" |
32 | 32 |
#include "pci.h" |
33 |
#include "pxa.h" |
|
34 | 33 |
#include "devices.h" |
35 | 34 |
#include "usb-ohci.h" |
36 | 35 |
|
... | ... | |
1399 | 1398 |
return; |
1400 | 1399 |
} |
1401 | 1400 |
|
1402 |
static uint32_t ohci_mem_read(void *ptr, target_phys_addr_t addr) |
|
1401 |
static uint32_t ohci_mem_read_le(void *ptr, target_phys_addr_t addr)
|
|
1403 | 1402 |
{ |
1404 | 1403 |
OHCIState *ohci = ptr; |
1405 | 1404 |
uint32_t retval; |
... | ... | |
1516 | 1515 |
retval = 0xffffffff; |
1517 | 1516 |
} |
1518 | 1517 |
} |
1518 |
return retval; |
|
1519 |
} |
|
1520 |
|
|
1521 |
static uint32_t ohci_mem_read_be(void *ptr, target_phys_addr_t addr) |
|
1522 |
{ |
|
1523 |
uint32_t retval; |
|
1519 | 1524 |
|
1520 |
#ifdef TARGET_WORDS_BIGENDIAN
|
|
1525 |
retval = ohci_mem_read_le(ptr, addr);
|
|
1521 | 1526 |
retval = bswap32(retval); |
1522 |
#endif |
|
1523 | 1527 |
return retval; |
1524 | 1528 |
} |
1525 | 1529 |
|
1526 |
static void ohci_mem_write(void *ptr, target_phys_addr_t addr, uint32_t val) |
|
1530 |
static void ohci_mem_write_le(void *ptr, target_phys_addr_t addr, uint32_t val)
|
|
1527 | 1531 |
{ |
1528 | 1532 |
OHCIState *ohci = ptr; |
1529 | 1533 |
|
1530 |
#ifdef TARGET_WORDS_BIGENDIAN |
|
1531 |
val = bswap32(val); |
|
1532 |
#endif |
|
1533 |
|
|
1534 | 1534 |
/* Only aligned reads are allowed on OHCI */ |
1535 | 1535 |
if (addr & 3) { |
1536 | 1536 |
fprintf(stderr, "usb-ohci: Mis-aligned write\n"); |
... | ... | |
1647 | 1647 |
} |
1648 | 1648 |
} |
1649 | 1649 |
|
1650 |
static void ohci_mem_write_be(void *ptr, target_phys_addr_t addr, uint32_t val) |
|
1651 |
{ |
|
1652 |
val = bswap32(val); |
|
1653 |
ohci_mem_write_le(ptr, addr, val); |
|
1654 |
} |
|
1655 |
|
|
1650 | 1656 |
/* Only dword reads are defined on OHCI register space */ |
1651 |
static CPUReadMemoryFunc * const ohci_readfn[3]={ |
|
1652 |
ohci_mem_read, |
|
1653 |
ohci_mem_read, |
|
1654 |
ohci_mem_read |
|
1657 |
static CPUReadMemoryFunc * const ohci_readfn_be[3]={
|
|
1658 |
ohci_mem_read_be,
|
|
1659 |
ohci_mem_read_be,
|
|
1660 |
ohci_mem_read_be
|
|
1655 | 1661 |
}; |
1656 | 1662 |
|
1657 | 1663 |
/* Only dword writes are defined on OHCI register space */ |
1658 |
static CPUWriteMemoryFunc * const ohci_writefn[3]={ |
|
1659 |
ohci_mem_write, |
|
1660 |
ohci_mem_write, |
|
1661 |
ohci_mem_write |
|
1664 |
static CPUWriteMemoryFunc * const ohci_writefn_be[3]={ |
|
1665 |
ohci_mem_write_be, |
|
1666 |
ohci_mem_write_be, |
|
1667 |
ohci_mem_write_be |
|
1668 |
}; |
|
1669 |
|
|
1670 |
static CPUReadMemoryFunc * const ohci_readfn_le[3]={ |
|
1671 |
ohci_mem_read_le, |
|
1672 |
ohci_mem_read_le, |
|
1673 |
ohci_mem_read_le |
|
1674 |
}; |
|
1675 |
|
|
1676 |
static CPUWriteMemoryFunc * const ohci_writefn_le[3]={ |
|
1677 |
ohci_mem_write_le, |
|
1678 |
ohci_mem_write_le, |
|
1679 |
ohci_mem_write_le |
|
1662 | 1680 |
}; |
1663 | 1681 |
|
1664 | 1682 |
static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, |
1665 | 1683 |
int num_ports, int devfn, |
1666 | 1684 |
qemu_irq irq, enum ohci_type type, |
1667 |
const char *name, uint32_t localmem_base) |
|
1685 |
const char *name, uint32_t localmem_base, |
|
1686 |
int be) |
|
1668 | 1687 |
{ |
1669 | 1688 |
int i; |
1670 | 1689 |
|
... | ... | |
1684 | 1703 |
usb_frame_time, usb_bit_time); |
1685 | 1704 |
} |
1686 | 1705 |
|
1687 |
ohci->mem = cpu_register_io_memory(ohci_readfn, ohci_writefn, ohci); |
|
1706 |
if (be) { |
|
1707 |
ohci->mem = cpu_register_io_memory(ohci_readfn_be, ohci_writefn_be, |
|
1708 |
ohci); |
|
1709 |
} else { |
|
1710 |
ohci->mem = cpu_register_io_memory(ohci_readfn_le, ohci_writefn_le, |
|
1711 |
ohci); |
|
1712 |
} |
|
1688 | 1713 |
ohci->localmem_base = localmem_base; |
1689 | 1714 |
ohci->name = name; |
1690 | 1715 |
|
... | ... | |
1704 | 1729 |
typedef struct { |
1705 | 1730 |
PCIDevice pci_dev; |
1706 | 1731 |
OHCIState state; |
1732 |
uint32_t be; |
|
1707 | 1733 |
} OHCIPCIState; |
1708 | 1734 |
|
1709 | 1735 |
static void ohci_mapfunc(PCIDevice *pci_dev, int i, |
... | ... | |
1728 | 1754 |
|
1729 | 1755 |
usb_ohci_init(&ohci->state, &dev->qdev, num_ports, |
1730 | 1756 |
ohci->pci_dev.devfn, ohci->pci_dev.irq[0], |
1731 |
OHCI_TYPE_PCI, ohci->pci_dev.name, 0); |
|
1757 |
OHCI_TYPE_PCI, ohci->pci_dev.name, 0, ohci->be);
|
|
1732 | 1758 |
|
1733 | 1759 |
/* TODO: avoid cast below by using dev */ |
1734 | 1760 |
pci_register_bar((struct PCIDevice *)ohci, 0, 256, |
... | ... | |
1736 | 1762 |
return 0; |
1737 | 1763 |
} |
1738 | 1764 |
|
1739 |
void usb_ohci_init_pci(struct PCIBus *bus, int devfn) |
|
1765 |
void usb_ohci_init_pci(struct PCIBus *bus, int devfn, int be)
|
|
1740 | 1766 |
{ |
1741 |
pci_create_simple(bus, devfn, "pci-ohci"); |
|
1767 |
PCIDevice *dev; |
|
1768 |
|
|
1769 |
dev = pci_create(bus, devfn, "pci-ohci"); |
|
1770 |
qdev_prop_set_uint32(&dev->qdev, "be", be); |
|
1771 |
qdev_init_nofail(&dev->qdev); |
|
1742 | 1772 |
} |
1743 | 1773 |
|
1744 | 1774 |
void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, |
1745 |
qemu_irq irq) |
|
1775 |
qemu_irq irq, int be)
|
|
1746 | 1776 |
{ |
1747 | 1777 |
OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); |
1748 | 1778 |
|
1749 | 1779 |
usb_ohci_init(ohci, NULL /* FIXME */, num_ports, devfn, irq, |
1750 |
OHCI_TYPE_PXA, "OHCI USB", 0); |
|
1780 |
OHCI_TYPE_PXA, "OHCI USB", 0, be);
|
|
1751 | 1781 |
|
1752 | 1782 |
cpu_register_physical_memory(base, 0x1000, ohci->mem); |
1753 | 1783 |
} |
1754 | 1784 |
|
1755 | 1785 |
void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base, |
1756 |
int num_ports, int devfn, qemu_irq irq) |
|
1786 |
int num_ports, int devfn, qemu_irq irq, int be)
|
|
1757 | 1787 |
{ |
1758 | 1788 |
OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); |
1759 | 1789 |
|
1760 | 1790 |
usb_ohci_init(ohci, NULL /* FIXME */, num_ports, devfn, irq, |
1761 |
OHCI_TYPE_SM501, "OHCI USB", localmem_base); |
|
1791 |
OHCI_TYPE_SM501, "OHCI USB", localmem_base, be);
|
|
1762 | 1792 |
|
1763 | 1793 |
cpu_register_physical_memory(mmio_base, 0x1000, ohci->mem); |
1764 | 1794 |
} |
... | ... | |
1768 | 1798 |
.qdev.desc = "Apple USB Controller", |
1769 | 1799 |
.qdev.size = sizeof(OHCIPCIState), |
1770 | 1800 |
.init = usb_ohci_initfn_pci, |
1801 |
.qdev.props = (Property[]) { |
|
1802 |
DEFINE_PROP_HEX32("be", OHCIPCIState, be, 0), |
|
1803 |
DEFINE_PROP_END_OF_LIST(), |
|
1804 |
} |
|
1771 | 1805 |
}; |
1772 | 1806 |
|
1773 | 1807 |
static void ohci_register(void) |
Also available in: Unified diff