arm-smdkc210-machine.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.1 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. #include "qemu/osdep.h"
  19. #include "../libqtest.h"
  20. #include "qemu/module.h"
  21. #include "malloc.h"
  22. #include "qgraph.h"
  23. #include "sdhci.h"
  24. #define ARM_PAGE_SIZE 4096
  25. #define SMDKC210_RAM_ADDR 0x40000000ull
  26. #define SMDKC210_RAM_SIZE 0x40000000ull
  27. typedef struct QSmdkc210Machine QSmdkc210Machine;
  28. struct QSmdkc210Machine {
  29. QOSGraphObject obj;
  30. QGuestAllocator alloc;
  31. QSDHCI_MemoryMapped sdhci;
  32. };
  33. static void *smdkc210_get_driver(void *object, const char *interface)
  34. {
  35. QSmdkc210Machine *machine = object;
  36. if (!g_strcmp0(interface, "memory")) {
  37. return &machine->alloc;
  38. }
  39. fprintf(stderr, "%s not present in arm/smdkc210\n", interface);
  40. g_assert_not_reached();
  41. }
  42. static QOSGraphObject *smdkc210_get_device(void *obj, const char *device)
  43. {
  44. QSmdkc210Machine *machine = obj;
  45. if (!g_strcmp0(device, "generic-sdhci")) {
  46. return &machine->sdhci.obj;
  47. }
  48. fprintf(stderr, "%s not present in arm/smdkc210\n", device);
  49. g_assert_not_reached();
  50. }
  51. static void smdkc210_destructor(QOSGraphObject *obj)
  52. {
  53. QSmdkc210Machine *machine = (QSmdkc210Machine *) obj;
  54. alloc_destroy(&machine->alloc);
  55. }
  56. static void *qos_create_machine_arm_smdkc210(QTestState *qts)
  57. {
  58. QSmdkc210Machine *machine = g_new0(QSmdkc210Machine, 1);
  59. alloc_init(&machine->alloc, 0,
  60. SMDKC210_RAM_ADDR,
  61. SMDKC210_RAM_ADDR + SMDKC210_RAM_SIZE,
  62. ARM_PAGE_SIZE);
  63. machine->obj.get_device = smdkc210_get_device;
  64. machine->obj.get_driver = smdkc210_get_driver;
  65. machine->obj.destructor = smdkc210_destructor;
  66. qos_init_sdhci_mm(&machine->sdhci, qts, 0x12510000, &(QSDHCIProperties) {
  67. .version = 2,
  68. .baseclock = 0,
  69. .capab.sdma = true,
  70. .capab.reg = 0x5e80080,
  71. });
  72. return &machine->obj;
  73. }
  74. static void smdkc210_register_nodes(void)
  75. {
  76. qos_node_create_machine("arm/smdkc210", qos_create_machine_arm_smdkc210);
  77. qos_node_contains("arm/smdkc210", "generic-sdhci", NULL);
  78. }
  79. libqos_init(smdkc210_register_nodes);