arm-n800-machine.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * libqos driver framework
  3. *
  4. * Copyright (c) 2019 Red Hat, Inc.
  5. *
  6. * Author: Paolo Bonzini <pbonzini@redhat.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License version 2.1 as published by the Free Software Foundation.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>
  19. */
  20. #include "qemu/osdep.h"
  21. #include "../libqtest.h"
  22. #include "malloc.h"
  23. #include "qgraph.h"
  24. #include "i2c.h"
  25. #define ARM_PAGE_SIZE 4096
  26. #define N800_RAM_START 0x80000000
  27. #define N800_RAM_END 0x88000000
  28. typedef struct QN800Machine QN800Machine;
  29. struct QN800Machine {
  30. QOSGraphObject obj;
  31. QGuestAllocator alloc;
  32. OMAPI2C i2c_1;
  33. };
  34. static void *n800_get_driver(void *object, const char *interface)
  35. {
  36. QN800Machine *machine = object;
  37. if (!g_strcmp0(interface, "memory")) {
  38. return &machine->alloc;
  39. }
  40. fprintf(stderr, "%s not present in arm/n800\n", interface);
  41. g_assert_not_reached();
  42. }
  43. static QOSGraphObject *n800_get_device(void *obj, const char *device)
  44. {
  45. QN800Machine *machine = obj;
  46. if (!g_strcmp0(device, "omap_i2c")) {
  47. return &machine->i2c_1.obj;
  48. }
  49. fprintf(stderr, "%s not present in arm/n800\n", device);
  50. g_assert_not_reached();
  51. }
  52. static void n800_destructor(QOSGraphObject *obj)
  53. {
  54. QN800Machine *machine = (QN800Machine *) obj;
  55. alloc_destroy(&machine->alloc);
  56. }
  57. static void *qos_create_machine_arm_n800(QTestState *qts)
  58. {
  59. QN800Machine *machine = g_new0(QN800Machine, 1);
  60. alloc_init(&machine->alloc, 0,
  61. N800_RAM_START,
  62. N800_RAM_END,
  63. ARM_PAGE_SIZE);
  64. machine->obj.get_device = n800_get_device;
  65. machine->obj.get_driver = n800_get_driver;
  66. machine->obj.destructor = n800_destructor;
  67. omap_i2c_init(&machine->i2c_1, qts, 0x48070000);
  68. return &machine->obj;
  69. }
  70. static void n800_register_nodes(void)
  71. {
  72. QOSGraphEdgeOptions edge = {
  73. .extra_device_opts = "bus=i2c-bus.0"
  74. };
  75. qos_node_create_machine("arm/n800", qos_create_machine_arm_n800);
  76. qos_node_contains("arm/n800", "omap_i2c", &edge, NULL);
  77. }
  78. libqos_init(n800_register_nodes);