2 * SuperH on-chip PCIC emulation.
4 * Copyright (c) 2008 Takashi YOSHII
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
29 #include "exec-memory.h"
31 typedef struct SHPCIState
{
42 static void sh_pci_reg_write (void *p
, target_phys_addr_t addr
, uint32_t val
)
47 cpu_to_le32w((uint32_t*)(pcic
->dev
->config
+ addr
), val
);
53 pcic
->mbr
= val
& 0xff000001;
56 if ((val
& 0xfffc0000) != (pcic
->iobr
& 0xfffc0000)) {
57 cpu_register_physical_memory(pcic
->iobr
& 0xfffc0000, 0x40000,
59 pcic
->iobr
= val
& 0xfffc0001;
60 isa_mmio_init(pcic
->iobr
& 0xfffc0000, 0x40000);
64 pci_data_write(pcic
->bus
, pcic
->par
, val
, 4);
69 static uint32_t sh_pci_reg_read (void *p
, target_phys_addr_t addr
)
74 return le32_to_cpup((uint32_t*)(pcic
->dev
->config
+ addr
));
82 return pci_data_read(pcic
->bus
, pcic
->par
, 4);
88 CPUReadMemoryFunc
* const r
[3];
89 CPUWriteMemoryFunc
* const w
[3];
92 static MemOp sh_pci_reg
= {
93 { NULL
, NULL
, sh_pci_reg_read
},
94 { NULL
, NULL
, sh_pci_reg_write
},
97 static int sh_pci_map_irq(PCIDevice
*d
, int irq_num
)
99 return (d
->devfn
>> 3);
102 static void sh_pci_set_irq(void *opaque
, int irq_num
, int level
)
104 qemu_irq
*pic
= opaque
;
106 qemu_set_irq(pic
[irq_num
], level
);
109 static void sh_pci_map(SysBusDevice
*dev
, target_phys_addr_t base
)
111 SHPCIState
*s
= FROM_SYSBUS(SHPCIState
, dev
);
113 cpu_register_physical_memory(P4ADDR(base
), 0x224, s
->memconfig
);
114 cpu_register_physical_memory(A7ADDR(base
), 0x224, s
->memconfig
);
116 s
->iobr
= 0xfe240000;
117 isa_mmio_init(s
->iobr
, 0x40000);
120 static int sh_pci_init_device(SysBusDevice
*dev
)
125 s
= FROM_SYSBUS(SHPCIState
, dev
);
126 for (i
= 0; i
< 4; i
++) {
127 sysbus_init_irq(dev
, &s
->irq
[i
]);
129 s
->bus
= pci_register_bus(&s
->busdev
.qdev
, "pci",
130 sh_pci_set_irq
, sh_pci_map_irq
,
135 s
->memconfig
= cpu_register_io_memory(sh_pci_reg
.r
, sh_pci_reg
.w
,
136 s
, DEVICE_NATIVE_ENDIAN
);
137 sysbus_init_mmio_cb(dev
, 0x224, sh_pci_map
);
138 s
->dev
= pci_create_simple(s
->bus
, PCI_DEVFN(0, 0), "sh_pci_host");
142 static int sh_pci_host_init(PCIDevice
*d
)
144 pci_set_word(d
->config
+ PCI_COMMAND
, PCI_COMMAND_WAIT
);
145 pci_set_word(d
->config
+ PCI_STATUS
, PCI_STATUS_CAP_LIST
|
146 PCI_STATUS_FAST_BACK
| PCI_STATUS_DEVSEL_MEDIUM
);
150 static PCIDeviceInfo sh_pci_host_info
= {
151 .qdev
.name
= "sh_pci_host",
152 .qdev
.size
= sizeof(PCIDevice
),
153 .init
= sh_pci_host_init
,
154 .vendor_id
= PCI_VENDOR_ID_HITACHI
,
155 .device_id
= PCI_DEVICE_ID_HITACHI_SH7751R
,
158 static void sh_pci_register_devices(void)
160 sysbus_register_dev("sh_pci", sizeof(SHPCIState
),
162 pci_qdev_register(&sh_pci_host_info
);
165 device_init(sh_pci_register_devices
)