root / hw / xen / xen_pvdevice.c @ 8fbab3b6
History | View | Annotate | Download (4.1 kB)
1 | 8fbab3b6 | Paul Durrant | /* Copyright (c) Citrix Systems Inc.
|
---|---|---|---|
2 | 8fbab3b6 | Paul Durrant | * All rights reserved.
|
3 | 8fbab3b6 | Paul Durrant | *
|
4 | 8fbab3b6 | Paul Durrant | * Redistribution and use in source and binary forms,
|
5 | 8fbab3b6 | Paul Durrant | * with or without modification, are permitted provided
|
6 | 8fbab3b6 | Paul Durrant | * that the following conditions are met:
|
7 | 8fbab3b6 | Paul Durrant | *
|
8 | 8fbab3b6 | Paul Durrant | * * Redistributions of source code must retain the above
|
9 | 8fbab3b6 | Paul Durrant | * copyright notice, this list of conditions and the
|
10 | 8fbab3b6 | Paul Durrant | * following disclaimer.
|
11 | 8fbab3b6 | Paul Durrant | * * Redistributions in binary form must reproduce the above
|
12 | 8fbab3b6 | Paul Durrant | * copyright notice, this list of conditions and the
|
13 | 8fbab3b6 | Paul Durrant | * following disclaimer in the documentation and/or other
|
14 | 8fbab3b6 | Paul Durrant | * materials provided with the distribution.
|
15 | 8fbab3b6 | Paul Durrant | *
|
16 | 8fbab3b6 | Paul Durrant | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
17 | 8fbab3b6 | Paul Durrant | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18 | 8fbab3b6 | Paul Durrant | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19 | 8fbab3b6 | Paul Durrant | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 | 8fbab3b6 | Paul Durrant | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
21 | 8fbab3b6 | Paul Durrant | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 8fbab3b6 | Paul Durrant | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
23 | 8fbab3b6 | Paul Durrant | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24 | 8fbab3b6 | Paul Durrant | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 | 8fbab3b6 | Paul Durrant | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
26 | 8fbab3b6 | Paul Durrant | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27 | 8fbab3b6 | Paul Durrant | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28 | 8fbab3b6 | Paul Durrant | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
29 | 8fbab3b6 | Paul Durrant | * SUCH DAMAGE.
|
30 | 8fbab3b6 | Paul Durrant | */
|
31 | 8fbab3b6 | Paul Durrant | |
32 | 8fbab3b6 | Paul Durrant | #include "hw/hw.h" |
33 | 8fbab3b6 | Paul Durrant | #include "hw/pci/pci.h" |
34 | 8fbab3b6 | Paul Durrant | #include "trace.h" |
35 | 8fbab3b6 | Paul Durrant | |
36 | 8fbab3b6 | Paul Durrant | #define TYPE_XEN_PV_DEVICE "xen-pvdevice" |
37 | 8fbab3b6 | Paul Durrant | |
38 | 8fbab3b6 | Paul Durrant | #define XEN_PV_DEVICE(obj) \
|
39 | 8fbab3b6 | Paul Durrant | OBJECT_CHECK(XenPVDevice, (obj), TYPE_XEN_PV_DEVICE) |
40 | 8fbab3b6 | Paul Durrant | |
41 | 8fbab3b6 | Paul Durrant | typedef struct XenPVDevice { |
42 | 8fbab3b6 | Paul Durrant | /*< private >*/
|
43 | 8fbab3b6 | Paul Durrant | PCIDevice parent_obj; |
44 | 8fbab3b6 | Paul Durrant | /*< public >*/
|
45 | 8fbab3b6 | Paul Durrant | uint16_t vendor_id; |
46 | 8fbab3b6 | Paul Durrant | uint16_t device_id; |
47 | 8fbab3b6 | Paul Durrant | uint8_t revision; |
48 | 8fbab3b6 | Paul Durrant | uint32_t size; |
49 | 8fbab3b6 | Paul Durrant | MemoryRegion mmio; |
50 | 8fbab3b6 | Paul Durrant | } XenPVDevice; |
51 | 8fbab3b6 | Paul Durrant | |
52 | 8fbab3b6 | Paul Durrant | static uint64_t xen_pv_mmio_read(void *opaque, hwaddr addr, |
53 | 8fbab3b6 | Paul Durrant | unsigned size)
|
54 | 8fbab3b6 | Paul Durrant | { |
55 | 8fbab3b6 | Paul Durrant | trace_xen_pv_mmio_read(addr); |
56 | 8fbab3b6 | Paul Durrant | |
57 | 8fbab3b6 | Paul Durrant | return ~(uint64_t)0; |
58 | 8fbab3b6 | Paul Durrant | } |
59 | 8fbab3b6 | Paul Durrant | |
60 | 8fbab3b6 | Paul Durrant | static void xen_pv_mmio_write(void *opaque, hwaddr addr, |
61 | 8fbab3b6 | Paul Durrant | uint64_t val, unsigned size)
|
62 | 8fbab3b6 | Paul Durrant | { |
63 | 8fbab3b6 | Paul Durrant | trace_xen_pv_mmio_write(addr); |
64 | 8fbab3b6 | Paul Durrant | } |
65 | 8fbab3b6 | Paul Durrant | |
66 | 8fbab3b6 | Paul Durrant | static const MemoryRegionOps xen_pv_mmio_ops = { |
67 | 8fbab3b6 | Paul Durrant | .read = &xen_pv_mmio_read, |
68 | 8fbab3b6 | Paul Durrant | .write = &xen_pv_mmio_write, |
69 | 8fbab3b6 | Paul Durrant | .endianness = DEVICE_LITTLE_ENDIAN, |
70 | 8fbab3b6 | Paul Durrant | }; |
71 | 8fbab3b6 | Paul Durrant | |
72 | 8fbab3b6 | Paul Durrant | static int xen_pv_init(PCIDevice *pci_dev) |
73 | 8fbab3b6 | Paul Durrant | { |
74 | 8fbab3b6 | Paul Durrant | XenPVDevice *d = XEN_PV_DEVICE(pci_dev); |
75 | 8fbab3b6 | Paul Durrant | uint8_t *pci_conf; |
76 | 8fbab3b6 | Paul Durrant | |
77 | 8fbab3b6 | Paul Durrant | pci_conf = pci_dev->config; |
78 | 8fbab3b6 | Paul Durrant | |
79 | 8fbab3b6 | Paul Durrant | pci_set_word(pci_conf + PCI_VENDOR_ID, d->vendor_id); |
80 | 8fbab3b6 | Paul Durrant | pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, d->vendor_id); |
81 | 8fbab3b6 | Paul Durrant | pci_set_word(pci_conf + PCI_DEVICE_ID, d->device_id); |
82 | 8fbab3b6 | Paul Durrant | pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, d->device_id); |
83 | 8fbab3b6 | Paul Durrant | pci_set_byte(pci_conf + PCI_REVISION_ID, d->revision); |
84 | 8fbab3b6 | Paul Durrant | |
85 | 8fbab3b6 | Paul Durrant | pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_MEMORY); |
86 | 8fbab3b6 | Paul Durrant | |
87 | 8fbab3b6 | Paul Durrant | pci_config_set_prog_interface(pci_conf, 0);
|
88 | 8fbab3b6 | Paul Durrant | |
89 | 8fbab3b6 | Paul Durrant | pci_conf[PCI_INTERRUPT_PIN] = 1;
|
90 | 8fbab3b6 | Paul Durrant | |
91 | 8fbab3b6 | Paul Durrant | memory_region_init_io(&d->mmio, NULL, &xen_pv_mmio_ops, d,
|
92 | 8fbab3b6 | Paul Durrant | "mmio", d->size);
|
93 | 8fbab3b6 | Paul Durrant | |
94 | 8fbab3b6 | Paul Durrant | pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
|
95 | 8fbab3b6 | Paul Durrant | &d->mmio); |
96 | 8fbab3b6 | Paul Durrant | |
97 | 8fbab3b6 | Paul Durrant | return 0; |
98 | 8fbab3b6 | Paul Durrant | } |
99 | 8fbab3b6 | Paul Durrant | |
100 | 8fbab3b6 | Paul Durrant | static Property xen_pv_props[] = {
|
101 | 8fbab3b6 | Paul Durrant | DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN),
|
102 | 8fbab3b6 | Paul Durrant | DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, PCI_DEVICE_ID_XEN_PVDEVICE),
|
103 | 8fbab3b6 | Paul Durrant | DEFINE_PROP_UINT8("revision", XenPVDevice, revision, 0x01), |
104 | 8fbab3b6 | Paul Durrant | DEFINE_PROP_UINT32("size", XenPVDevice, size, 0x400000), |
105 | 8fbab3b6 | Paul Durrant | DEFINE_PROP_END_OF_LIST() |
106 | 8fbab3b6 | Paul Durrant | }; |
107 | 8fbab3b6 | Paul Durrant | |
108 | 8fbab3b6 | Paul Durrant | static void xen_pv_class_init(ObjectClass *klass, void *data) |
109 | 8fbab3b6 | Paul Durrant | { |
110 | 8fbab3b6 | Paul Durrant | DeviceClass *dc = DEVICE_CLASS(klass); |
111 | 8fbab3b6 | Paul Durrant | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
112 | 8fbab3b6 | Paul Durrant | |
113 | 8fbab3b6 | Paul Durrant | k->init = xen_pv_init; |
114 | 8fbab3b6 | Paul Durrant | k->class_id = PCI_CLASS_SYSTEM_OTHER; |
115 | 8fbab3b6 | Paul Durrant | dc->desc = "Xen PV Device";
|
116 | 8fbab3b6 | Paul Durrant | dc->props = xen_pv_props; |
117 | 8fbab3b6 | Paul Durrant | } |
118 | 8fbab3b6 | Paul Durrant | |
119 | 8fbab3b6 | Paul Durrant | static const TypeInfo xen_pv_type_info = { |
120 | 8fbab3b6 | Paul Durrant | .name = TYPE_XEN_PV_DEVICE, |
121 | 8fbab3b6 | Paul Durrant | .parent = TYPE_PCI_DEVICE, |
122 | 8fbab3b6 | Paul Durrant | .instance_size = sizeof(XenPVDevice),
|
123 | 8fbab3b6 | Paul Durrant | .class_init = xen_pv_class_init, |
124 | 8fbab3b6 | Paul Durrant | }; |
125 | 8fbab3b6 | Paul Durrant | |
126 | 8fbab3b6 | Paul Durrant | static void xen_pv_register_types(void) |
127 | 8fbab3b6 | Paul Durrant | { |
128 | 8fbab3b6 | Paul Durrant | type_register_static(&xen_pv_type_info); |
129 | 8fbab3b6 | Paul Durrant | } |
130 | 8fbab3b6 | Paul Durrant | |
131 | 8fbab3b6 | Paul Durrant | type_init(xen_pv_register_types) |