debuggers.hg

view tools/ioemu/hw/xen_platform.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 /*
2 * XEN platform fake pci device, formerly known as the event channel device
3 *
4 * Copyright (c) 2003-2004 Intel Corp.
5 * Copyright (c) 2006 XenSource
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 #include "vl.h"
27 #include <xenguest.h>
29 extern FILE *logfile;
31 static void platform_ioport_map(PCIDevice *pci_dev, int region_num,
32 uint32_t addr, uint32_t size, int type)
33 {
34 /* nothing yet */
35 }
37 static uint32_t platform_mmio_read(void *opaque, target_phys_addr_t addr)
38 {
39 static int warnings = 0;
40 if (warnings < 5) {
41 fprintf(logfile, "Warning: attempted read from physical address "
42 "0x%"PRIx64" in xen platform mmio space\n", (uint64_t)addr);
43 warnings++;
44 }
45 return 0;
46 }
48 static void platform_mmio_write(void *opaque, target_phys_addr_t addr,
49 uint32_t val)
50 {
51 static int warnings = 0;
52 if (warnings < 5) {
53 fprintf(logfile, "Warning: attempted write of 0x%x to physical "
54 "address 0x%"PRIx64" in xen platform mmio space\n",
55 val, (uint64_t)addr);
56 warnings++;
57 }
58 return;
59 }
61 static CPUReadMemoryFunc *platform_mmio_read_funcs[3] = {
62 platform_mmio_read,
63 platform_mmio_read,
64 platform_mmio_read,
65 };
67 static CPUWriteMemoryFunc *platform_mmio_write_funcs[3] = {
68 platform_mmio_write,
69 platform_mmio_write,
70 platform_mmio_write,
71 };
73 static void platform_mmio_map(PCIDevice *d, int region_num,
74 uint32_t addr, uint32_t size, int type)
75 {
76 int mmio_io_addr;
78 mmio_io_addr = cpu_register_io_memory(0, platform_mmio_read_funcs,
79 platform_mmio_write_funcs, NULL);
81 cpu_register_physical_memory(addr, 0x1000000, mmio_io_addr);
82 }
84 struct pci_config_header {
85 uint16_t vendor_id;
86 uint16_t device_id;
87 uint16_t command;
88 uint16_t status;
89 uint8_t revision;
90 uint8_t api;
91 uint8_t subclass;
92 uint8_t class;
93 uint8_t cache_line_size; /* Units of 32 bit words */
94 uint8_t latency_timer; /* In units of bus cycles */
95 uint8_t header_type; /* Should be 0 */
96 uint8_t bist; /* Built in self test */
97 uint32_t base_address_regs[6];
98 uint32_t reserved1;
99 uint16_t subsystem_vendor_id;
100 uint16_t subsystem_id;
101 uint32_t rom_addr;
102 uint32_t reserved3;
103 uint32_t reserved4;
104 uint8_t interrupt_line;
105 uint8_t interrupt_pin;
106 uint8_t min_gnt;
107 uint8_t max_lat;
108 };
110 void xen_pci_save(QEMUFile *f, void *opaque)
111 {
112 PCIDevice *d = opaque;
114 pci_device_save(d, f);
115 }
117 int xen_pci_load(QEMUFile *f, void *opaque, int version_id)
118 {
119 PCIDevice *d = opaque;
121 if (version_id != 1)
122 return -EINVAL;
124 return pci_device_load(d, f);
125 }
127 void pci_xen_platform_init(PCIBus *bus)
128 {
129 PCIDevice *d;
130 struct pci_config_header *pch;
132 printf("Register xen platform.\n");
133 d = pci_register_device(bus, "xen-platform", sizeof(PCIDevice), -1, NULL,
134 NULL);
135 pch = (struct pci_config_header *)d->config;
136 pch->vendor_id = 0x5853;
137 pch->device_id = 0x0001;
138 pch->command = 3; /* IO and memory access */
139 pch->revision = 1;
140 pch->api = 0;
141 pch->subclass = 0x80; /* Other */
142 pch->class = 0xff; /* Unclassified device class */
143 pch->header_type = 0;
144 pch->interrupt_pin = 1;
146 /* Microsoft WHQL requires non-zero subsystem IDs. */
147 /* http://www.pcisig.com/reflector/msg02205.html. */
148 pch->subsystem_vendor_id = pch->vendor_id; /* Duplicate vendor id. */
149 pch->subsystem_id = 0x0001; /* Hardcode sub-id as 1. */
151 pci_register_io_region(d, 0, 0x100, PCI_ADDRESS_SPACE_IO,
152 platform_ioport_map);
154 /* reserve 16MB mmio address for share memory*/
155 pci_register_io_region(d, 1, 0x1000000, PCI_ADDRESS_SPACE_MEM_PREFETCH,
156 platform_mmio_map);
158 register_savevm("platform", 0, 1, xen_pci_save, xen_pci_load, d);
159 printf("Done register platform.\n");
160 }