11cf4323eSThomas Huth /* 21cf4323eSThomas Huth * libqos driver framework 31cf4323eSThomas Huth * 41cf4323eSThomas Huth * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com> 51cf4323eSThomas Huth * 61cf4323eSThomas Huth * This library is free software; you can redistribute it and/or 71cf4323eSThomas Huth * modify it under the terms of the GNU Lesser General Public 8*dc0ad02dSThomas Huth * License version 2.1 as published by the Free Software Foundation. 91cf4323eSThomas Huth * 101cf4323eSThomas Huth * This library is distributed in the hope that it will be useful, 111cf4323eSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of 121cf4323eSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 131cf4323eSThomas Huth * Lesser General Public License for more details. 141cf4323eSThomas Huth * 151cf4323eSThomas Huth * You should have received a copy of the GNU Lesser General Public 161cf4323eSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/> 171cf4323eSThomas Huth */ 181cf4323eSThomas Huth 191cf4323eSThomas Huth #include "qemu/osdep.h" 201cf4323eSThomas Huth #include "libqtest.h" 211cf4323eSThomas Huth #include "libqos/qgraph.h" 221cf4323eSThomas Huth #include "pci-pc.h" 231cf4323eSThomas Huth #include "qemu/module.h" 241cf4323eSThomas Huth #include "malloc-pc.h" 251cf4323eSThomas Huth 261cf4323eSThomas Huth typedef struct QX86PCMachine QX86PCMachine; 271cf4323eSThomas Huth typedef struct i440FX_pcihost i440FX_pcihost; 281cf4323eSThomas Huth typedef struct QSDHCI_PCI QSDHCI_PCI; 291cf4323eSThomas Huth 301cf4323eSThomas Huth struct i440FX_pcihost { 311cf4323eSThomas Huth QOSGraphObject obj; 321cf4323eSThomas Huth QPCIBusPC pci; 331cf4323eSThomas Huth }; 341cf4323eSThomas Huth 351cf4323eSThomas Huth struct QX86PCMachine { 361cf4323eSThomas Huth QOSGraphObject obj; 371cf4323eSThomas Huth QGuestAllocator alloc; 381cf4323eSThomas Huth i440FX_pcihost bridge; 391cf4323eSThomas Huth }; 401cf4323eSThomas Huth 411cf4323eSThomas Huth /* i440FX_pcihost */ 421cf4323eSThomas Huth 431cf4323eSThomas Huth static QOSGraphObject *i440FX_host_get_device(void *obj, const char *device) 441cf4323eSThomas Huth { 451cf4323eSThomas Huth i440FX_pcihost *host = obj; 461cf4323eSThomas Huth if (!g_strcmp0(device, "pci-bus-pc")) { 471cf4323eSThomas Huth return &host->pci.obj; 481cf4323eSThomas Huth } 491cf4323eSThomas Huth fprintf(stderr, "%s not present in i440FX-pcihost\n", device); 501cf4323eSThomas Huth g_assert_not_reached(); 511cf4323eSThomas Huth } 521cf4323eSThomas Huth 531cf4323eSThomas Huth static void qos_create_i440FX_host(i440FX_pcihost *host, 541cf4323eSThomas Huth QTestState *qts, 551cf4323eSThomas Huth QGuestAllocator *alloc) 561cf4323eSThomas Huth { 571cf4323eSThomas Huth host->obj.get_device = i440FX_host_get_device; 581cf4323eSThomas Huth qpci_init_pc(&host->pci, qts, alloc); 591cf4323eSThomas Huth } 601cf4323eSThomas Huth 611cf4323eSThomas Huth /* x86_64/pc machine */ 621cf4323eSThomas Huth 631cf4323eSThomas Huth static void pc_destructor(QOSGraphObject *obj) 641cf4323eSThomas Huth { 651cf4323eSThomas Huth QX86PCMachine *machine = (QX86PCMachine *) obj; 661cf4323eSThomas Huth alloc_destroy(&machine->alloc); 671cf4323eSThomas Huth } 681cf4323eSThomas Huth 691cf4323eSThomas Huth static void *pc_get_driver(void *object, const char *interface) 701cf4323eSThomas Huth { 711cf4323eSThomas Huth QX86PCMachine *machine = object; 721cf4323eSThomas Huth if (!g_strcmp0(interface, "memory")) { 731cf4323eSThomas Huth return &machine->alloc; 741cf4323eSThomas Huth } 751cf4323eSThomas Huth 761cf4323eSThomas Huth fprintf(stderr, "%s not present in x86_64/pc\n", interface); 771cf4323eSThomas Huth g_assert_not_reached(); 781cf4323eSThomas Huth } 791cf4323eSThomas Huth 801cf4323eSThomas Huth static QOSGraphObject *pc_get_device(void *obj, const char *device) 811cf4323eSThomas Huth { 821cf4323eSThomas Huth QX86PCMachine *machine = obj; 831cf4323eSThomas Huth if (!g_strcmp0(device, "i440FX-pcihost")) { 841cf4323eSThomas Huth return &machine->bridge.obj; 851cf4323eSThomas Huth } 861cf4323eSThomas Huth 871cf4323eSThomas Huth fprintf(stderr, "%s not present in x86_64/pc\n", device); 881cf4323eSThomas Huth g_assert_not_reached(); 891cf4323eSThomas Huth } 901cf4323eSThomas Huth 911cf4323eSThomas Huth static void *qos_create_machine_pc(QTestState *qts) 921cf4323eSThomas Huth { 931cf4323eSThomas Huth QX86PCMachine *machine = g_new0(QX86PCMachine, 1); 941cf4323eSThomas Huth machine->obj.get_device = pc_get_device; 951cf4323eSThomas Huth machine->obj.get_driver = pc_get_driver; 961cf4323eSThomas Huth machine->obj.destructor = pc_destructor; 971cf4323eSThomas Huth pc_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS); 981cf4323eSThomas Huth qos_create_i440FX_host(&machine->bridge, qts, &machine->alloc); 991cf4323eSThomas Huth 1001cf4323eSThomas Huth return &machine->obj; 1011cf4323eSThomas Huth } 1021cf4323eSThomas Huth 1031cf4323eSThomas Huth static void pc_machine_register_nodes(void) 1041cf4323eSThomas Huth { 1051cf4323eSThomas Huth qos_node_create_machine("i386/pc", qos_create_machine_pc); 1061cf4323eSThomas Huth qos_node_contains("i386/pc", "i440FX-pcihost", NULL); 1071cf4323eSThomas Huth 1081cf4323eSThomas Huth qos_node_create_machine("x86_64/pc", qos_create_machine_pc); 1091cf4323eSThomas Huth qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL); 1101cf4323eSThomas Huth 1111cf4323eSThomas Huth qos_node_create_driver("i440FX-pcihost", NULL); 1121cf4323eSThomas Huth qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL); 1131cf4323eSThomas Huth } 1141cf4323eSThomas Huth 1151cf4323eSThomas Huth libqos_init(pc_machine_register_nodes); 116