qemu/tests/libqos/x86_64_pc-machine.c
<<
>>
Prefs
   1/*
   2 * libqos driver framework
   3 *
   4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
   5 *
   6 * This library is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU Lesser General Public
   8 * License version 2 as published by the Free Software Foundation.
   9 *
  10 * This library is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13 * Lesser General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU Lesser General Public
  16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
  17 */
  18
  19#include "qemu/osdep.h"
  20#include "libqtest.h"
  21#include "libqos/qgraph.h"
  22#include "pci-pc.h"
  23#include "malloc-pc.h"
  24
  25typedef struct QX86PCMachine QX86PCMachine;
  26typedef struct i440FX_pcihost i440FX_pcihost;
  27typedef struct QSDHCI_PCI  QSDHCI_PCI;
  28
  29struct i440FX_pcihost {
  30    QOSGraphObject obj;
  31    QPCIBusPC pci;
  32};
  33
  34struct QX86PCMachine {
  35    QOSGraphObject obj;
  36    QGuestAllocator alloc;
  37    i440FX_pcihost bridge;
  38};
  39
  40/* i440FX_pcihost */
  41
  42static QOSGraphObject *i440FX_host_get_device(void *obj, const char *device)
  43{
  44    i440FX_pcihost *host = obj;
  45    if (!g_strcmp0(device, "pci-bus-pc")) {
  46        return &host->pci.obj;
  47    }
  48    fprintf(stderr, "%s not present in i440FX-pcihost\n", device);
  49    g_assert_not_reached();
  50}
  51
  52static void qos_create_i440FX_host(i440FX_pcihost *host,
  53                                   QTestState *qts,
  54                                   QGuestAllocator *alloc)
  55{
  56    host->obj.get_device = i440FX_host_get_device;
  57    qpci_init_pc(&host->pci, qts, alloc);
  58}
  59
  60/* x86_64/pc machine */
  61
  62static void pc_destructor(QOSGraphObject *obj)
  63{
  64    QX86PCMachine *machine = (QX86PCMachine *) obj;
  65    alloc_destroy(&machine->alloc);
  66}
  67
  68static void *pc_get_driver(void *object, const char *interface)
  69{
  70    QX86PCMachine *machine = object;
  71    if (!g_strcmp0(interface, "memory")) {
  72        return &machine->alloc;
  73    }
  74
  75    fprintf(stderr, "%s not present in x86_64/pc\n", interface);
  76    g_assert_not_reached();
  77}
  78
  79static QOSGraphObject *pc_get_device(void *obj, const char *device)
  80{
  81    QX86PCMachine *machine = obj;
  82    if (!g_strcmp0(device, "i440FX-pcihost")) {
  83        return &machine->bridge.obj;
  84    }
  85
  86    fprintf(stderr, "%s not present in x86_64/pc\n", device);
  87    g_assert_not_reached();
  88}
  89
  90static void *qos_create_machine_pc(QTestState *qts)
  91{
  92    QX86PCMachine *machine = g_new0(QX86PCMachine, 1);
  93    machine->obj.get_device = pc_get_device;
  94    machine->obj.get_driver = pc_get_driver;
  95    machine->obj.destructor = pc_destructor;
  96    pc_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS);
  97    qos_create_i440FX_host(&machine->bridge, qts, &machine->alloc);
  98
  99    return &machine->obj;
 100}
 101
 102static void pc_machine_register_nodes(void)
 103{
 104    qos_node_create_machine("i386/pc", qos_create_machine_pc);
 105    qos_node_contains("i386/pc", "i440FX-pcihost", NULL);
 106
 107    qos_node_create_machine("x86_64/pc", qos_create_machine_pc);
 108    qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL);
 109
 110    qos_node_create_driver("i440FX-pcihost", NULL);
 111    qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL);
 112}
 113
 114libqos_init(pc_machine_register_nodes);
 115