root / hw / dec_pci.c @ 78895427
History | View | Annotate | Download (3.9 kB)
1 | e1c6bbab | Blue Swirl | /*
|
---|---|---|---|
2 | e1c6bbab | Blue Swirl | * QEMU DEC 21154 PCI bridge
|
3 | e1c6bbab | Blue Swirl | *
|
4 | e1c6bbab | Blue Swirl | * Copyright (c) 2006-2007 Fabrice Bellard
|
5 | e1c6bbab | Blue Swirl | * Copyright (c) 2007 Jocelyn Mayer
|
6 | e1c6bbab | Blue Swirl | *
|
7 | e1c6bbab | Blue Swirl | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | e1c6bbab | Blue Swirl | * of this software and associated documentation files (the "Software"), to deal
|
9 | e1c6bbab | Blue Swirl | * in the Software without restriction, including without limitation the rights
|
10 | e1c6bbab | Blue Swirl | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | e1c6bbab | Blue Swirl | * copies of the Software, and to permit persons to whom the Software is
|
12 | e1c6bbab | Blue Swirl | * furnished to do so, subject to the following conditions:
|
13 | e1c6bbab | Blue Swirl | *
|
14 | e1c6bbab | Blue Swirl | * The above copyright notice and this permission notice shall be included in
|
15 | e1c6bbab | Blue Swirl | * all copies or substantial portions of the Software.
|
16 | e1c6bbab | Blue Swirl | *
|
17 | e1c6bbab | Blue Swirl | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | e1c6bbab | Blue Swirl | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | e1c6bbab | Blue Swirl | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | e1c6bbab | Blue Swirl | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | e1c6bbab | Blue Swirl | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | e1c6bbab | Blue Swirl | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | e1c6bbab | Blue Swirl | * THE SOFTWARE.
|
24 | e1c6bbab | Blue Swirl | */
|
25 | e1c6bbab | Blue Swirl | |
26 | d55380bb | Blue Swirl | #include "dec_pci.h" |
27 | e1c6bbab | Blue Swirl | #include "sysbus.h" |
28 | e1c6bbab | Blue Swirl | #include "pci.h" |
29 | e1c6bbab | Blue Swirl | #include "pci_host.h" |
30 | 783753fd | Isaku Yamahata | #include "pci_bridge.h" |
31 | 68f79994 | Isaku Yamahata | #include "pci_internals.h" |
32 | e1c6bbab | Blue Swirl | |
33 | e1c6bbab | Blue Swirl | /* debug DEC */
|
34 | e1c6bbab | Blue Swirl | //#define DEBUG_DEC
|
35 | e1c6bbab | Blue Swirl | |
36 | e1c6bbab | Blue Swirl | #ifdef DEBUG_DEC
|
37 | e1c6bbab | Blue Swirl | #define DEC_DPRINTF(fmt, ...) \
|
38 | e1c6bbab | Blue Swirl | do { printf("DEC: " fmt , ## __VA_ARGS__); } while (0) |
39 | e1c6bbab | Blue Swirl | #else
|
40 | e1c6bbab | Blue Swirl | #define DEC_DPRINTF(fmt, ...)
|
41 | e1c6bbab | Blue Swirl | #endif
|
42 | e1c6bbab | Blue Swirl | |
43 | e1c6bbab | Blue Swirl | typedef struct DECState { |
44 | e1c6bbab | Blue Swirl | SysBusDevice busdev; |
45 | e1c6bbab | Blue Swirl | PCIHostState host_state; |
46 | e1c6bbab | Blue Swirl | } DECState; |
47 | e1c6bbab | Blue Swirl | |
48 | d55380bb | Blue Swirl | static int dec_map_irq(PCIDevice *pci_dev, int irq_num) |
49 | d55380bb | Blue Swirl | { |
50 | d55380bb | Blue Swirl | return irq_num;
|
51 | d55380bb | Blue Swirl | } |
52 | d55380bb | Blue Swirl | |
53 | 68f79994 | Isaku Yamahata | static int dec_21154_initfn(PCIDevice *dev) |
54 | d55380bb | Blue Swirl | { |
55 | 68f79994 | Isaku Yamahata | int rc;
|
56 | 68f79994 | Isaku Yamahata | |
57 | 68f79994 | Isaku Yamahata | rc = pci_bridge_initfn(dev); |
58 | 68f79994 | Isaku Yamahata | if (rc < 0) { |
59 | 68f79994 | Isaku Yamahata | return rc;
|
60 | 68f79994 | Isaku Yamahata | } |
61 | 68f79994 | Isaku Yamahata | |
62 | 68f79994 | Isaku Yamahata | pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_DEC); |
63 | 68f79994 | Isaku Yamahata | pci_config_set_device_id(dev->config, PCI_DEVICE_ID_DEC_21154); |
64 | 68f79994 | Isaku Yamahata | return 0; |
65 | 68f79994 | Isaku Yamahata | } |
66 | d55380bb | Blue Swirl | |
67 | 68f79994 | Isaku Yamahata | static PCIDeviceInfo dec_21154_pci_bridge_info = {
|
68 | 68f79994 | Isaku Yamahata | .qdev.name = "dec-21154-p2p-bridge",
|
69 | 68f79994 | Isaku Yamahata | .qdev.desc = "DEC 21154 PCI-PCI bridge",
|
70 | 68f79994 | Isaku Yamahata | .qdev.size = sizeof(PCIBridge),
|
71 | 68f79994 | Isaku Yamahata | .qdev.vmsd = &vmstate_pci_device, |
72 | 68f79994 | Isaku Yamahata | .qdev.reset = pci_bridge_reset, |
73 | 68f79994 | Isaku Yamahata | .init = dec_21154_initfn, |
74 | 68f79994 | Isaku Yamahata | .exit = pci_bridge_exitfn, |
75 | 68f79994 | Isaku Yamahata | .config_write = pci_bridge_write_config, |
76 | 68f79994 | Isaku Yamahata | .is_bridge = 1,
|
77 | 68f79994 | Isaku Yamahata | }; |
78 | 68f79994 | Isaku Yamahata | |
79 | 68f79994 | Isaku Yamahata | PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
|
80 | 68f79994 | Isaku Yamahata | { |
81 | 68f79994 | Isaku Yamahata | PCIDevice *dev; |
82 | 68f79994 | Isaku Yamahata | PCIBridge *br; |
83 | d55380bb | Blue Swirl | |
84 | 68f79994 | Isaku Yamahata | dev = pci_create_multifunction(parent_bus, devfn, false,
|
85 | 68f79994 | Isaku Yamahata | "dec-21154-p2p-bridge");
|
86 | 68f79994 | Isaku Yamahata | br = DO_UPCAST(PCIBridge, dev, dev); |
87 | 68f79994 | Isaku Yamahata | pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
|
88 | 68f79994 | Isaku Yamahata | qdev_init_nofail(&dev->qdev); |
89 | 68f79994 | Isaku Yamahata | return pci_bridge_get_sec_bus(br);
|
90 | d55380bb | Blue Swirl | } |
91 | d55380bb | Blue Swirl | |
92 | e1c6bbab | Blue Swirl | static int pci_dec_21154_init_device(SysBusDevice *dev) |
93 | e1c6bbab | Blue Swirl | { |
94 | e1c6bbab | Blue Swirl | DECState *s; |
95 | e1c6bbab | Blue Swirl | int pci_mem_config, pci_mem_data;
|
96 | e1c6bbab | Blue Swirl | |
97 | e1c6bbab | Blue Swirl | s = FROM_SYSBUS(DECState, dev); |
98 | e1c6bbab | Blue Swirl | |
99 | 952760bb | Blue Swirl | pci_mem_config = pci_host_conf_register_mmio(&s->host_state, 1);
|
100 | 952760bb | Blue Swirl | pci_mem_data = pci_host_data_register_mmio(&s->host_state, 1);
|
101 | e1c6bbab | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
102 | e1c6bbab | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
103 | e1c6bbab | Blue Swirl | return 0; |
104 | e1c6bbab | Blue Swirl | } |
105 | e1c6bbab | Blue Swirl | |
106 | e1c6bbab | Blue Swirl | static int dec_21154_pci_host_init(PCIDevice *d) |
107 | e1c6bbab | Blue Swirl | { |
108 | e1c6bbab | Blue Swirl | /* PCI2PCI bridge same values as PearPC - check this */
|
109 | e1c6bbab | Blue Swirl | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC); |
110 | e1c6bbab | Blue Swirl | pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154); |
111 | 204ff571 | Blue Swirl | pci_set_byte(d->config + PCI_REVISION_ID, 0x02);
|
112 | e1c6bbab | Blue Swirl | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI); |
113 | e1c6bbab | Blue Swirl | return 0; |
114 | e1c6bbab | Blue Swirl | } |
115 | e1c6bbab | Blue Swirl | |
116 | e1c6bbab | Blue Swirl | static PCIDeviceInfo dec_21154_pci_host_info = {
|
117 | e1c6bbab | Blue Swirl | .qdev.name = "dec-21154",
|
118 | e1c6bbab | Blue Swirl | .qdev.size = sizeof(PCIDevice),
|
119 | e1c6bbab | Blue Swirl | .init = dec_21154_pci_host_init, |
120 | e327e323 | Isaku Yamahata | .is_bridge = 1,
|
121 | e1c6bbab | Blue Swirl | }; |
122 | e1c6bbab | Blue Swirl | |
123 | e1c6bbab | Blue Swirl | static void dec_register_devices(void) |
124 | e1c6bbab | Blue Swirl | { |
125 | e1c6bbab | Blue Swirl | sysbus_register_dev("dec-21154", sizeof(DECState), |
126 | e1c6bbab | Blue Swirl | pci_dec_21154_init_device); |
127 | e1c6bbab | Blue Swirl | pci_qdev_register(&dec_21154_pci_host_info); |
128 | 68f79994 | Isaku Yamahata | pci_qdev_register(&dec_21154_pci_bridge_info); |
129 | e1c6bbab | Blue Swirl | } |
130 | e1c6bbab | Blue Swirl | |
131 | e1c6bbab | Blue Swirl | device_init(dec_register_devices) |