]> git.proxmox.com Git - mirror_qemu.git/blame - hw/sh_pci.c
Integrate I/O memory regions into qemu
[mirror_qemu.git] / hw / 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 */
cf154394 24#include "sysbus.h"
1e5459a3
AZ
25#include "sh.h"
26#include "pci.h"
b6243d99 27#include "pci_host.h"
1e5459a3 28#include "bswap.h"
1e39101c 29#include "exec-memory.h"
1e5459a3 30
cf154394
AJ
31typedef struct SHPCIState {
32 SysBusDevice busdev;
1e5459a3
AZ
33 PCIBus *bus;
34 PCIDevice *dev;
cf154394
AJ
35 qemu_irq irq[4];
36 int memconfig;
1e5459a3
AZ
37 uint32_t par;
38 uint32_t mbr;
39 uint32_t iobr;
cf154394 40} SHPCIState;
1e5459a3 41
c227f099 42static void sh_pci_reg_write (void *p, target_phys_addr_t addr, uint32_t val)
1e5459a3 43{
cf154394 44 SHPCIState *pcic = p;
1e5459a3
AZ
45 switch(addr) {
46 case 0 ... 0xfc:
47 cpu_to_le32w((uint32_t*)(pcic->dev->config + addr), val);
48 break;
49 case 0x1c0:
50 pcic->par = val;
51 break;
52 case 0x1c4:
5ba9e952 53 pcic->mbr = val & 0xff000001;
1e5459a3
AZ
54 break;
55 case 0x1c8:
5ba9e952
AJ
56 if ((val & 0xfffc0000) != (pcic->iobr & 0xfffc0000)) {
57 cpu_register_physical_memory(pcic->iobr & 0xfffc0000, 0x40000,
58 IO_MEM_UNASSIGNED);
59 pcic->iobr = val & 0xfffc0001;
968d683c 60 isa_mmio_init(pcic->iobr & 0xfffc0000, 0x40000);
5ba9e952 61 }
1e5459a3
AZ
62 break;
63 case 0x220:
64 pci_data_write(pcic->bus, pcic->par, val, 4);
65 break;
66 }
67}
68
c227f099 69static uint32_t sh_pci_reg_read (void *p, target_phys_addr_t addr)
1e5459a3 70{
cf154394 71 SHPCIState *pcic = p;
1e5459a3
AZ
72 switch(addr) {
73 case 0 ... 0xfc:
74 return le32_to_cpup((uint32_t*)(pcic->dev->config + addr));
75 case 0x1c0:
76 return pcic->par;
5ba9e952
AJ
77 case 0x1c4:
78 return pcic->mbr;
79 case 0x1c8:
80 return pcic->iobr;
1e5459a3
AZ
81 case 0x220:
82 return pci_data_read(pcic->bus, pcic->par, 4);
83 }
84 return 0;
85}
86
1e5459a3 87typedef struct {
d60efc6b
BS
88 CPUReadMemoryFunc * const r[3];
89 CPUWriteMemoryFunc * const w[3];
1e5459a3
AZ
90} MemOp;
91
92static MemOp sh_pci_reg = {
93 { NULL, NULL, sh_pci_reg_read },
94 { NULL, NULL, sh_pci_reg_write },
95};
96
cf154394
AJ
97static int sh_pci_map_irq(PCIDevice *d, int irq_num)
98{
99 return (d->devfn >> 3);
100}
101
102static void sh_pci_set_irq(void *opaque, int irq_num, int level)
103{
104 qemu_irq *pic = opaque;
105
106 qemu_set_irq(pic[irq_num], level);
107}
108
109static void sh_pci_map(SysBusDevice *dev, target_phys_addr_t base)
110{
111 SHPCIState *s = FROM_SYSBUS(SHPCIState, dev);
112
113 cpu_register_physical_memory(P4ADDR(base), 0x224, s->memconfig);
114 cpu_register_physical_memory(A7ADDR(base), 0x224, s->memconfig);
115
116 s->iobr = 0xfe240000;
117 isa_mmio_init(s->iobr, 0x40000);
118}
119
120static int sh_pci_init_device(SysBusDevice *dev)
121{
122 SHPCIState *s;
123 int i;
124
125 s = FROM_SYSBUS(SHPCIState, dev);
126 for (i = 0; i < 4; i++) {
127 sysbus_init_irq(dev, &s->irq[i]);
128 }
129 s->bus = pci_register_bus(&s->busdev.qdev, "pci",
130 sh_pci_set_irq, sh_pci_map_irq,
1e39101c
AK
131 s->irq, get_system_memory(),
132 PCI_DEVFN(0, 0), 4);
cf154394
AJ
133 s->memconfig = cpu_register_io_memory(sh_pci_reg.r, sh_pci_reg.w,
134 s, DEVICE_NATIVE_ENDIAN);
135 sysbus_init_mmio_cb(dev, 0x224, sh_pci_map);
136 s->dev = pci_create_simple(s->bus, PCI_DEVFN(0, 0), "sh_pci_host");
137 return 0;
138}
139
140static int sh_pci_host_init(PCIDevice *d)
141{
cf154394
AJ
142 pci_set_word(d->config + PCI_COMMAND, PCI_COMMAND_WAIT);
143 pci_set_word(d->config + PCI_STATUS, PCI_STATUS_CAP_LIST |
144 PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM);
145 return 0;
146}
147
148static PCIDeviceInfo sh_pci_host_info = {
149 .qdev.name = "sh_pci_host",
150 .qdev.size = sizeof(PCIDevice),
151 .init = sh_pci_host_init,
ae2ebad7
IY
152 .vendor_id = PCI_VENDOR_ID_HITACHI,
153 .device_id = PCI_DEVICE_ID_HITACHI_SH7751R,
cf154394
AJ
154};
155
156static void sh_pci_register_devices(void)
1e5459a3 157{
cf154394
AJ
158 sysbus_register_dev("sh_pci", sizeof(SHPCIState),
159 sh_pci_init_device);
160 pci_qdev_register(&sh_pci_host_info);
1e5459a3 161}
cf154394
AJ
162
163device_init(sh_pci_register_devices)