Statistics
| Branch: | Revision:

root / hw / pci_host.h @ 356c7ff4

History | View | Annotate | Download (3.8 kB)

1 502a5395 pbrook
/*
2 502a5395 pbrook
 * QEMU Common PCI Host bridge configuration data space access routines.
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 502a5395 pbrook
/* Worker routines for a PCI host controller that uses an {address,data}
26 502a5395 pbrook
   register pair to access PCI configuration space.  */
27 502a5395 pbrook
28 8026037b blueswir1
/* debug PCI */
29 8026037b blueswir1
//#define DEBUG_PCI
30 8026037b blueswir1
31 8026037b blueswir1
#ifdef DEBUG_PCI
32 001faf32 Blue Swirl
#define PCI_DPRINTF(fmt, ...) \
33 001faf32 Blue Swirl
do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
34 8026037b blueswir1
#else
35 001faf32 Blue Swirl
#define PCI_DPRINTF(fmt, ...)
36 8026037b blueswir1
#endif
37 8026037b blueswir1
38 502a5395 pbrook
typedef struct {
39 502a5395 pbrook
    uint32_t config_reg;
40 502a5395 pbrook
    PCIBus *bus;
41 502a5395 pbrook
} PCIHostState;
42 502a5395 pbrook
43 502a5395 pbrook
static void pci_host_data_writeb(void* opaque, pci_addr_t addr, uint32_t val)
44 502a5395 pbrook
{
45 502a5395 pbrook
    PCIHostState *s = opaque;
46 8026037b blueswir1
47 8026037b blueswir1
    PCI_DPRINTF("writeb addr " TARGET_FMT_plx " val %x\n",
48 8026037b blueswir1
                (target_phys_addr_t)addr, val);
49 502a5395 pbrook
    if (s->config_reg & (1u << 31))
50 502a5395 pbrook
        pci_data_write(s->bus, s->config_reg | (addr & 3), val, 1);
51 502a5395 pbrook
}
52 502a5395 pbrook
53 502a5395 pbrook
static void pci_host_data_writew(void* opaque, pci_addr_t addr, uint32_t val)
54 502a5395 pbrook
{
55 502a5395 pbrook
    PCIHostState *s = opaque;
56 502a5395 pbrook
#ifdef TARGET_WORDS_BIGENDIAN
57 502a5395 pbrook
    val = bswap16(val);
58 502a5395 pbrook
#endif
59 8026037b blueswir1
    PCI_DPRINTF("writew addr " TARGET_FMT_plx " val %x\n",
60 8026037b blueswir1
                (target_phys_addr_t)addr, val);
61 502a5395 pbrook
    if (s->config_reg & (1u << 31))
62 502a5395 pbrook
        pci_data_write(s->bus, s->config_reg | (addr & 3), val, 2);
63 502a5395 pbrook
}
64 502a5395 pbrook
65 502a5395 pbrook
static void pci_host_data_writel(void* opaque, pci_addr_t addr, uint32_t val)
66 502a5395 pbrook
{
67 502a5395 pbrook
    PCIHostState *s = opaque;
68 502a5395 pbrook
#ifdef TARGET_WORDS_BIGENDIAN
69 502a5395 pbrook
    val = bswap32(val);
70 502a5395 pbrook
#endif
71 8026037b blueswir1
    PCI_DPRINTF("writel addr " TARGET_FMT_plx " val %x\n",
72 8026037b blueswir1
                (target_phys_addr_t)addr, val);
73 502a5395 pbrook
    if (s->config_reg & (1u << 31))
74 502a5395 pbrook
        pci_data_write(s->bus, s->config_reg, val, 4);
75 502a5395 pbrook
}
76 502a5395 pbrook
77 502a5395 pbrook
static uint32_t pci_host_data_readb(void* opaque, pci_addr_t addr)
78 502a5395 pbrook
{
79 502a5395 pbrook
    PCIHostState *s = opaque;
80 8026037b blueswir1
    uint32_t val;
81 8026037b blueswir1
82 502a5395 pbrook
    if (!(s->config_reg & (1 << 31)))
83 502a5395 pbrook
        return 0xff;
84 8026037b blueswir1
    val = pci_data_read(s->bus, s->config_reg | (addr & 3), 1);
85 8026037b blueswir1
    PCI_DPRINTF("readb addr " TARGET_FMT_plx " val %x\n",
86 8026037b blueswir1
                (target_phys_addr_t)addr, val);
87 8026037b blueswir1
    return val;
88 502a5395 pbrook
}
89 502a5395 pbrook
90 502a5395 pbrook
static uint32_t pci_host_data_readw(void* opaque, pci_addr_t addr)
91 502a5395 pbrook
{
92 502a5395 pbrook
    PCIHostState *s = opaque;
93 502a5395 pbrook
    uint32_t val;
94 502a5395 pbrook
    if (!(s->config_reg & (1 << 31)))
95 502a5395 pbrook
        return 0xffff;
96 502a5395 pbrook
    val = pci_data_read(s->bus, s->config_reg | (addr & 3), 2);
97 8026037b blueswir1
    PCI_DPRINTF("readw addr " TARGET_FMT_plx " val %x\n",
98 8026037b blueswir1
                (target_phys_addr_t)addr, val);
99 502a5395 pbrook
#ifdef TARGET_WORDS_BIGENDIAN
100 502a5395 pbrook
    val = bswap16(val);
101 502a5395 pbrook
#endif
102 502a5395 pbrook
    return val;
103 502a5395 pbrook
}
104 502a5395 pbrook
105 502a5395 pbrook
static uint32_t pci_host_data_readl(void* opaque, pci_addr_t addr)
106 502a5395 pbrook
{
107 502a5395 pbrook
    PCIHostState *s = opaque;
108 502a5395 pbrook
    uint32_t val;
109 502a5395 pbrook
    if (!(s->config_reg & (1 << 31)))
110 502a5395 pbrook
        return 0xffffffff;
111 502a5395 pbrook
    val = pci_data_read(s->bus, s->config_reg | (addr & 3), 4);
112 8026037b blueswir1
    PCI_DPRINTF("readl addr " TARGET_FMT_plx " val %x\n",
113 8026037b blueswir1
                (target_phys_addr_t)addr, val);
114 502a5395 pbrook
#ifdef TARGET_WORDS_BIGENDIAN
115 502a5395 pbrook
    val = bswap32(val);
116 502a5395 pbrook
#endif
117 502a5395 pbrook
    return val;
118 502a5395 pbrook
}