root / hw / prep_pci.c @ b4b784fe
History | View | Annotate | Download (4.5 kB)
1 | 502a5395 | pbrook | /*
|
---|---|---|---|
2 | 502a5395 | pbrook | * QEMU PREP PCI host
|
3 | 502a5395 | pbrook | *
|
4 | 502a5395 | pbrook | * Copyright (c) 2006 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 502a5395 | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 502a5395 | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | 502a5395 | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | 502a5395 | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 502a5395 | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | 502a5395 | pbrook | * furnished to do so, subject to the following conditions:
|
12 | 502a5395 | pbrook | *
|
13 | 502a5395 | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | 502a5395 | pbrook | * all copies or substantial portions of the Software.
|
15 | 502a5395 | pbrook | *
|
16 | 502a5395 | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 502a5395 | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 502a5395 | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 502a5395 | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 502a5395 | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 502a5395 | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 502a5395 | pbrook | * THE SOFTWARE.
|
23 | 502a5395 | pbrook | */
|
24 | 502a5395 | pbrook | |
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 87ecb68b | pbrook | #include "pci.h" |
27 | 502a5395 | pbrook | #include "pci_host.h" |
28 | 18e08a55 | Michael S. Tsirkin | #include "prep_pci.h" |
29 | 502a5395 | pbrook | |
30 | 502a5395 | pbrook | typedef PCIHostState PREPPCIState;
|
31 | 502a5395 | pbrook | |
32 | c227f099 | Anthony Liguori | static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr) |
33 | 502a5395 | pbrook | { |
34 | 502a5395 | pbrook | int i;
|
35 | 502a5395 | pbrook | |
36 | 502a5395 | pbrook | for(i = 0; i < 11; i++) { |
37 | 502a5395 | pbrook | if ((addr & (1 << (11 + i))) != 0) |
38 | 502a5395 | pbrook | break;
|
39 | 502a5395 | pbrook | } |
40 | 502a5395 | pbrook | return (addr & 0x7ff) | (i << 11); |
41 | 502a5395 | pbrook | } |
42 | 502a5395 | pbrook | |
43 | c227f099 | Anthony Liguori | static void PPC_PCIIO_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) |
44 | 502a5395 | pbrook | { |
45 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
46 | 502a5395 | pbrook | pci_data_write(s->bus, PPC_PCIIO_config(addr), val, 1);
|
47 | 502a5395 | pbrook | } |
48 | 502a5395 | pbrook | |
49 | c227f099 | Anthony Liguori | static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t val) |
50 | 502a5395 | pbrook | { |
51 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
52 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
53 | 502a5395 | pbrook | val = bswap16(val); |
54 | 502a5395 | pbrook | #endif
|
55 | 502a5395 | pbrook | pci_data_write(s->bus, PPC_PCIIO_config(addr), val, 2);
|
56 | 502a5395 | pbrook | } |
57 | 502a5395 | pbrook | |
58 | c227f099 | Anthony Liguori | static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t val) |
59 | 502a5395 | pbrook | { |
60 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
61 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
62 | 502a5395 | pbrook | val = bswap32(val); |
63 | 502a5395 | pbrook | #endif
|
64 | 502a5395 | pbrook | pci_data_write(s->bus, PPC_PCIIO_config(addr), val, 4);
|
65 | 502a5395 | pbrook | } |
66 | 502a5395 | pbrook | |
67 | c227f099 | Anthony Liguori | static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr) |
68 | 502a5395 | pbrook | { |
69 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
70 | 502a5395 | pbrook | uint32_t val; |
71 | 502a5395 | pbrook | val = pci_data_read(s->bus, PPC_PCIIO_config(addr), 1);
|
72 | 502a5395 | pbrook | return val;
|
73 | 502a5395 | pbrook | } |
74 | 502a5395 | pbrook | |
75 | c227f099 | Anthony Liguori | static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) |
76 | 502a5395 | pbrook | { |
77 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
78 | 502a5395 | pbrook | uint32_t val; |
79 | 502a5395 | pbrook | val = pci_data_read(s->bus, PPC_PCIIO_config(addr), 2);
|
80 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
81 | 502a5395 | pbrook | val = bswap16(val); |
82 | 502a5395 | pbrook | #endif
|
83 | 502a5395 | pbrook | return val;
|
84 | 502a5395 | pbrook | } |
85 | 502a5395 | pbrook | |
86 | c227f099 | Anthony Liguori | static uint32_t PPC_PCIIO_readl (void *opaque, target_phys_addr_t addr) |
87 | 502a5395 | pbrook | { |
88 | 502a5395 | pbrook | PREPPCIState *s = opaque; |
89 | 502a5395 | pbrook | uint32_t val; |
90 | 502a5395 | pbrook | val = pci_data_read(s->bus, PPC_PCIIO_config(addr), 4);
|
91 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
92 | 502a5395 | pbrook | val = bswap32(val); |
93 | 502a5395 | pbrook | #endif
|
94 | 502a5395 | pbrook | return val;
|
95 | 502a5395 | pbrook | } |
96 | 502a5395 | pbrook | |
97 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const PPC_PCIIO_write[] = { |
98 | 502a5395 | pbrook | &PPC_PCIIO_writeb, |
99 | 502a5395 | pbrook | &PPC_PCIIO_writew, |
100 | 502a5395 | pbrook | &PPC_PCIIO_writel, |
101 | 502a5395 | pbrook | }; |
102 | 502a5395 | pbrook | |
103 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const PPC_PCIIO_read[] = { |
104 | 502a5395 | pbrook | &PPC_PCIIO_readb, |
105 | 502a5395 | pbrook | &PPC_PCIIO_readw, |
106 | 502a5395 | pbrook | &PPC_PCIIO_readl, |
107 | 502a5395 | pbrook | }; |
108 | 502a5395 | pbrook | |
109 | d2b59317 | pbrook | static int prep_map_irq(PCIDevice *pci_dev, int irq_num) |
110 | 502a5395 | pbrook | { |
111 | 80b3ada7 | pbrook | return (irq_num + (pci_dev->devfn >> 3)) & 1; |
112 | d2b59317 | pbrook | } |
113 | d2b59317 | pbrook | |
114 | 5d4e84c8 | Juan Quintela | static void prep_set_irq(void *opaque, int irq_num, int level) |
115 | d2b59317 | pbrook | { |
116 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
117 | 5d4e84c8 | Juan Quintela | |
118 | 8c9d7f83 | j_mayer | qemu_set_irq(pic[(irq_num & 1) ? 11 : 9] , level); |
119 | 502a5395 | pbrook | } |
120 | 502a5395 | pbrook | |
121 | d537cf6c | pbrook | PCIBus *pci_prep_init(qemu_irq *pic) |
122 | 502a5395 | pbrook | { |
123 | 502a5395 | pbrook | PREPPCIState *s; |
124 | 502a5395 | pbrook | PCIDevice *d; |
125 | 502a5395 | pbrook | int PPC_io_memory;
|
126 | 502a5395 | pbrook | |
127 | 502a5395 | pbrook | s = qemu_mallocz(sizeof(PREPPCIState));
|
128 | 02e2da45 | Paul Brook | s->bus = pci_register_bus(NULL, "pci", |
129 | 02e2da45 | Paul Brook | prep_set_irq, prep_map_irq, pic, 0, 4); |
130 | 502a5395 | pbrook | |
131 | f08b32fe | Isaku Yamahata | pci_host_conf_register_ioport(0xcf8, s);
|
132 | 502a5395 | pbrook | |
133 | 4f5e19e6 | Isaku Yamahata | pci_host_data_register_ioport(0xcfc, s);
|
134 | 502a5395 | pbrook | |
135 | 1eed09cb | Avi Kivity | PPC_io_memory = cpu_register_io_memory(PPC_PCIIO_read, |
136 | 502a5395 | pbrook | PPC_PCIIO_write, s); |
137 | 502a5395 | pbrook | cpu_register_physical_memory(0x80800000, 0x00400000, PPC_io_memory); |
138 | 502a5395 | pbrook | |
139 | 5fafdf24 | ths | /* PCI host bridge */
|
140 | 5fafdf24 | ths | d = pci_register_device(s->bus, "PREP Host Bridge - Motorola Raven",
|
141 | 502a5395 | pbrook | sizeof(PCIDevice), 0, NULL, NULL); |
142 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MOTOROLA); |
143 | deb54399 | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_MOTOROLA_RAVEN); |
144 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
145 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
146 | 502a5395 | pbrook | d->config[0x0C] = 0x08; // cache_line_size |
147 | 502a5395 | pbrook | d->config[0x0D] = 0x10; // latency_timer |
148 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
149 | 502a5395 | pbrook | d->config[0x34] = 0x00; // capabilities_pointer |
150 | 502a5395 | pbrook | |
151 | 502a5395 | pbrook | return s->bus;
|
152 | 502a5395 | pbrook | } |