root / hw / sh_pci.c @ 1e39101c
History | View | Annotate | Download (4.7 kB)
1 | 1e5459a3 | balrog | /*
|
---|---|---|---|
2 | 1e5459a3 | balrog | * SuperH on-chip PCIC emulation.
|
3 | 1e5459a3 | balrog | *
|
4 | 1e5459a3 | balrog | * Copyright (c) 2008 Takashi YOSHII
|
5 | 1e5459a3 | balrog | *
|
6 | 1e5459a3 | balrog | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 1e5459a3 | balrog | * of this software and associated documentation files (the "Software"), to deal
|
8 | 1e5459a3 | balrog | * in the Software without restriction, including without limitation the rights
|
9 | 1e5459a3 | balrog | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 1e5459a3 | balrog | * copies of the Software, and to permit persons to whom the Software is
|
11 | 1e5459a3 | balrog | * furnished to do so, subject to the following conditions:
|
12 | 1e5459a3 | balrog | *
|
13 | 1e5459a3 | balrog | * The above copyright notice and this permission notice shall be included in
|
14 | 1e5459a3 | balrog | * all copies or substantial portions of the Software.
|
15 | 1e5459a3 | balrog | *
|
16 | 1e5459a3 | balrog | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 1e5459a3 | balrog | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 1e5459a3 | balrog | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 1e5459a3 | balrog | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 1e5459a3 | balrog | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 1e5459a3 | balrog | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 1e5459a3 | balrog | * THE SOFTWARE.
|
23 | 1e5459a3 | balrog | */
|
24 | cf154394 | Aurelien Jarno | #include "sysbus.h" |
25 | 1e5459a3 | balrog | #include "sh.h" |
26 | 1e5459a3 | balrog | #include "pci.h" |
27 | b6243d99 | Isaku Yamahata | #include "pci_host.h" |
28 | 1e5459a3 | balrog | #include "bswap.h" |
29 | 1e39101c | Avi Kivity | #include "exec-memory.h" |
30 | 1e5459a3 | balrog | |
31 | cf154394 | Aurelien Jarno | typedef struct SHPCIState { |
32 | cf154394 | Aurelien Jarno | SysBusDevice busdev; |
33 | 1e5459a3 | balrog | PCIBus *bus; |
34 | 1e5459a3 | balrog | PCIDevice *dev; |
35 | cf154394 | Aurelien Jarno | qemu_irq irq[4];
|
36 | cf154394 | Aurelien Jarno | int memconfig;
|
37 | 1e5459a3 | balrog | uint32_t par; |
38 | 1e5459a3 | balrog | uint32_t mbr; |
39 | 1e5459a3 | balrog | uint32_t iobr; |
40 | cf154394 | Aurelien Jarno | } SHPCIState; |
41 | 1e5459a3 | balrog | |
42 | c227f099 | Anthony Liguori | static void sh_pci_reg_write (void *p, target_phys_addr_t addr, uint32_t val) |
43 | 1e5459a3 | balrog | { |
44 | cf154394 | Aurelien Jarno | SHPCIState *pcic = p; |
45 | 1e5459a3 | balrog | switch(addr) {
|
46 | 1e5459a3 | balrog | case 0 ... 0xfc: |
47 | 1e5459a3 | balrog | cpu_to_le32w((uint32_t*)(pcic->dev->config + addr), val); |
48 | 1e5459a3 | balrog | break;
|
49 | 1e5459a3 | balrog | case 0x1c0: |
50 | 1e5459a3 | balrog | pcic->par = val; |
51 | 1e5459a3 | balrog | break;
|
52 | 1e5459a3 | balrog | case 0x1c4: |
53 | 5ba9e952 | Aurelien Jarno | pcic->mbr = val & 0xff000001;
|
54 | 1e5459a3 | balrog | break;
|
55 | 1e5459a3 | balrog | case 0x1c8: |
56 | 5ba9e952 | Aurelien Jarno | if ((val & 0xfffc0000) != (pcic->iobr & 0xfffc0000)) { |
57 | 5ba9e952 | Aurelien Jarno | cpu_register_physical_memory(pcic->iobr & 0xfffc0000, 0x40000, |
58 | 5ba9e952 | Aurelien Jarno | IO_MEM_UNASSIGNED); |
59 | 5ba9e952 | Aurelien Jarno | pcic->iobr = val & 0xfffc0001;
|
60 | 968d683c | Alexander Graf | isa_mmio_init(pcic->iobr & 0xfffc0000, 0x40000); |
61 | 5ba9e952 | Aurelien Jarno | } |
62 | 1e5459a3 | balrog | break;
|
63 | 1e5459a3 | balrog | case 0x220: |
64 | 1e5459a3 | balrog | pci_data_write(pcic->bus, pcic->par, val, 4);
|
65 | 1e5459a3 | balrog | break;
|
66 | 1e5459a3 | balrog | } |
67 | 1e5459a3 | balrog | } |
68 | 1e5459a3 | balrog | |
69 | c227f099 | Anthony Liguori | static uint32_t sh_pci_reg_read (void *p, target_phys_addr_t addr) |
70 | 1e5459a3 | balrog | { |
71 | cf154394 | Aurelien Jarno | SHPCIState *pcic = p; |
72 | 1e5459a3 | balrog | switch(addr) {
|
73 | 1e5459a3 | balrog | case 0 ... 0xfc: |
74 | 1e5459a3 | balrog | return le32_to_cpup((uint32_t*)(pcic->dev->config + addr));
|
75 | 1e5459a3 | balrog | case 0x1c0: |
76 | 1e5459a3 | balrog | return pcic->par;
|
77 | 5ba9e952 | Aurelien Jarno | case 0x1c4: |
78 | 5ba9e952 | Aurelien Jarno | return pcic->mbr;
|
79 | 5ba9e952 | Aurelien Jarno | case 0x1c8: |
80 | 5ba9e952 | Aurelien Jarno | return pcic->iobr;
|
81 | 1e5459a3 | balrog | case 0x220: |
82 | 1e5459a3 | balrog | return pci_data_read(pcic->bus, pcic->par, 4); |
83 | 1e5459a3 | balrog | } |
84 | 1e5459a3 | balrog | return 0; |
85 | 1e5459a3 | balrog | } |
86 | 1e5459a3 | balrog | |
87 | 1e5459a3 | balrog | typedef struct { |
88 | d60efc6b | Blue Swirl | CPUReadMemoryFunc * const r[3]; |
89 | d60efc6b | Blue Swirl | CPUWriteMemoryFunc * const w[3]; |
90 | 1e5459a3 | balrog | } MemOp; |
91 | 1e5459a3 | balrog | |
92 | 1e5459a3 | balrog | static MemOp sh_pci_reg = {
|
93 | 1e5459a3 | balrog | { NULL, NULL, sh_pci_reg_read }, |
94 | 1e5459a3 | balrog | { NULL, NULL, sh_pci_reg_write }, |
95 | 1e5459a3 | balrog | }; |
96 | 1e5459a3 | balrog | |
97 | cf154394 | Aurelien Jarno | static int sh_pci_map_irq(PCIDevice *d, int irq_num) |
98 | cf154394 | Aurelien Jarno | { |
99 | cf154394 | Aurelien Jarno | return (d->devfn >> 3); |
100 | cf154394 | Aurelien Jarno | } |
101 | cf154394 | Aurelien Jarno | |
102 | cf154394 | Aurelien Jarno | static void sh_pci_set_irq(void *opaque, int irq_num, int level) |
103 | cf154394 | Aurelien Jarno | { |
104 | cf154394 | Aurelien Jarno | qemu_irq *pic = opaque; |
105 | cf154394 | Aurelien Jarno | |
106 | cf154394 | Aurelien Jarno | qemu_set_irq(pic[irq_num], level); |
107 | cf154394 | Aurelien Jarno | } |
108 | cf154394 | Aurelien Jarno | |
109 | cf154394 | Aurelien Jarno | static void sh_pci_map(SysBusDevice *dev, target_phys_addr_t base) |
110 | cf154394 | Aurelien Jarno | { |
111 | cf154394 | Aurelien Jarno | SHPCIState *s = FROM_SYSBUS(SHPCIState, dev); |
112 | cf154394 | Aurelien Jarno | |
113 | cf154394 | Aurelien Jarno | cpu_register_physical_memory(P4ADDR(base), 0x224, s->memconfig);
|
114 | cf154394 | Aurelien Jarno | cpu_register_physical_memory(A7ADDR(base), 0x224, s->memconfig);
|
115 | cf154394 | Aurelien Jarno | |
116 | cf154394 | Aurelien Jarno | s->iobr = 0xfe240000;
|
117 | cf154394 | Aurelien Jarno | isa_mmio_init(s->iobr, 0x40000);
|
118 | cf154394 | Aurelien Jarno | } |
119 | cf154394 | Aurelien Jarno | |
120 | cf154394 | Aurelien Jarno | static int sh_pci_init_device(SysBusDevice *dev) |
121 | cf154394 | Aurelien Jarno | { |
122 | cf154394 | Aurelien Jarno | SHPCIState *s; |
123 | cf154394 | Aurelien Jarno | int i;
|
124 | cf154394 | Aurelien Jarno | |
125 | cf154394 | Aurelien Jarno | s = FROM_SYSBUS(SHPCIState, dev); |
126 | cf154394 | Aurelien Jarno | for (i = 0; i < 4; i++) { |
127 | cf154394 | Aurelien Jarno | sysbus_init_irq(dev, &s->irq[i]); |
128 | cf154394 | Aurelien Jarno | } |
129 | cf154394 | Aurelien Jarno | s->bus = pci_register_bus(&s->busdev.qdev, "pci",
|
130 | cf154394 | Aurelien Jarno | sh_pci_set_irq, sh_pci_map_irq, |
131 | 1e39101c | Avi Kivity | s->irq, get_system_memory(), |
132 | 1e39101c | Avi Kivity | PCI_DEVFN(0, 0), 4); |
133 | cf154394 | Aurelien Jarno | s->memconfig = cpu_register_io_memory(sh_pci_reg.r, sh_pci_reg.w, |
134 | cf154394 | Aurelien Jarno | s, DEVICE_NATIVE_ENDIAN); |
135 | cf154394 | Aurelien Jarno | sysbus_init_mmio_cb(dev, 0x224, sh_pci_map);
|
136 | cf154394 | Aurelien Jarno | s->dev = pci_create_simple(s->bus, PCI_DEVFN(0, 0), "sh_pci_host"); |
137 | cf154394 | Aurelien Jarno | return 0; |
138 | cf154394 | Aurelien Jarno | } |
139 | cf154394 | Aurelien Jarno | |
140 | cf154394 | Aurelien Jarno | static int sh_pci_host_init(PCIDevice *d) |
141 | cf154394 | Aurelien Jarno | { |
142 | cf154394 | Aurelien Jarno | pci_set_word(d->config + PCI_COMMAND, PCI_COMMAND_WAIT); |
143 | cf154394 | Aurelien Jarno | pci_set_word(d->config + PCI_STATUS, PCI_STATUS_CAP_LIST | |
144 | cf154394 | Aurelien Jarno | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); |
145 | cf154394 | Aurelien Jarno | return 0; |
146 | cf154394 | Aurelien Jarno | } |
147 | cf154394 | Aurelien Jarno | |
148 | cf154394 | Aurelien Jarno | static PCIDeviceInfo sh_pci_host_info = {
|
149 | cf154394 | Aurelien Jarno | .qdev.name = "sh_pci_host",
|
150 | cf154394 | Aurelien Jarno | .qdev.size = sizeof(PCIDevice),
|
151 | cf154394 | Aurelien Jarno | .init = sh_pci_host_init, |
152 | ae2ebad7 | Isaku Yamahata | .vendor_id = PCI_VENDOR_ID_HITACHI, |
153 | ae2ebad7 | Isaku Yamahata | .device_id = PCI_DEVICE_ID_HITACHI_SH7751R, |
154 | cf154394 | Aurelien Jarno | }; |
155 | cf154394 | Aurelien Jarno | |
156 | cf154394 | Aurelien Jarno | static void sh_pci_register_devices(void) |
157 | 1e5459a3 | balrog | { |
158 | cf154394 | Aurelien Jarno | sysbus_register_dev("sh_pci", sizeof(SHPCIState), |
159 | cf154394 | Aurelien Jarno | sh_pci_init_device); |
160 | cf154394 | Aurelien Jarno | pci_qdev_register(&sh_pci_host_info); |
161 | 1e5459a3 | balrog | } |
162 | cf154394 | Aurelien Jarno | |
163 | cf154394 | Aurelien Jarno | device_init(sh_pci_register_devices) |