Statistics
| Branch: | Revision:

root / hw / xen / xen_pvdevice.c @ 8fbab3b6

History | View | Annotate | Download (4.1 kB)

1
/* Copyright (c) Citrix Systems Inc.
2
 * All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms,
5
 * with or without modification, are permitted provided
6
 * that the following conditions are met:
7
 *
8
 * *   Redistributions of source code must retain the above
9
 *     copyright notice, this list of conditions and the
10
 *     following disclaimer.
11
 * *   Redistributions in binary form must reproduce the above
12
 *     copyright notice, this list of conditions and the
13
 *     following disclaimer in the documentation and/or other
14
 *     materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
17
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
 * SUCH DAMAGE.
30
 */
31

    
32
#include "hw/hw.h"
33
#include "hw/pci/pci.h"
34
#include "trace.h"
35

    
36
#define TYPE_XEN_PV_DEVICE  "xen-pvdevice"
37

    
38
#define XEN_PV_DEVICE(obj) \
39
     OBJECT_CHECK(XenPVDevice, (obj), TYPE_XEN_PV_DEVICE)
40

    
41
typedef struct XenPVDevice {
42
    /*< private >*/
43
    PCIDevice       parent_obj;
44
    /*< public >*/
45
    uint16_t        vendor_id;
46
    uint16_t        device_id;
47
    uint8_t         revision;
48
    uint32_t        size;
49
    MemoryRegion    mmio;
50
} XenPVDevice;
51

    
52
static uint64_t xen_pv_mmio_read(void *opaque, hwaddr addr,
53
                                 unsigned size)
54
{
55
    trace_xen_pv_mmio_read(addr);
56

    
57
    return ~(uint64_t)0;
58
}
59

    
60
static void xen_pv_mmio_write(void *opaque, hwaddr addr,
61
                              uint64_t val, unsigned size)
62
{
63
    trace_xen_pv_mmio_write(addr);
64
}
65

    
66
static const MemoryRegionOps xen_pv_mmio_ops = {
67
    .read = &xen_pv_mmio_read,
68
    .write = &xen_pv_mmio_write,
69
    .endianness = DEVICE_LITTLE_ENDIAN,
70
};
71

    
72
static int xen_pv_init(PCIDevice *pci_dev)
73
{
74
    XenPVDevice *d = XEN_PV_DEVICE(pci_dev);
75
    uint8_t *pci_conf;
76

    
77
    pci_conf = pci_dev->config;
78

    
79
    pci_set_word(pci_conf + PCI_VENDOR_ID, d->vendor_id);
80
    pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, d->vendor_id);
81
    pci_set_word(pci_conf + PCI_DEVICE_ID, d->device_id);
82
    pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, d->device_id);
83
    pci_set_byte(pci_conf + PCI_REVISION_ID, d->revision);
84

    
85
    pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_MEMORY);
86

    
87
    pci_config_set_prog_interface(pci_conf, 0);
88

    
89
    pci_conf[PCI_INTERRUPT_PIN] = 1;
90

    
91
    memory_region_init_io(&d->mmio, NULL, &xen_pv_mmio_ops, d,
92
                          "mmio", d->size);
93

    
94
    pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
95
                     &d->mmio);
96

    
97
    return 0;
98
}
99

    
100
static Property xen_pv_props[] = {
101
    DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN),
102
    DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, PCI_DEVICE_ID_XEN_PVDEVICE),
103
    DEFINE_PROP_UINT8("revision", XenPVDevice, revision, 0x01),
104
    DEFINE_PROP_UINT32("size", XenPVDevice, size, 0x400000),
105
    DEFINE_PROP_END_OF_LIST()
106
};
107

    
108
static void xen_pv_class_init(ObjectClass *klass, void *data)
109
{
110
    DeviceClass *dc = DEVICE_CLASS(klass);
111
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
112

    
113
    k->init = xen_pv_init;
114
    k->class_id = PCI_CLASS_SYSTEM_OTHER;
115
    dc->desc = "Xen PV Device";
116
    dc->props = xen_pv_props;
117
}
118

    
119
static const TypeInfo xen_pv_type_info = {
120
    .name          = TYPE_XEN_PV_DEVICE,
121
    .parent        = TYPE_PCI_DEVICE,
122
    .instance_size = sizeof(XenPVDevice),
123
    .class_init    = xen_pv_class_init,
124
};
125

    
126
static void xen_pv_register_types(void)
127
{
128
    type_register_static(&xen_pv_type_info);
129
}
130

    
131
type_init(xen_pv_register_types)