]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pci-host/sh_pci.c
target/arm: Rename arm_cpu_mp_affinity
[mirror_qemu.git] / hw / pci-host / 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 */
0b8fa32f 24
9d4c9946 25#include "qemu/osdep.h"
83c9f4ca 26#include "hw/sysbus.h"
0d09e41a 27#include "hw/sh4/sh.h"
64552b6b 28#include "hw/irq.h"
edf5ca5d 29#include "hw/pci/pci_device.h"
83c9f4ca 30#include "hw/pci/pci_host.h"
1de7afc9 31#include "qemu/bswap.h"
0b8fa32f 32#include "qemu/module.h"
db1015e9 33#include "qom/object.h"
1e5459a3 34
b23ea25f
PB
35#define TYPE_SH_PCI_HOST_BRIDGE "sh_pci"
36
8063396b 37OBJECT_DECLARE_SIMPLE_TYPE(SHPCIState, SH_PCI_HOST_BRIDGE)
b23ea25f 38
db1015e9 39struct SHPCIState {
b23ea25f
PB
40 PCIHostState parent_obj;
41
1e5459a3 42 PCIDevice *dev;
f158d3be 43 qemu_irq irq[PCI_NUM_PINS];
fb57117a
AK
44 MemoryRegion memconfig_p4;
45 MemoryRegion memconfig_a7;
46 MemoryRegion isa;
1e5459a3
AZ
47 uint32_t par;
48 uint32_t mbr;
49 uint32_t iobr;
db1015e9 50};
1e5459a3 51
f94bff13 52static void sh_pci_reg_write(void *p, hwaddr addr, uint64_t val, unsigned size)
1e5459a3 53{
cf154394 54 SHPCIState *pcic = p;
b23ea25f
PB
55 PCIHostState *phb = PCI_HOST_BRIDGE(pcic);
56
f94bff13 57 switch (addr) {
1e5459a3 58 case 0 ... 0xfc:
b7a51124 59 stl_le_p(pcic->dev->config + addr, val);
1e5459a3
AZ
60 break;
61 case 0x1c0:
62 pcic->par = val;
63 break;
64 case 0x1c4:
5ba9e952 65 pcic->mbr = val & 0xff000001;
1e5459a3
AZ
66 break;
67 case 0x1c8:
47d2d36c
GR
68 pcic->iobr = val & 0xfffc0001;
69 memory_region_set_alias_offset(&pcic->isa, val & 0xfffc0000);
1e5459a3
AZ
70 break;
71 case 0x220:
b23ea25f 72 pci_data_write(phb->bus, pcic->par, val, 4);
1e5459a3
AZ
73 break;
74 }
75}
76
f94bff13 77static uint64_t sh_pci_reg_read(void *p, hwaddr addr, unsigned size)
1e5459a3 78{
cf154394 79 SHPCIState *pcic = p;
b23ea25f
PB
80 PCIHostState *phb = PCI_HOST_BRIDGE(pcic);
81
f94bff13 82 switch (addr) {
1e5459a3 83 case 0 ... 0xfc:
b7a51124 84 return ldl_le_p(pcic->dev->config + addr);
1e5459a3
AZ
85 case 0x1c0:
86 return pcic->par;
5ba9e952
AJ
87 case 0x1c4:
88 return pcic->mbr;
89 case 0x1c8:
90 return pcic->iobr;
1e5459a3 91 case 0x220:
b23ea25f 92 return pci_data_read(phb->bus, pcic->par, 4);
1e5459a3
AZ
93 }
94 return 0;
95}
96
fb57117a
AK
97static const MemoryRegionOps sh_pci_reg_ops = {
98 .read = sh_pci_reg_read,
99 .write = sh_pci_reg_write,
100 .endianness = DEVICE_NATIVE_ENDIAN,
101 .valid = {
102 .min_access_size = 4,
103 .max_access_size = 4,
104 },
1e5459a3
AZ
105};
106
cf154394
AJ
107static int sh_pci_map_irq(PCIDevice *d, int irq_num)
108{
8d40def6 109 return PCI_SLOT(d->devfn);
cf154394
AJ
110}
111
112static void sh_pci_set_irq(void *opaque, int irq_num, int level)
113{
114 qemu_irq *pic = opaque;
115
116 qemu_set_irq(pic[irq_num], level);
117}
118
6db7f62b 119static void sh_pcic_host_realize(DeviceState *dev, Error **errp)
cf154394 120{
0e372e58
PMD
121 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
122 SHPCIState *s = SH_PCI_HOST_BRIDGE(dev);
123 PCIHostState *phb = PCI_HOST_BRIDGE(s);
cf154394
AJ
124 int i;
125
cf154394 126 for (i = 0; i < 4; i++) {
0e372e58 127 sysbus_init_irq(sbd, &s->irq[i]);
cf154394 128 }
8e5c952b 129 phb->bus = pci_register_root_bus(dev, "pci",
1115ff6d
DG
130 sh_pci_set_irq, sh_pci_map_irq,
131 s->irq,
132 get_system_memory(),
133 get_system_io(),
f158d3be
PMD
134 PCI_DEVFN(0, 0), PCI_NUM_PINS,
135 TYPE_PCI_BUS);
29776739 136 memory_region_init_io(&s->memconfig_p4, OBJECT(s), &sh_pci_reg_ops, s,
fb57117a 137 "sh_pci", 0x224);
29776739
PB
138 memory_region_init_alias(&s->memconfig_a7, OBJECT(s), "sh_pci.2",
139 &s->memconfig_p4, 0, 0x224);
4759ab6b
PB
140 memory_region_init_alias(&s->isa, OBJECT(s), "sh_pci.isa",
141 get_system_io(), 0, 0x40000);
0e372e58
PMD
142 sysbus_init_mmio(sbd, &s->memconfig_p4);
143 sysbus_init_mmio(sbd, &s->memconfig_a7);
47d2d36c 144 memory_region_add_subregion(get_system_memory(), 0xfe240000, &s->isa);
8c106233 145
b23ea25f 146 s->dev = pci_create_simple(phb->bus, PCI_DEVFN(0, 0), "sh_pci_host");
cf154394
AJ
147}
148
6db7f62b 149static void sh_pcic_pci_realize(PCIDevice *d, Error **errp)
cf154394 150{
cf154394
AJ
151 pci_set_word(d->config + PCI_COMMAND, PCI_COMMAND_WAIT);
152 pci_set_word(d->config + PCI_STATUS, PCI_STATUS_CAP_LIST |
153 PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM);
cf154394
AJ
154}
155
6db7f62b 156static void sh_pcic_pci_class_init(ObjectClass *klass, void *data)
40021f08
AL
157{
158 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
08c58f92 159 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08 160
6db7f62b 161 k->realize = sh_pcic_pci_realize;
40021f08
AL
162 k->vendor_id = PCI_VENDOR_ID_HITACHI;
163 k->device_id = PCI_DEVICE_ID_HITACHI_SH7751R;
08c58f92
MA
164 /*
165 * PCI-facing part of the host bridge, not usable without the
166 * host-facing part, which can't be device_add'ed, yet.
167 */
e90f2a8c 168 dc->user_creatable = false;
40021f08
AL
169}
170
6db7f62b 171static void sh_pcic_host_class_init(ObjectClass *klass, void *data)
999e12bb 172{
0e372e58 173 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 174
6db7f62b 175 dc->realize = sh_pcic_host_realize;
999e12bb
AL
176}
177
bf9e5c1f
PMD
178static const TypeInfo sh_pcic_types[] = {
179 {
180 .name = TYPE_SH_PCI_HOST_BRIDGE,
181 .parent = TYPE_PCI_HOST_BRIDGE,
182 .instance_size = sizeof(SHPCIState),
6db7f62b 183 .class_init = sh_pcic_host_class_init,
bf9e5c1f
PMD
184 }, {
185 .name = "sh_pci_host",
186 .parent = TYPE_PCI_DEVICE,
187 .instance_size = sizeof(PCIDevice),
6db7f62b 188 .class_init = sh_pcic_pci_class_init,
bf9e5c1f
PMD
189 .interfaces = (InterfaceInfo[]) {
190 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
191 { },
192 },
193 },
999e12bb
AL
194};
195
bf9e5c1f 196DEFINE_TYPES(sh_pcic_types)