2011-06-16 18:05:17 +02:00
|
|
|
/*
|
|
|
|
* XEN platform pci device, formerly known as the event channel device
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2004 Intel Corp.
|
|
|
|
* Copyright (c) 2006 XenSource
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:03 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2022-05-13 20:09:57 +02:00
|
|
|
#include "hw/ide/pci.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2018-06-19 12:44:46 +02:00
|
|
|
#include "net/net.h"
|
2011-06-16 18:05:17 +02:00
|
|
|
#include "trace.h"
|
2020-05-08 12:02:22 +02:00
|
|
|
#include "sysemu/xen.h"
|
2014-10-07 13:59:18 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2015-10-21 17:46:50 +02:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2011-06-16 18:05:17 +02:00
|
|
|
|
2018-06-19 12:44:46 +02:00
|
|
|
#ifdef CONFIG_XEN
|
2023-01-02 01:39:13 +01:00
|
|
|
#include "hw/xen/xen_native.h"
|
2018-06-19 12:44:46 +02:00
|
|
|
#endif
|
|
|
|
|
2023-01-02 01:39:13 +01:00
|
|
|
/* The rule is that xen_native.h must come first */
|
|
|
|
#include "hw/xen/xen.h"
|
|
|
|
|
2011-06-16 18:05:17 +02:00
|
|
|
//#define DEBUG_PLATFORM
|
|
|
|
|
|
|
|
#ifdef DEBUG_PLATFORM
|
|
|
|
#define DPRINTF(fmt, ...) do { \
|
|
|
|
fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
|
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct PCIXenPlatformState {
|
2013-06-30 15:20:05 +02:00
|
|
|
/*< private >*/
|
|
|
|
PCIDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
MemoryRegion fixed_io;
|
|
|
|
MemoryRegion bar;
|
|
|
|
MemoryRegion mmio_bar;
|
2011-06-16 18:05:17 +02:00
|
|
|
uint8_t flags; /* used only for version_id == 2 */
|
|
|
|
uint16_t driver_product_version;
|
|
|
|
|
|
|
|
/* Log from guest drivers */
|
|
|
|
char log_buffer[4096];
|
|
|
|
int log_buffer_off;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2011-06-16 18:05:17 +02:00
|
|
|
|
2013-06-24 09:00:14 +02:00
|
|
|
#define TYPE_XEN_PLATFORM "xen-platform"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(PCIXenPlatformState, XEN_PLATFORM)
|
2013-06-24 09:00:14 +02:00
|
|
|
|
2011-06-16 18:05:17 +02:00
|
|
|
#define XEN_PLATFORM_IOPORT 0x10
|
|
|
|
|
|
|
|
/* Send bytes to syslog */
|
|
|
|
static void log_writeb(PCIXenPlatformState *s, char val)
|
|
|
|
{
|
|
|
|
if (val == '\n' || s->log_buffer_off == sizeof(s->log_buffer) - 1) {
|
|
|
|
/* Flush buffer */
|
|
|
|
s->log_buffer[s->log_buffer_off] = 0;
|
|
|
|
trace_xen_platform_log(s->log_buffer);
|
|
|
|
s->log_buffer_off = 0;
|
|
|
|
} else {
|
|
|
|
s->log_buffer[s->log_buffer_off++] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:28:12 +02:00
|
|
|
/*
|
|
|
|
* Unplug device flags.
|
|
|
|
*
|
|
|
|
* The logic got a little confused at some point in the past but this is
|
|
|
|
* what they do now.
|
|
|
|
*
|
|
|
|
* bit 0: Unplug all IDE and SCSI disks.
|
|
|
|
* bit 1: Unplug all NICs.
|
|
|
|
* bit 2: Unplug IDE disks except primary master. This is overridden if
|
|
|
|
* bit 0 is also present in the mask.
|
|
|
|
* bit 3: Unplug all NVMe disks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define _UNPLUG_IDE_SCSI_DISKS 0
|
|
|
|
#define UNPLUG_IDE_SCSI_DISKS (1u << _UNPLUG_IDE_SCSI_DISKS)
|
|
|
|
|
|
|
|
#define _UNPLUG_ALL_NICS 1
|
|
|
|
#define UNPLUG_ALL_NICS (1u << _UNPLUG_ALL_NICS)
|
|
|
|
|
|
|
|
#define _UNPLUG_AUX_IDE_DISKS 2
|
|
|
|
#define UNPLUG_AUX_IDE_DISKS (1u << _UNPLUG_AUX_IDE_DISKS)
|
|
|
|
|
|
|
|
#define _UNPLUG_NVME_DISKS 3
|
|
|
|
#define UNPLUG_NVME_DISKS (1u << _UNPLUG_NVME_DISKS)
|
2011-07-18 08:07:02 +02:00
|
|
|
|
2019-01-18 20:29:52 +01:00
|
|
|
static bool pci_device_is_passthrough(PCIDevice *d)
|
|
|
|
{
|
|
|
|
if (!strcmp(d->name, "xen-pci-passthrough")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xen_mode == XEN_EMULATE && !strcmp(d->name, "vfio-pci")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-21 17:35:28 +02:00
|
|
|
static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
|
2011-07-18 08:07:02 +02:00
|
|
|
{
|
2012-10-03 15:45:24 +02:00
|
|
|
/* We have to ignore passthrough devices */
|
2011-07-18 08:07:02 +02:00
|
|
|
if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
|
2012-10-03 15:45:24 +02:00
|
|
|
PCI_CLASS_NETWORK_ETHERNET
|
2019-01-18 20:29:52 +01:00
|
|
|
&& !pci_device_is_passthrough(d)) {
|
2013-09-11 14:54:09 +02:00
|
|
|
object_unparent(OBJECT(d));
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 14:50:28 +02:00
|
|
|
/* Remove the peer of the NIC device. Normally, this would be a tap device. */
|
|
|
|
static void del_nic_peer(NICState *nic, void *opaque)
|
|
|
|
{
|
|
|
|
NetClientState *nc;
|
|
|
|
|
|
|
|
nc = qemu_get_queue(nic);
|
|
|
|
if (nc->peer)
|
|
|
|
qemu_del_net_client(nc->peer);
|
|
|
|
}
|
|
|
|
|
2011-07-18 08:07:02 +02:00
|
|
|
static void pci_unplug_nics(PCIBus *bus)
|
|
|
|
{
|
2017-06-30 14:50:28 +02:00
|
|
|
qemu_foreach_nic(del_nic_peer, NULL);
|
2012-06-21 17:35:28 +02:00
|
|
|
pci_for_each_device(bus, 0, unplug_nic, NULL);
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:09:57 +02:00
|
|
|
/*
|
|
|
|
* The Xen HVM unplug protocol [1] specifies a mechanism to allow guests to
|
|
|
|
* request unplug of 'aux' disks (which is stated to mean all IDE disks,
|
|
|
|
* except the primary master).
|
|
|
|
*
|
|
|
|
* NOTE: The semantics of what happens if unplug of all disks and 'aux' disks
|
|
|
|
* is simultaneously requested is not clear. The implementation assumes
|
|
|
|
* that an 'all' request overrides an 'aux' request.
|
|
|
|
*
|
|
|
|
* [1] https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=docs/misc/hvm-emulated-unplug.pandoc
|
|
|
|
*/
|
xen-platform: do full PCI reset during unplug of IDE devices
The IDE unplug function needs to reset the entire PCI device, to make
sure all state is initialized to defaults. This is done by calling
pci_device_reset, which resets not only the chip specific registers, but
also all PCI state. This fixes "unplug" in a Xen HVM domU with the
modular legacy xenlinux PV drivers.
Commit ee358e919e38 ("hw/ide/piix: Convert reset handler to
DeviceReset") changed the way how the the disks are unplugged. Prior
this commit the PCI device remained unchanged. After this change,
piix_ide_reset is exercised after the "unplug" command, which was not
the case prior that commit. This function resets the command register.
As a result the ata_piix driver inside the domU will see a disabled PCI
device. The generic PCI code will reenable the PCI device. On the qemu
side, this runs pci_default_write_config/pci_update_mappings. Here a
changed address is returned by pci_bar_address, this is the address
which was truncated in piix_ide_reset. In case of a Xen HVM domU, the
address changes from 0xc120 to 0xc100. This truncation was a bug in
piix_ide_reset, which was fixed in commit 230dfd9257 ("hw/ide/piix:
properly initialize the BMIBA register"). If pci_xen_ide_unplug had used
pci_device_reset, the PCI registers would have been properly reset, and
commit ee358e919e38 would have not introduced a regression for this
specific domU environment.
While the unplug is supposed to hide the IDE disks, the changed BMIBA
address broke the UHCI device. In case the domU has an USB tablet
configured, to recive absolute pointer coordinates for the GUI, it will
cause a hang during device discovery of the partly discovered USB hid
device. Reading the USBSTS word size register will fail. The access ends
up in the QEMU piix-bmdma device, instead of the expected uhci device.
Here a byte size request is expected, and a value of ~0 is returned. As
a result the UCHI driver sees an error state in the register, and turns
off the UHCI controller.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Paul Durrant <paul@xen.org>
Message-Id: <20230720072950.20198-1-olaf@aepfle.de>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2023-07-20 09:29:50 +02:00
|
|
|
static void pci_xen_ide_unplug(PCIDevice *d, bool aux)
|
2022-05-13 20:09:57 +02:00
|
|
|
{
|
xen-platform: do full PCI reset during unplug of IDE devices
The IDE unplug function needs to reset the entire PCI device, to make
sure all state is initialized to defaults. This is done by calling
pci_device_reset, which resets not only the chip specific registers, but
also all PCI state. This fixes "unplug" in a Xen HVM domU with the
modular legacy xenlinux PV drivers.
Commit ee358e919e38 ("hw/ide/piix: Convert reset handler to
DeviceReset") changed the way how the the disks are unplugged. Prior
this commit the PCI device remained unchanged. After this change,
piix_ide_reset is exercised after the "unplug" command, which was not
the case prior that commit. This function resets the command register.
As a result the ata_piix driver inside the domU will see a disabled PCI
device. The generic PCI code will reenable the PCI device. On the qemu
side, this runs pci_default_write_config/pci_update_mappings. Here a
changed address is returned by pci_bar_address, this is the address
which was truncated in piix_ide_reset. In case of a Xen HVM domU, the
address changes from 0xc120 to 0xc100. This truncation was a bug in
piix_ide_reset, which was fixed in commit 230dfd9257 ("hw/ide/piix:
properly initialize the BMIBA register"). If pci_xen_ide_unplug had used
pci_device_reset, the PCI registers would have been properly reset, and
commit ee358e919e38 would have not introduced a regression for this
specific domU environment.
While the unplug is supposed to hide the IDE disks, the changed BMIBA
address broke the UHCI device. In case the domU has an USB tablet
configured, to recive absolute pointer coordinates for the GUI, it will
cause a hang during device discovery of the partly discovered USB hid
device. Reading the USBSTS word size register will fail. The access ends
up in the QEMU piix-bmdma device, instead of the expected uhci device.
Here a byte size request is expected, and a value of ~0 is returned. As
a result the UCHI driver sees an error state in the register, and turns
off the UHCI controller.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Paul Durrant <paul@xen.org>
Message-Id: <20230720072950.20198-1-olaf@aepfle.de>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2023-07-20 09:29:50 +02:00
|
|
|
DeviceState *dev = DEVICE(d);
|
2022-05-13 20:09:57 +02:00
|
|
|
PCIIDEState *pci_ide;
|
|
|
|
int i;
|
|
|
|
IDEDevice *idedev;
|
|
|
|
IDEBus *idebus;
|
|
|
|
BlockBackend *blk;
|
|
|
|
|
|
|
|
pci_ide = PCI_IDE(dev);
|
|
|
|
|
|
|
|
for (i = aux ? 1 : 0; i < 4; i++) {
|
|
|
|
idebus = &pci_ide->bus[i / 2];
|
|
|
|
blk = idebus->ifs[i % 2].blk;
|
|
|
|
|
|
|
|
if (blk && idebus->ifs[i % 2].drive_kind != IDE_CD) {
|
|
|
|
if (!(i % 2)) {
|
|
|
|
idedev = idebus->master;
|
|
|
|
} else {
|
|
|
|
idedev = idebus->slave;
|
|
|
|
}
|
|
|
|
|
|
|
|
blk_drain(blk);
|
|
|
|
blk_flush(blk);
|
|
|
|
|
|
|
|
blk_detach_dev(blk, DEVICE(idedev));
|
|
|
|
idebus->ifs[i % 2].blk = NULL;
|
|
|
|
idedev->conf.blk = NULL;
|
|
|
|
monitor_remove_blk(blk);
|
|
|
|
blk_unref(blk);
|
|
|
|
}
|
|
|
|
}
|
xen-platform: do full PCI reset during unplug of IDE devices
The IDE unplug function needs to reset the entire PCI device, to make
sure all state is initialized to defaults. This is done by calling
pci_device_reset, which resets not only the chip specific registers, but
also all PCI state. This fixes "unplug" in a Xen HVM domU with the
modular legacy xenlinux PV drivers.
Commit ee358e919e38 ("hw/ide/piix: Convert reset handler to
DeviceReset") changed the way how the the disks are unplugged. Prior
this commit the PCI device remained unchanged. After this change,
piix_ide_reset is exercised after the "unplug" command, which was not
the case prior that commit. This function resets the command register.
As a result the ata_piix driver inside the domU will see a disabled PCI
device. The generic PCI code will reenable the PCI device. On the qemu
side, this runs pci_default_write_config/pci_update_mappings. Here a
changed address is returned by pci_bar_address, this is the address
which was truncated in piix_ide_reset. In case of a Xen HVM domU, the
address changes from 0xc120 to 0xc100. This truncation was a bug in
piix_ide_reset, which was fixed in commit 230dfd9257 ("hw/ide/piix:
properly initialize the BMIBA register"). If pci_xen_ide_unplug had used
pci_device_reset, the PCI registers would have been properly reset, and
commit ee358e919e38 would have not introduced a regression for this
specific domU environment.
While the unplug is supposed to hide the IDE disks, the changed BMIBA
address broke the UHCI device. In case the domU has an USB tablet
configured, to recive absolute pointer coordinates for the GUI, it will
cause a hang during device discovery of the partly discovered USB hid
device. Reading the USBSTS word size register will fail. The access ends
up in the QEMU piix-bmdma device, instead of the expected uhci device.
Here a byte size request is expected, and a value of ~0 is returned. As
a result the UCHI driver sees an error state in the register, and turns
off the UHCI controller.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Paul Durrant <paul@xen.org>
Message-Id: <20230720072950.20198-1-olaf@aepfle.de>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2023-07-20 09:29:50 +02:00
|
|
|
pci_device_reset(d);
|
2022-05-13 20:09:57 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 15:05:47 +01:00
|
|
|
static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
|
2011-07-18 08:07:02 +02:00
|
|
|
{
|
2017-01-24 15:05:47 +01:00
|
|
|
uint32_t flags = *(uint32_t *)opaque;
|
|
|
|
bool aux = (flags & UNPLUG_AUX_IDE_DISKS) &&
|
2017-07-18 22:28:12 +02:00
|
|
|
!(flags & UNPLUG_IDE_SCSI_DISKS);
|
2017-01-24 15:05:47 +01:00
|
|
|
|
2012-10-03 15:45:24 +02:00
|
|
|
/* We have to ignore passthrough devices */
|
2019-01-18 20:29:52 +01:00
|
|
|
if (pci_device_is_passthrough(d))
|
2017-01-24 15:05:45 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) {
|
|
|
|
case PCI_CLASS_STORAGE_IDE:
|
xen-platform: do full PCI reset during unplug of IDE devices
The IDE unplug function needs to reset the entire PCI device, to make
sure all state is initialized to defaults. This is done by calling
pci_device_reset, which resets not only the chip specific registers, but
also all PCI state. This fixes "unplug" in a Xen HVM domU with the
modular legacy xenlinux PV drivers.
Commit ee358e919e38 ("hw/ide/piix: Convert reset handler to
DeviceReset") changed the way how the the disks are unplugged. Prior
this commit the PCI device remained unchanged. After this change,
piix_ide_reset is exercised after the "unplug" command, which was not
the case prior that commit. This function resets the command register.
As a result the ata_piix driver inside the domU will see a disabled PCI
device. The generic PCI code will reenable the PCI device. On the qemu
side, this runs pci_default_write_config/pci_update_mappings. Here a
changed address is returned by pci_bar_address, this is the address
which was truncated in piix_ide_reset. In case of a Xen HVM domU, the
address changes from 0xc120 to 0xc100. This truncation was a bug in
piix_ide_reset, which was fixed in commit 230dfd9257 ("hw/ide/piix:
properly initialize the BMIBA register"). If pci_xen_ide_unplug had used
pci_device_reset, the PCI registers would have been properly reset, and
commit ee358e919e38 would have not introduced a regression for this
specific domU environment.
While the unplug is supposed to hide the IDE disks, the changed BMIBA
address broke the UHCI device. In case the domU has an USB tablet
configured, to recive absolute pointer coordinates for the GUI, it will
cause a hang during device discovery of the partly discovered USB hid
device. Reading the USBSTS word size register will fail. The access ends
up in the QEMU piix-bmdma device, instead of the expected uhci device.
Here a byte size request is expected, and a value of ~0 is returned. As
a result the UCHI driver sees an error state in the register, and turns
off the UHCI controller.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Paul Durrant <paul@xen.org>
Message-Id: <20230720072950.20198-1-olaf@aepfle.de>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2023-07-20 09:29:50 +02:00
|
|
|
pci_xen_ide_unplug(d, aux);
|
2017-01-24 15:05:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCI_CLASS_STORAGE_SCSI:
|
2017-01-24 15:05:47 +01:00
|
|
|
if (!aux) {
|
|
|
|
object_unparent(OBJECT(d));
|
|
|
|
}
|
2017-01-24 15:05:45 +01:00
|
|
|
break;
|
|
|
|
|
2017-07-18 22:28:12 +02:00
|
|
|
case PCI_CLASS_STORAGE_EXPRESS:
|
|
|
|
if (flags & UNPLUG_NVME_DISKS) {
|
|
|
|
object_unparent(OBJECT(d));
|
|
|
|
}
|
|
|
|
|
2017-01-24 15:05:45 +01:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 15:05:47 +01:00
|
|
|
static void pci_unplug_disks(PCIBus *bus, uint32_t flags)
|
2011-07-18 08:07:02 +02:00
|
|
|
{
|
2017-01-24 15:05:47 +01:00
|
|
|
pci_for_each_device(bus, 0, unplug_disks, &flags);
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
|
|
|
|
2011-11-04 16:35:11 +01:00
|
|
|
switch (addr) {
|
2013-06-30 15:20:05 +02:00
|
|
|
case 0: {
|
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2017-07-18 22:28:12 +02:00
|
|
|
/* Unplug devices. See comment above flag definitions */
|
|
|
|
if (val & (UNPLUG_IDE_SCSI_DISKS | UNPLUG_AUX_IDE_DISKS |
|
|
|
|
UNPLUG_NVME_DISKS)) {
|
2011-07-18 08:07:02 +02:00
|
|
|
DPRINTF("unplug disks\n");
|
2017-11-29 09:46:27 +01:00
|
|
|
pci_unplug_disks(pci_get_bus(pci_dev), val);
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
|
|
|
if (val & UNPLUG_ALL_NICS) {
|
|
|
|
DPRINTF("unplug nics\n");
|
2017-11-29 09:46:27 +01:00
|
|
|
pci_unplug_nics(pci_get_bus(pci_dev));
|
2011-07-18 08:07:02 +02:00
|
|
|
}
|
2011-06-16 18:05:17 +02:00
|
|
|
break;
|
2013-06-30 15:20:05 +02:00
|
|
|
}
|
2011-06-16 18:05:17 +02:00
|
|
|
case 2:
|
|
|
|
switch (val) {
|
|
|
|
case 1:
|
|
|
|
DPRINTF("Citrix Windows PV drivers loaded in guest\n");
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
DPRINTF("Guest claimed to be running PV product 0?\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINTF("Unknown PV product %d loaded in guest\n", val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->driver_product_version = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
|
|
|
|
uint32_t val)
|
|
|
|
{
|
2011-11-04 16:35:11 +01:00
|
|
|
switch (addr) {
|
2011-06-16 18:05:17 +02:00
|
|
|
case 0:
|
|
|
|
/* PV driver version */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
|
|
|
|
2011-11-04 16:35:11 +01:00
|
|
|
switch (addr) {
|
2018-06-19 12:44:46 +02:00
|
|
|
case 0: /* Platform flags */
|
|
|
|
if (xen_mode == XEN_EMULATE) {
|
|
|
|
/* XX: Use i440gx/q35 PAM setup to do this? */
|
2011-06-16 18:05:17 +02:00
|
|
|
s->flags = val & PFFLAG_ROM_LOCK;
|
2018-06-19 12:44:46 +02:00
|
|
|
#ifdef CONFIG_XEN
|
|
|
|
} else {
|
|
|
|
hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
|
|
|
|
HVMMEM_ram_ro : HVMMEM_ram_rw;
|
|
|
|
|
|
|
|
if (xen_set_mem_type(xen_domid, mem_type, 0xc0, 0x40)) {
|
|
|
|
DPRINTF("unable to change ro/rw state of ROM memory area!\n");
|
|
|
|
} else {
|
|
|
|
s->flags = val & PFFLAG_ROM_LOCK;
|
|
|
|
DPRINTF("changed ro/rw state of ROM memory area. now is %s state.\n",
|
|
|
|
(mem_type == HVMMEM_ram_ro ? "ro" : "rw"));
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-06-19 12:44:46 +02:00
|
|
|
|
2011-06-16 18:05:17 +02:00
|
|
|
case 2:
|
|
|
|
log_writeb(s, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
|
|
|
|
{
|
2011-11-04 16:35:11 +01:00
|
|
|
switch (addr) {
|
2011-06-16 18:05:17 +02:00
|
|
|
case 0:
|
2021-02-02 16:56:44 +01:00
|
|
|
/* Magic value so that you can identify the interface. */
|
|
|
|
return 0x49d2;
|
2011-06-16 18:05:17 +02:00
|
|
|
default:
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
|
|
|
|
2011-11-04 16:35:11 +01:00
|
|
|
switch (addr) {
|
2011-06-16 18:05:17 +02:00
|
|
|
case 0:
|
|
|
|
/* Platform flags */
|
|
|
|
return s->flags;
|
|
|
|
case 2:
|
|
|
|
/* Version number */
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_fixed_ioport_reset(void *opaque)
|
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
|
|
|
|
2011-11-04 16:35:11 +01:00
|
|
|
platform_fixed_ioport_writeb(s, 0, 0);
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
|
2012-10-08 13:47:30 +02:00
|
|
|
static uint64_t platform_fixed_ioport_read(void *opaque,
|
|
|
|
hwaddr addr,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return platform_fixed_ioport_readb(opaque, addr);
|
|
|
|
case 2:
|
|
|
|
return platform_fixed_ioport_readw(opaque, addr);
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_fixed_ioport_write(void *opaque, hwaddr addr,
|
|
|
|
|
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
platform_fixed_ioport_writeb(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
platform_fixed_ioport_writew(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
platform_fixed_ioport_writel(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
|
|
|
|
static const MemoryRegionOps platform_fixed_io_ops = {
|
2012-10-08 13:47:30 +02:00
|
|
|
.read = platform_fixed_ioport_read,
|
|
|
|
.write = platform_fixed_ioport_write,
|
2013-06-22 08:07:03 +02:00
|
|
|
.valid = {
|
|
|
|
.unaligned = true,
|
|
|
|
},
|
2012-10-08 13:47:30 +02:00
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
2013-06-22 08:07:03 +02:00
|
|
|
.unaligned = true,
|
2012-10-08 13:47:30 +02:00
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 15:09:25 +02:00
|
|
|
};
|
|
|
|
|
2011-06-16 18:05:17 +02:00
|
|
|
static void platform_fixed_ioport_init(PCIXenPlatformState* s)
|
|
|
|
{
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->fixed_io, OBJECT(s), &platform_fixed_io_ops, s,
|
2011-08-08 15:09:25 +02:00
|
|
|
"xen-fixed", 16);
|
|
|
|
memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT,
|
|
|
|
&s->fixed_io);
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Xen Platform PCI Device */
|
|
|
|
|
2013-01-04 22:29:40 +01:00
|
|
|
static uint64_t xen_platform_ioport_readb(void *opaque, hwaddr addr,
|
|
|
|
unsigned int size)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
|
|
|
if (addr == 0) {
|
2011-11-04 16:35:11 +01:00
|
|
|
return platform_fixed_ioport_readb(opaque, 0);
|
2011-06-16 18:05:17 +02:00
|
|
|
} else {
|
|
|
|
return ~0u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:29:40 +01:00
|
|
|
static void xen_platform_ioport_writeb(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned int size)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
2016-10-21 14:37:07 +02:00
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0: /* Platform flags */
|
2013-01-04 22:29:40 +01:00
|
|
|
platform_fixed_ioport_writeb(opaque, 0, (uint32_t)val);
|
2011-06-16 18:05:17 +02:00
|
|
|
break;
|
2016-10-21 14:37:07 +02:00
|
|
|
case 4:
|
|
|
|
if (val == 1) {
|
|
|
|
/*
|
|
|
|
* SUSE unplug for Xenlinux
|
|
|
|
* xen-kmp used this since xen-3.0.4, instead the official protocol
|
|
|
|
* from xen-3.3+ It did an unconditional "outl(1, (ioaddr + 4));"
|
|
|
|
* Pre VMDP 1.7 used 4 and 8 depending on how VMDP was configured.
|
|
|
|
* If VMDP was to control both disk and LAN it would use 4.
|
|
|
|
* If it controlled just disk or just LAN, it would use 8 below.
|
|
|
|
*/
|
2017-11-29 09:46:27 +01:00
|
|
|
pci_unplug_disks(pci_get_bus(pci_dev), UNPLUG_IDE_SCSI_DISKS);
|
|
|
|
pci_unplug_nics(pci_get_bus(pci_dev));
|
2016-10-21 14:37:07 +02:00
|
|
|
}
|
|
|
|
break;
|
2011-06-16 18:05:17 +02:00
|
|
|
case 8:
|
2016-10-21 14:37:07 +02:00
|
|
|
switch (val) {
|
|
|
|
case 1:
|
2017-11-29 09:46:27 +01:00
|
|
|
pci_unplug_disks(pci_get_bus(pci_dev), UNPLUG_IDE_SCSI_DISKS);
|
2016-10-21 14:37:07 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-11-29 09:46:27 +01:00
|
|
|
pci_unplug_nics(pci_get_bus(pci_dev));
|
2016-10-21 14:37:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_writeb(s, (uint32_t)val);
|
|
|
|
break;
|
|
|
|
}
|
2011-06-16 18:05:17 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
static const MemoryRegionOps xen_pci_io_ops = {
|
2013-01-04 22:29:40 +01:00
|
|
|
.read = xen_platform_ioport_readb,
|
|
|
|
.write = xen_platform_ioport_writeb,
|
|
|
|
.impl.min_access_size = 1,
|
|
|
|
.impl.max_access_size = 1,
|
2011-08-08 15:09:25 +02:00
|
|
|
};
|
2011-06-16 18:05:17 +02:00
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
static void platform_ioport_bar_setup(PCIXenPlatformState *d)
|
|
|
|
{
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&d->bar, OBJECT(d), &xen_pci_io_ops, d,
|
|
|
|
"xen-pci", 0x100);
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t platform_mmio_read(void *opaque, hwaddr addr,
|
2011-08-08 15:09:25 +02:00
|
|
|
unsigned size)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
|
|
|
DPRINTF("Warning: attempted read from physical address "
|
2023-01-10 22:29:47 +01:00
|
|
|
"0x" HWADDR_FMT_plx " in xen platform mmio space\n", addr);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void platform_mmio_write(void *opaque, hwaddr addr,
|
2011-08-08 15:09:25 +02:00
|
|
|
uint64_t val, unsigned size)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
2011-08-08 15:09:25 +02:00
|
|
|
DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical "
|
2023-01-10 22:29:47 +01:00
|
|
|
"address 0x" HWADDR_FMT_plx " in xen platform mmio space\n",
|
2011-06-16 18:05:17 +02:00
|
|
|
val, addr);
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
static const MemoryRegionOps platform_mmio_handler = {
|
2011-06-16 18:05:17 +02:00
|
|
|
.read = &platform_mmio_read,
|
|
|
|
.write = &platform_mmio_write,
|
2011-08-08 15:09:25 +02:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-06-16 18:05:17 +02:00
|
|
|
};
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
static void platform_mmio_setup(PCIXenPlatformState *d)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&d->mmio_bar, OBJECT(d), &platform_mmio_handler, d,
|
2011-08-08 15:09:25 +02:00
|
|
|
"xen-mmio", 0x1000000);
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_platform_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
PCIXenPlatformState *s = opaque;
|
|
|
|
|
2011-11-04 16:35:11 +01:00
|
|
|
platform_fixed_ioport_writeb(s, 0, s->flags);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_xen_platform = {
|
|
|
|
.name = "platform",
|
|
|
|
.version_id = 4,
|
|
|
|
.minimum_version_id = 4,
|
|
|
|
.post_load = xen_platform_post_load,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2013-06-30 15:20:05 +02:00
|
|
|
VMSTATE_PCI_DEVICE(parent_obj, PCIXenPlatformState),
|
2011-06-16 18:05:17 +02:00
|
|
|
VMSTATE_UINT8(flags, PCIXenPlatformState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-21 17:46:49 +02:00
|
|
|
static void xen_platform_realize(PCIDevice *dev, Error **errp)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
2013-06-24 09:00:14 +02:00
|
|
|
PCIXenPlatformState *d = XEN_PLATFORM(dev);
|
2011-06-16 18:05:17 +02:00
|
|
|
uint8_t *pci_conf;
|
|
|
|
|
2015-09-28 22:01:24 +02:00
|
|
|
/* Device will crash on reset if xen is not initialized */
|
2018-06-19 12:44:46 +02:00
|
|
|
if (xen_mode == XEN_DISABLED) {
|
|
|
|
error_setg(errp, "xen-platform device requires a Xen guest");
|
2015-10-21 17:46:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-09-28 22:01:24 +02:00
|
|
|
|
2013-06-30 15:20:05 +02:00
|
|
|
pci_conf = dev->config;
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
|
|
|
|
|
|
|
|
pci_config_set_prog_interface(pci_conf, 0);
|
|
|
|
|
|
|
|
pci_conf[PCI_INTERRUPT_PIN] = 1;
|
|
|
|
|
2011-08-08 15:09:25 +02:00
|
|
|
platform_ioport_bar_setup(d);
|
2013-06-30 15:20:05 +02:00
|
|
|
pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
/* reserve 16MB mmio address for share memory*/
|
2011-08-08 15:09:25 +02:00
|
|
|
platform_mmio_setup(d);
|
2013-06-30 15:20:05 +02:00
|
|
|
pci_register_bar(dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
|
2011-08-08 15:09:31 +02:00
|
|
|
&d->mmio_bar);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
platform_fixed_ioport_init(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_reset(DeviceState *dev)
|
|
|
|
{
|
2013-06-24 09:00:14 +02:00
|
|
|
PCIXenPlatformState *s = XEN_PLATFORM(dev);
|
2011-06-16 18:05:17 +02:00
|
|
|
|
|
|
|
platform_fixed_ioport_reset(s);
|
|
|
|
}
|
|
|
|
|
2011-12-04 19:22:06 +01:00
|
|
|
static void xen_platform_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:22:06 +01:00
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
2015-10-21 17:46:49 +02:00
|
|
|
k->realize = xen_platform_realize;
|
2011-12-04 19:22:06 +01:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_XEN;
|
|
|
|
k->device_id = PCI_DEVICE_ID_XEN_PLATFORM;
|
|
|
|
k->class_id = PCI_CLASS_OTHERS << 8 | 0x80;
|
|
|
|
k->subsystem_vendor_id = PCI_VENDOR_ID_XEN;
|
|
|
|
k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM;
|
|
|
|
k->revision = 1;
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "XEN platform pci device";
|
|
|
|
dc->reset = platform_reset;
|
|
|
|
dc->vmsd = &vmstate_xen_platform;
|
2011-12-04 19:22:06 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo xen_platform_info = {
|
2013-06-24 09:00:14 +02:00
|
|
|
.name = TYPE_XEN_PLATFORM,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(PCIXenPlatformState),
|
|
|
|
.class_init = xen_platform_class_init,
|
2017-09-27 21:56:34 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2011-06-16 18:05:17 +02:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void xen_platform_register_types(void)
|
2011-06-16 18:05:17 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&xen_platform_info);
|
2011-06-16 18:05:17 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(xen_platform_register_types)
|