Statistics
| Branch: | Revision:

root / hw / misc / pci-testdev.c @ 327ed10f

History | View | Annotate | Download (8.9 kB)

1 22773d60 Michael S. Tsirkin
/*
2 22773d60 Michael S. Tsirkin
 * QEMU PCI test device
3 22773d60 Michael S. Tsirkin
 *
4 22773d60 Michael S. Tsirkin
 * Copyright (c) 2012 Red Hat Inc.
5 22773d60 Michael S. Tsirkin
 * Author: Michael S. Tsirkin <mst@redhat.com>
6 22773d60 Michael S. Tsirkin
 *
7 22773d60 Michael S. Tsirkin
 * This program is free software; you can redistribute it and/or modify
8 22773d60 Michael S. Tsirkin
 * it under the terms of the GNU General Public License as published by
9 22773d60 Michael S. Tsirkin
 * the Free Software Foundation; either version 2 of the License, or
10 22773d60 Michael S. Tsirkin
 * (at your option) any later version.
11 22773d60 Michael S. Tsirkin
 *
12 22773d60 Michael S. Tsirkin
 * This program is distributed in the hope that it will be useful,
13 22773d60 Michael S. Tsirkin
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 22773d60 Michael S. Tsirkin
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 22773d60 Michael S. Tsirkin
 * GNU General Public License for more details.
16 22773d60 Michael S. Tsirkin
 *
17 22773d60 Michael S. Tsirkin
 * You should have received a copy of the GNU General Public License along
18 22773d60 Michael S. Tsirkin
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 22773d60 Michael S. Tsirkin
 */
20 22773d60 Michael S. Tsirkin
#include "hw/hw.h"
21 22773d60 Michael S. Tsirkin
#include "hw/pci/pci.h"
22 22773d60 Michael S. Tsirkin
#include "qemu/event_notifier.h"
23 22773d60 Michael S. Tsirkin
#include "qemu/osdep.h"
24 22773d60 Michael S. Tsirkin
25 22773d60 Michael S. Tsirkin
typedef struct PCITestDevHdr {
26 22773d60 Michael S. Tsirkin
    uint8_t test;
27 22773d60 Michael S. Tsirkin
    uint8_t width;
28 22773d60 Michael S. Tsirkin
    uint8_t pad0[2];
29 22773d60 Michael S. Tsirkin
    uint32_t offset;
30 22773d60 Michael S. Tsirkin
    uint8_t data;
31 22773d60 Michael S. Tsirkin
    uint8_t pad1[3];
32 22773d60 Michael S. Tsirkin
    uint32_t count;
33 22773d60 Michael S. Tsirkin
    uint8_t name[];
34 22773d60 Michael S. Tsirkin
} PCITestDevHdr;
35 22773d60 Michael S. Tsirkin
36 22773d60 Michael S. Tsirkin
typedef struct IOTest {
37 22773d60 Michael S. Tsirkin
    MemoryRegion *mr;
38 22773d60 Michael S. Tsirkin
    EventNotifier notifier;
39 22773d60 Michael S. Tsirkin
    bool hasnotifier;
40 22773d60 Michael S. Tsirkin
    unsigned size;
41 22773d60 Michael S. Tsirkin
    bool match_data;
42 22773d60 Michael S. Tsirkin
    PCITestDevHdr *hdr;
43 22773d60 Michael S. Tsirkin
    unsigned bufsize;
44 22773d60 Michael S. Tsirkin
} IOTest;
45 22773d60 Michael S. Tsirkin
46 22773d60 Michael S. Tsirkin
#define IOTEST_DATAMATCH 0xFA
47 22773d60 Michael S. Tsirkin
#define IOTEST_NOMATCH   0xCE
48 22773d60 Michael S. Tsirkin
49 22773d60 Michael S. Tsirkin
#define IOTEST_IOSIZE 128
50 22773d60 Michael S. Tsirkin
#define IOTEST_MEMSIZE 2048
51 22773d60 Michael S. Tsirkin
52 22773d60 Michael S. Tsirkin
static const char *iotest_test[] = {
53 22773d60 Michael S. Tsirkin
    "no-eventfd",
54 22773d60 Michael S. Tsirkin
    "wildcard-eventfd",
55 22773d60 Michael S. Tsirkin
    "datamatch-eventfd"
56 22773d60 Michael S. Tsirkin
};
57 22773d60 Michael S. Tsirkin
58 22773d60 Michael S. Tsirkin
static const char *iotest_type[] = {
59 22773d60 Michael S. Tsirkin
    "mmio",
60 22773d60 Michael S. Tsirkin
    "portio"
61 22773d60 Michael S. Tsirkin
};
62 22773d60 Michael S. Tsirkin
63 22773d60 Michael S. Tsirkin
#define IOTEST_TEST(i) (iotest_test[((i) % ARRAY_SIZE(iotest_test))])
64 22773d60 Michael S. Tsirkin
#define IOTEST_TYPE(i) (iotest_type[((i) / ARRAY_SIZE(iotest_test))])
65 22773d60 Michael S. Tsirkin
#define IOTEST_MAX_TEST (ARRAY_SIZE(iotest_test))
66 22773d60 Michael S. Tsirkin
#define IOTEST_MAX_TYPE (ARRAY_SIZE(iotest_type))
67 22773d60 Michael S. Tsirkin
#define IOTEST_MAX (IOTEST_MAX_TEST * IOTEST_MAX_TYPE)
68 22773d60 Michael S. Tsirkin
69 22773d60 Michael S. Tsirkin
enum {
70 22773d60 Michael S. Tsirkin
    IOTEST_ACCESS_NAME,
71 22773d60 Michael S. Tsirkin
    IOTEST_ACCESS_DATA,
72 22773d60 Michael S. Tsirkin
    IOTEST_ACCESS_MAX,
73 22773d60 Michael S. Tsirkin
};
74 22773d60 Michael S. Tsirkin
75 22773d60 Michael S. Tsirkin
#define IOTEST_ACCESS_TYPE uint8_t
76 22773d60 Michael S. Tsirkin
#define IOTEST_ACCESS_WIDTH (sizeof(uint8_t))
77 22773d60 Michael S. Tsirkin
78 22773d60 Michael S. Tsirkin
typedef struct PCITestDevState {
79 6d27a409 Andreas Färber
    /*< private >*/
80 6d27a409 Andreas Färber
    PCIDevice parent_obj;
81 6d27a409 Andreas Färber
    /*< public >*/
82 6d27a409 Andreas Färber
83 22773d60 Michael S. Tsirkin
    MemoryRegion mmio;
84 22773d60 Michael S. Tsirkin
    MemoryRegion portio;
85 22773d60 Michael S. Tsirkin
    IOTest *tests;
86 22773d60 Michael S. Tsirkin
    int current;
87 22773d60 Michael S. Tsirkin
} PCITestDevState;
88 22773d60 Michael S. Tsirkin
89 40108d0a Peter Crosthwaite
#define TYPE_PCI_TEST_DEV "pci-testdev"
90 40108d0a Peter Crosthwaite
91 40108d0a Peter Crosthwaite
#define PCI_TEST_DEV(obj) \
92 40108d0a Peter Crosthwaite
    OBJECT_CHECK(PCITestDevState, (obj), TYPE_PCI_TEST_DEV)
93 40108d0a Peter Crosthwaite
94 22773d60 Michael S. Tsirkin
#define IOTEST_IS_MEM(i) (strcmp(IOTEST_TYPE(i), "portio"))
95 22773d60 Michael S. Tsirkin
#define IOTEST_REGION(d, i) (IOTEST_IS_MEM(i) ?  &(d)->mmio : &(d)->portio)
96 22773d60 Michael S. Tsirkin
#define IOTEST_SIZE(i) (IOTEST_IS_MEM(i) ? IOTEST_MEMSIZE : IOTEST_IOSIZE)
97 22773d60 Michael S. Tsirkin
#define IOTEST_PCI_BAR(i) (IOTEST_IS_MEM(i) ? PCI_BASE_ADDRESS_SPACE_MEMORY : \
98 22773d60 Michael S. Tsirkin
                           PCI_BASE_ADDRESS_SPACE_IO)
99 22773d60 Michael S. Tsirkin
100 22773d60 Michael S. Tsirkin
static int pci_testdev_start(IOTest *test)
101 22773d60 Michael S. Tsirkin
{
102 22773d60 Michael S. Tsirkin
    test->hdr->count = 0;
103 22773d60 Michael S. Tsirkin
    if (!test->hasnotifier) {
104 22773d60 Michael S. Tsirkin
        return 0;
105 22773d60 Michael S. Tsirkin
    }
106 22773d60 Michael S. Tsirkin
    event_notifier_test_and_clear(&test->notifier);
107 22773d60 Michael S. Tsirkin
    memory_region_add_eventfd(test->mr,
108 22773d60 Michael S. Tsirkin
                              le32_to_cpu(test->hdr->offset),
109 22773d60 Michael S. Tsirkin
                              test->size,
110 22773d60 Michael S. Tsirkin
                              test->match_data,
111 22773d60 Michael S. Tsirkin
                              test->hdr->data,
112 22773d60 Michael S. Tsirkin
                              &test->notifier);
113 22773d60 Michael S. Tsirkin
    return 0;
114 22773d60 Michael S. Tsirkin
}
115 22773d60 Michael S. Tsirkin
116 22773d60 Michael S. Tsirkin
static void pci_testdev_stop(IOTest *test)
117 22773d60 Michael S. Tsirkin
{
118 22773d60 Michael S. Tsirkin
    if (!test->hasnotifier) {
119 22773d60 Michael S. Tsirkin
        return;
120 22773d60 Michael S. Tsirkin
    }
121 22773d60 Michael S. Tsirkin
    memory_region_del_eventfd(test->mr,
122 22773d60 Michael S. Tsirkin
                              le32_to_cpu(test->hdr->offset),
123 22773d60 Michael S. Tsirkin
                              test->size,
124 22773d60 Michael S. Tsirkin
                              test->match_data,
125 22773d60 Michael S. Tsirkin
                              test->hdr->data,
126 22773d60 Michael S. Tsirkin
                              &test->notifier);
127 22773d60 Michael S. Tsirkin
}
128 22773d60 Michael S. Tsirkin
129 22773d60 Michael S. Tsirkin
static void
130 22773d60 Michael S. Tsirkin
pci_testdev_reset(PCITestDevState *d)
131 22773d60 Michael S. Tsirkin
{
132 22773d60 Michael S. Tsirkin
    if (d->current == -1) {
133 22773d60 Michael S. Tsirkin
        return;
134 22773d60 Michael S. Tsirkin
    }
135 22773d60 Michael S. Tsirkin
    pci_testdev_stop(&d->tests[d->current]);
136 22773d60 Michael S. Tsirkin
    d->current = -1;
137 22773d60 Michael S. Tsirkin
}
138 22773d60 Michael S. Tsirkin
139 22773d60 Michael S. Tsirkin
static void pci_testdev_inc(IOTest *test, unsigned inc)
140 22773d60 Michael S. Tsirkin
{
141 22773d60 Michael S. Tsirkin
    uint32_t c = le32_to_cpu(test->hdr->count);
142 22773d60 Michael S. Tsirkin
    test->hdr->count = cpu_to_le32(c + inc);
143 22773d60 Michael S. Tsirkin
}
144 22773d60 Michael S. Tsirkin
145 22773d60 Michael S. Tsirkin
static void
146 22773d60 Michael S. Tsirkin
pci_testdev_write(void *opaque, hwaddr addr, uint64_t val,
147 22773d60 Michael S. Tsirkin
                  unsigned size, int type)
148 22773d60 Michael S. Tsirkin
{
149 22773d60 Michael S. Tsirkin
    PCITestDevState *d = opaque;
150 22773d60 Michael S. Tsirkin
    IOTest *test;
151 22773d60 Michael S. Tsirkin
    int t, r;
152 22773d60 Michael S. Tsirkin
153 22773d60 Michael S. Tsirkin
    if (addr == offsetof(PCITestDevHdr, test)) {
154 22773d60 Michael S. Tsirkin
        pci_testdev_reset(d);
155 22773d60 Michael S. Tsirkin
        if (val >= IOTEST_MAX_TEST) {
156 22773d60 Michael S. Tsirkin
            return;
157 22773d60 Michael S. Tsirkin
        }
158 22773d60 Michael S. Tsirkin
        t = type * IOTEST_MAX_TEST + val;
159 22773d60 Michael S. Tsirkin
        r = pci_testdev_start(&d->tests[t]);
160 22773d60 Michael S. Tsirkin
        if (r < 0) {
161 22773d60 Michael S. Tsirkin
            return;
162 22773d60 Michael S. Tsirkin
        }
163 22773d60 Michael S. Tsirkin
        d->current = t;
164 22773d60 Michael S. Tsirkin
        return;
165 22773d60 Michael S. Tsirkin
    }
166 22773d60 Michael S. Tsirkin
    if (d->current < 0) {
167 22773d60 Michael S. Tsirkin
        return;
168 22773d60 Michael S. Tsirkin
    }
169 22773d60 Michael S. Tsirkin
    test = &d->tests[d->current];
170 22773d60 Michael S. Tsirkin
    if (addr != le32_to_cpu(test->hdr->offset)) {
171 22773d60 Michael S. Tsirkin
        return;
172 22773d60 Michael S. Tsirkin
    }
173 22773d60 Michael S. Tsirkin
    if (test->match_data && test->size != size) {
174 22773d60 Michael S. Tsirkin
        return;
175 22773d60 Michael S. Tsirkin
    }
176 22773d60 Michael S. Tsirkin
    if (test->match_data && val != test->hdr->data) {
177 22773d60 Michael S. Tsirkin
        return;
178 22773d60 Michael S. Tsirkin
    }
179 22773d60 Michael S. Tsirkin
    pci_testdev_inc(test, 1);
180 22773d60 Michael S. Tsirkin
}
181 22773d60 Michael S. Tsirkin
182 22773d60 Michael S. Tsirkin
static uint64_t
183 22773d60 Michael S. Tsirkin
pci_testdev_read(void *opaque, hwaddr addr, unsigned size)
184 22773d60 Michael S. Tsirkin
{
185 22773d60 Michael S. Tsirkin
    PCITestDevState *d = opaque;
186 22773d60 Michael S. Tsirkin
    const char *buf;
187 22773d60 Michael S. Tsirkin
    IOTest *test;
188 22773d60 Michael S. Tsirkin
    if (d->current < 0) {
189 22773d60 Michael S. Tsirkin
        return 0;
190 22773d60 Michael S. Tsirkin
    }
191 22773d60 Michael S. Tsirkin
    test = &d->tests[d->current];
192 22773d60 Michael S. Tsirkin
    buf = (const char *)test->hdr;
193 22773d60 Michael S. Tsirkin
    if (addr + size >= test->bufsize) {
194 22773d60 Michael S. Tsirkin
        return 0;
195 22773d60 Michael S. Tsirkin
    }
196 22773d60 Michael S. Tsirkin
    if (test->hasnotifier) {
197 22773d60 Michael S. Tsirkin
        event_notifier_test_and_clear(&test->notifier);
198 22773d60 Michael S. Tsirkin
    }
199 22773d60 Michael S. Tsirkin
    return buf[addr];
200 22773d60 Michael S. Tsirkin
}
201 22773d60 Michael S. Tsirkin
202 22773d60 Michael S. Tsirkin
static void
203 22773d60 Michael S. Tsirkin
pci_testdev_mmio_write(void *opaque, hwaddr addr, uint64_t val,
204 22773d60 Michael S. Tsirkin
                       unsigned size)
205 22773d60 Michael S. Tsirkin
{
206 22773d60 Michael S. Tsirkin
    pci_testdev_write(opaque, addr, val, size, 0);
207 22773d60 Michael S. Tsirkin
}
208 22773d60 Michael S. Tsirkin
209 22773d60 Michael S. Tsirkin
static void
210 22773d60 Michael S. Tsirkin
pci_testdev_pio_write(void *opaque, hwaddr addr, uint64_t val,
211 22773d60 Michael S. Tsirkin
                       unsigned size)
212 22773d60 Michael S. Tsirkin
{
213 22773d60 Michael S. Tsirkin
    pci_testdev_write(opaque, addr, val, size, 1);
214 22773d60 Michael S. Tsirkin
}
215 22773d60 Michael S. Tsirkin
216 22773d60 Michael S. Tsirkin
static const MemoryRegionOps pci_testdev_mmio_ops = {
217 22773d60 Michael S. Tsirkin
    .read = pci_testdev_read,
218 22773d60 Michael S. Tsirkin
    .write = pci_testdev_mmio_write,
219 22773d60 Michael S. Tsirkin
    .endianness = DEVICE_LITTLE_ENDIAN,
220 22773d60 Michael S. Tsirkin
    .impl = {
221 22773d60 Michael S. Tsirkin
        .min_access_size = 1,
222 22773d60 Michael S. Tsirkin
        .max_access_size = 1,
223 22773d60 Michael S. Tsirkin
    },
224 22773d60 Michael S. Tsirkin
};
225 22773d60 Michael S. Tsirkin
226 22773d60 Michael S. Tsirkin
static const MemoryRegionOps pci_testdev_pio_ops = {
227 22773d60 Michael S. Tsirkin
    .read = pci_testdev_read,
228 22773d60 Michael S. Tsirkin
    .write = pci_testdev_pio_write,
229 22773d60 Michael S. Tsirkin
    .endianness = DEVICE_LITTLE_ENDIAN,
230 22773d60 Michael S. Tsirkin
    .impl = {
231 22773d60 Michael S. Tsirkin
        .min_access_size = 1,
232 22773d60 Michael S. Tsirkin
        .max_access_size = 1,
233 22773d60 Michael S. Tsirkin
    },
234 22773d60 Michael S. Tsirkin
};
235 22773d60 Michael S. Tsirkin
236 22773d60 Michael S. Tsirkin
static int pci_testdev_init(PCIDevice *pci_dev)
237 22773d60 Michael S. Tsirkin
{
238 40108d0a Peter Crosthwaite
    PCITestDevState *d = PCI_TEST_DEV(pci_dev);
239 22773d60 Michael S. Tsirkin
    uint8_t *pci_conf;
240 22773d60 Michael S. Tsirkin
    char *name;
241 22773d60 Michael S. Tsirkin
    int r, i;
242 22773d60 Michael S. Tsirkin
243 6d27a409 Andreas Färber
    pci_conf = pci_dev->config;
244 22773d60 Michael S. Tsirkin
245 22773d60 Michael S. Tsirkin
    pci_conf[PCI_INTERRUPT_PIN] = 0; /* no interrupt pin */
246 22773d60 Michael S. Tsirkin
247 3c161542 Paolo Bonzini
    memory_region_init_io(&d->mmio, OBJECT(d), &pci_testdev_mmio_ops, d,
248 22773d60 Michael S. Tsirkin
                          "pci-testdev-mmio", IOTEST_MEMSIZE * 2);
249 3c161542 Paolo Bonzini
    memory_region_init_io(&d->portio, OBJECT(d), &pci_testdev_pio_ops, d,
250 22773d60 Michael S. Tsirkin
                          "pci-testdev-portio", IOTEST_IOSIZE * 2);
251 6d27a409 Andreas Färber
    pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio);
252 6d27a409 Andreas Färber
    pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &d->portio);
253 22773d60 Michael S. Tsirkin
254 22773d60 Michael S. Tsirkin
    d->current = -1;
255 22773d60 Michael S. Tsirkin
    d->tests = g_malloc0(IOTEST_MAX * sizeof *d->tests);
256 22773d60 Michael S. Tsirkin
    for (i = 0; i < IOTEST_MAX; ++i) {
257 22773d60 Michael S. Tsirkin
        IOTest *test = &d->tests[i];
258 22773d60 Michael S. Tsirkin
        name = g_strdup_printf("%s-%s", IOTEST_TYPE(i), IOTEST_TEST(i));
259 22773d60 Michael S. Tsirkin
        test->bufsize = sizeof(PCITestDevHdr) + strlen(name) + 1;
260 22773d60 Michael S. Tsirkin
        test->hdr = g_malloc0(test->bufsize);
261 22773d60 Michael S. Tsirkin
        memcpy(test->hdr->name, name, strlen(name) + 1);
262 22773d60 Michael S. Tsirkin
        g_free(name);
263 22773d60 Michael S. Tsirkin
        test->hdr->offset = cpu_to_le32(IOTEST_SIZE(i) + i * IOTEST_ACCESS_WIDTH);
264 22773d60 Michael S. Tsirkin
        test->size = IOTEST_ACCESS_WIDTH;
265 22773d60 Michael S. Tsirkin
        test->match_data = strcmp(IOTEST_TEST(i), "wildcard-eventfd");
266 22773d60 Michael S. Tsirkin
        test->hdr->test = i;
267 22773d60 Michael S. Tsirkin
        test->hdr->data = test->match_data ? IOTEST_DATAMATCH : IOTEST_NOMATCH;
268 22773d60 Michael S. Tsirkin
        test->hdr->width = IOTEST_ACCESS_WIDTH;
269 22773d60 Michael S. Tsirkin
        test->mr = IOTEST_REGION(d, i);
270 22773d60 Michael S. Tsirkin
        if (!strcmp(IOTEST_TEST(i), "no-eventfd")) {
271 22773d60 Michael S. Tsirkin
            test->hasnotifier = false;
272 22773d60 Michael S. Tsirkin
            continue;
273 22773d60 Michael S. Tsirkin
        }
274 22773d60 Michael S. Tsirkin
        r = event_notifier_init(&test->notifier, 0);
275 22773d60 Michael S. Tsirkin
        assert(r >= 0);
276 22773d60 Michael S. Tsirkin
        test->hasnotifier = true;
277 22773d60 Michael S. Tsirkin
    }
278 22773d60 Michael S. Tsirkin
279 22773d60 Michael S. Tsirkin
    return 0;
280 22773d60 Michael S. Tsirkin
}
281 22773d60 Michael S. Tsirkin
282 22773d60 Michael S. Tsirkin
static void
283 22773d60 Michael S. Tsirkin
pci_testdev_uninit(PCIDevice *dev)
284 22773d60 Michael S. Tsirkin
{
285 40108d0a Peter Crosthwaite
    PCITestDevState *d = PCI_TEST_DEV(dev);
286 22773d60 Michael S. Tsirkin
    int i;
287 22773d60 Michael S. Tsirkin
288 22773d60 Michael S. Tsirkin
    pci_testdev_reset(d);
289 22773d60 Michael S. Tsirkin
    for (i = 0; i < IOTEST_MAX; ++i) {
290 22773d60 Michael S. Tsirkin
        if (d->tests[i].hasnotifier) {
291 22773d60 Michael S. Tsirkin
            event_notifier_cleanup(&d->tests[i].notifier);
292 22773d60 Michael S. Tsirkin
        }
293 22773d60 Michael S. Tsirkin
        g_free(d->tests[i].hdr);
294 22773d60 Michael S. Tsirkin
    }
295 22773d60 Michael S. Tsirkin
    g_free(d->tests);
296 22773d60 Michael S. Tsirkin
    memory_region_destroy(&d->mmio);
297 22773d60 Michael S. Tsirkin
    memory_region_destroy(&d->portio);
298 22773d60 Michael S. Tsirkin
}
299 22773d60 Michael S. Tsirkin
300 22773d60 Michael S. Tsirkin
static void qdev_pci_testdev_reset(DeviceState *dev)
301 22773d60 Michael S. Tsirkin
{
302 40108d0a Peter Crosthwaite
    PCITestDevState *d = PCI_TEST_DEV(dev);
303 22773d60 Michael S. Tsirkin
    pci_testdev_reset(d);
304 22773d60 Michael S. Tsirkin
}
305 22773d60 Michael S. Tsirkin
306 22773d60 Michael S. Tsirkin
static void pci_testdev_class_init(ObjectClass *klass, void *data)
307 22773d60 Michael S. Tsirkin
{
308 22773d60 Michael S. Tsirkin
    DeviceClass *dc = DEVICE_CLASS(klass);
309 22773d60 Michael S. Tsirkin
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
310 22773d60 Michael S. Tsirkin
311 22773d60 Michael S. Tsirkin
    k->init = pci_testdev_init;
312 22773d60 Michael S. Tsirkin
    k->exit = pci_testdev_uninit;
313 22773d60 Michael S. Tsirkin
    k->vendor_id = PCI_VENDOR_ID_REDHAT;
314 22773d60 Michael S. Tsirkin
    k->device_id = PCI_DEVICE_ID_REDHAT_TEST;
315 22773d60 Michael S. Tsirkin
    k->revision = 0x00;
316 22773d60 Michael S. Tsirkin
    k->class_id = PCI_CLASS_OTHERS;
317 22773d60 Michael S. Tsirkin
    dc->desc = "PCI Test Device";
318 125ee0ed Marcel Apfelbaum
    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
319 22773d60 Michael S. Tsirkin
    dc->reset = qdev_pci_testdev_reset;
320 22773d60 Michael S. Tsirkin
}
321 22773d60 Michael S. Tsirkin
322 22773d60 Michael S. Tsirkin
static const TypeInfo pci_testdev_info = {
323 40108d0a Peter Crosthwaite
    .name          = TYPE_PCI_TEST_DEV,
324 22773d60 Michael S. Tsirkin
    .parent        = TYPE_PCI_DEVICE,
325 22773d60 Michael S. Tsirkin
    .instance_size = sizeof(PCITestDevState),
326 22773d60 Michael S. Tsirkin
    .class_init    = pci_testdev_class_init,
327 22773d60 Michael S. Tsirkin
};
328 22773d60 Michael S. Tsirkin
329 22773d60 Michael S. Tsirkin
static void pci_testdev_register_types(void)
330 22773d60 Michael S. Tsirkin
{
331 22773d60 Michael S. Tsirkin
    type_register_static(&pci_testdev_info);
332 22773d60 Michael S. Tsirkin
}
333 22773d60 Michael S. Tsirkin
334 22773d60 Michael S. Tsirkin
type_init(pci_testdev_register_types)