]> Git Repo - qemu.git/blame - hw/sh4/sh_pci.c
Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into...
[qemu.git] / hw / sh4 / sh_pci.c
CommitLineData
1e5459a3
AZ
1/*
2 * SuperH on-chip PCIC emulation.
3 *
4 * Copyright (c) 2008 Takashi YOSHII
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
9d4c9946 24#include "qemu/osdep.h"
83c9f4ca 25#include "hw/sysbus.h"
0d09e41a 26#include "hw/sh4/sh.h"
83c9f4ca
PB
27#include "hw/pci/pci.h"
28#include "hw/pci/pci_host.h"
1de7afc9 29#include "qemu/bswap.h"
022c62cb 30#include "exec/address-spaces.h"
1e5459a3 31
b23ea25f
PB
32#define TYPE_SH_PCI_HOST_BRIDGE "sh_pci"
33
34#define SH_PCI_HOST_BRIDGE(obj) \
35 OBJECT_CHECK(SHPCIState, (obj), TYPE_SH_PCI_HOST_BRIDGE)
36
cf154394 37typedef struct SHPCIState {
b23ea25f
PB
38 PCIHostState parent_obj;
39
1e5459a3 40 PCIDevice *dev;
cf154394 41 qemu_irq irq[4];
fb57117a
AK
42 MemoryRegion memconfig_p4;
43 MemoryRegion memconfig_a7;
44 MemoryRegion isa;
1e5459a3
AZ
45 uint32_t par;
46 uint32_t mbr;
47 uint32_t iobr;
cf154394 48} SHPCIState;
1e5459a3 49
a8170e5e 50static void sh_pci_reg_write (void *p, hwaddr addr, uint64_t val,
fb57117a 51 unsigned size)
1e5459a3 52{
cf154394 53 SHPCIState *pcic = p;
b23ea25f
PB
54 PCIHostState *phb = PCI_HOST_BRIDGE(pcic);
55
1e5459a3
AZ
56 switch(addr) {
57 case 0 ... 0xfc:
b7a51124 58 stl_le_p(pcic->dev->config + addr, val);
1e5459a3
AZ
59 break;
60 case 0x1c0:
61 pcic->par = val;
62 break;
63 case 0x1c4:
5ba9e952 64 pcic->mbr = val & 0xff000001;
1e5459a3
AZ
65 break;
66 case 0x1c8:
5ba9e952 67 if ((val & 0xfffc0000) != (pcic->iobr & 0xfffc0000)) {
fb57117a 68 memory_region_del_subregion(get_system_memory(), &pcic->isa);
5ba9e952 69 pcic->iobr = val & 0xfffc0001;
fb57117a
AK
70 memory_region_add_subregion(get_system_memory(),
71 pcic->iobr & 0xfffc0000, &pcic->isa);
5ba9e952 72 }
1e5459a3
AZ
73 break;
74 case 0x220:
b23ea25f 75 pci_data_write(phb->bus, pcic->par, val, 4);
1e5459a3
AZ
76 break;
77 }
78}
79
a8170e5e 80static uint64_t sh_pci_reg_read (void *p, hwaddr addr,
fb57117a 81 unsigned size)
1e5459a3 82{
cf154394 83 SHPCIState *pcic = p;
b23ea25f
PB
84 PCIHostState *phb = PCI_HOST_BRIDGE(pcic);
85
1e5459a3
AZ
86 switch(addr) {
87 case 0 ... 0xfc:
b7a51124 88 return ldl_le_p(pcic->dev->config + addr);
1e5459a3
AZ
89 case 0x1c0:
90 return pcic->par;
5ba9e952
AJ
91 case 0x1c4:
92 return pcic->mbr;
93 case 0x1c8:
94 return pcic->iobr;
1e5459a3 95 case 0x220:
b23ea25f 96 return pci_data_read(phb->bus, pcic->par, 4);
1e5459a3
AZ
97 }
98 return 0;
99}
100
fb57117a
AK
101static const MemoryRegionOps sh_pci_reg_ops = {
102 .read = sh_pci_reg_read,
103 .write = sh_pci_reg_write,
104 .endianness = DEVICE_NATIVE_ENDIAN,
105 .valid = {
106 .min_access_size = 4,
107 .max_access_size = 4,
108 },
1e5459a3
AZ
109};
110
cf154394
AJ
111static int sh_pci_map_irq(PCIDevice *d, int irq_num)
112{
113 return (d->devfn >> 3);
114}
115
116static void sh_pci_set_irq(void *opaque, int irq_num, int level)
117{
118 qemu_irq *pic = opaque;
119
120 qemu_set_irq(pic[irq_num], level);
121}
122
0e372e58 123static void sh_pci_device_realize(DeviceState *dev, Error **errp)
cf154394 124{
0e372e58
PMD
125 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
126 SHPCIState *s = SH_PCI_HOST_BRIDGE(dev);
127 PCIHostState *phb = PCI_HOST_BRIDGE(s);
cf154394
AJ
128 int i;
129
cf154394 130 for (i = 0; i < 4; i++) {
0e372e58 131 sysbus_init_irq(sbd, &s->irq[i]);
cf154394 132 }
1115ff6d
DG
133 phb->bus = pci_register_root_bus(DEVICE(dev), "pci",
134 sh_pci_set_irq, sh_pci_map_irq,
135 s->irq,
136 get_system_memory(),
137 get_system_io(),
138 PCI_DEVFN(0, 0), 4, TYPE_PCI_BUS);
29776739 139 memory_region_init_io(&s->memconfig_p4, OBJECT(s), &sh_pci_reg_ops, s,
fb57117a 140 "sh_pci", 0x224);
29776739
PB
141 memory_region_init_alias(&s->memconfig_a7, OBJECT(s), "sh_pci.2",
142 &s->memconfig_p4, 0, 0x224);
4759ab6b
PB
143 memory_region_init_alias(&s->isa, OBJECT(s), "sh_pci.isa",
144 get_system_io(), 0, 0x40000);
0e372e58
PMD
145 sysbus_init_mmio(sbd, &s->memconfig_p4);
146 sysbus_init_mmio(sbd, &s->memconfig_a7);
8c106233
BC
147 s->iobr = 0xfe240000;
148 memory_region_add_subregion(get_system_memory(), s->iobr, &s->isa);
149
b23ea25f 150 s->dev = pci_create_simple(phb->bus, PCI_DEVFN(0, 0), "sh_pci_host");
cf154394
AJ
151}
152
9f23b27d 153static void sh_pci_host_realize(PCIDevice *d, Error **errp)
cf154394 154{
cf154394
AJ
155 pci_set_word(d->config + PCI_COMMAND, PCI_COMMAND_WAIT);
156 pci_set_word(d->config + PCI_STATUS, PCI_STATUS_CAP_LIST |
157 PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM);
cf154394
AJ
158}
159
40021f08
AL
160static void sh_pci_host_class_init(ObjectClass *klass, void *data)
161{
162 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
08c58f92 163 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08 164
9f23b27d 165 k->realize = sh_pci_host_realize;
40021f08
AL
166 k->vendor_id = PCI_VENDOR_ID_HITACHI;
167 k->device_id = PCI_DEVICE_ID_HITACHI_SH7751R;
08c58f92
MA
168 /*
169 * PCI-facing part of the host bridge, not usable without the
170 * host-facing part, which can't be device_add'ed, yet.
171 */
e90f2a8c 172 dc->user_creatable = false;
40021f08
AL
173}
174
8c43a6f0 175static const TypeInfo sh_pci_host_info = {
39bffca2
AL
176 .name = "sh_pci_host",
177 .parent = TYPE_PCI_DEVICE,
178 .instance_size = sizeof(PCIDevice),
179 .class_init = sh_pci_host_class_init,
fd3b02c8
EH
180 .interfaces = (InterfaceInfo[]) {
181 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
182 { },
183 },
cf154394
AJ
184};
185
999e12bb
AL
186static void sh_pci_device_class_init(ObjectClass *klass, void *data)
187{
0e372e58 188 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 189
0e372e58 190 dc->realize = sh_pci_device_realize;
999e12bb
AL
191}
192
8c43a6f0 193static const TypeInfo sh_pci_device_info = {
b23ea25f
PB
194 .name = TYPE_SH_PCI_HOST_BRIDGE,
195 .parent = TYPE_PCI_HOST_BRIDGE,
39bffca2
AL
196 .instance_size = sizeof(SHPCIState),
197 .class_init = sh_pci_device_class_init,
999e12bb
AL
198};
199
83f7d43a 200static void sh_pci_register_types(void)
1e5459a3 201{
39bffca2
AL
202 type_register_static(&sh_pci_device_info);
203 type_register_static(&sh_pci_host_info);
1e5459a3 204}
cf154394 205
83f7d43a 206type_init(sh_pci_register_types)
This page took 0.864571 seconds and 4 git commands to generate.