qemu_fw_cfg.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __FW_CFG__
  7. #define __FW_CFG__
  8. #define FW_CONTROL_PORT 0x510
  9. #define FW_DATA_PORT 0x511
  10. #define FW_DMA_PORT_LOW 0x514
  11. #define FW_DMA_PORT_HIGH 0x518
  12. #include <linux/list.h>
  13. enum qemu_fwcfg_items {
  14. FW_CFG_SIGNATURE = 0x00,
  15. FW_CFG_ID = 0x01,
  16. FW_CFG_UUID = 0x02,
  17. FW_CFG_RAM_SIZE = 0x03,
  18. FW_CFG_NOGRAPHIC = 0x04,
  19. FW_CFG_NB_CPUS = 0x05,
  20. FW_CFG_MACHINE_ID = 0x06,
  21. FW_CFG_KERNEL_ADDR = 0x07,
  22. FW_CFG_KERNEL_SIZE = 0x08,
  23. FW_CFG_KERNEL_CMDLINE = 0x09,
  24. FW_CFG_INITRD_ADDR = 0x0a,
  25. FW_CFG_INITRD_SIZE = 0x0b,
  26. FW_CFG_BOOT_DEVICE = 0x0c,
  27. FW_CFG_NUMA = 0x0d,
  28. FW_CFG_BOOT_MENU = 0x0e,
  29. FW_CFG_MAX_CPUS = 0x0f,
  30. FW_CFG_KERNEL_ENTRY = 0x10,
  31. FW_CFG_KERNEL_DATA = 0x11,
  32. FW_CFG_INITRD_DATA = 0x12,
  33. FW_CFG_CMDLINE_ADDR = 0x13,
  34. FW_CFG_CMDLINE_SIZE = 0x14,
  35. FW_CFG_CMDLINE_DATA = 0x15,
  36. FW_CFG_SETUP_ADDR = 0x16,
  37. FW_CFG_SETUP_SIZE = 0x17,
  38. FW_CFG_SETUP_DATA = 0x18,
  39. FW_CFG_FILE_DIR = 0x19,
  40. FW_CFG_FILE_FIRST = 0x20,
  41. FW_CFG_WRITE_CHANNEL = 0x4000,
  42. FW_CFG_ARCH_LOCAL = 0x8000,
  43. FW_CFG_INVALID = 0xffff,
  44. };
  45. enum {
  46. BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1,
  47. BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2,
  48. BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
  49. };
  50. enum {
  51. BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
  52. BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
  53. };
  54. #define FW_CFG_FILE_SLOTS 0x10
  55. #define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST + FW_CFG_FILE_SLOTS)
  56. #define FW_CFG_ENTRY_MASK ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
  57. #define FW_CFG_MAX_FILE_PATH 56
  58. #define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
  59. #define QEMU_FW_CFG_SIGNATURE (('Q' << 24) | ('E' << 16) | ('M' << 8) | 'U')
  60. #define FW_CFG_DMA_ERROR (1 << 0)
  61. #define FW_CFG_DMA_READ (1 << 1)
  62. #define FW_CFG_DMA_SKIP (1 << 2)
  63. #define FW_CFG_DMA_SELECT (1 << 3)
  64. #define FW_CFG_DMA_ENABLED (1 << 1)
  65. struct fw_cfg_file {
  66. __be32 size;
  67. __be16 select;
  68. __be16 reserved;
  69. char name[FW_CFG_MAX_FILE_PATH];
  70. };
  71. struct fw_file {
  72. struct fw_cfg_file cfg; /* firmware file information */
  73. unsigned long addr; /* firmware file in-memory address */
  74. struct list_head list; /* list node to link to fw_list */
  75. };
  76. struct fw_cfg_dma_access {
  77. __be32 control;
  78. __be32 length;
  79. __be64 address;
  80. };
  81. struct bios_linker_entry {
  82. __le32 command;
  83. union {
  84. /*
  85. * COMMAND_ALLOCATE - allocate a table from @alloc.file
  86. * subject to @alloc.align alignment (must be power of 2)
  87. * and @alloc.zone (can be HIGH or FSEG) requirements.
  88. *
  89. * Must appear exactly once for each file, and before
  90. * this file is referenced by any other command.
  91. */
  92. struct {
  93. char file[BIOS_LINKER_LOADER_FILESZ];
  94. __le32 align;
  95. uint8_t zone;
  96. } alloc;
  97. /*
  98. * COMMAND_ADD_POINTER - patch the table (originating from
  99. * @dest_file) at @pointer.offset, by adding a pointer to the
  100. * table originating from @src_file. 1,2,4 or 8 byte unsigned
  101. * addition is used depending on @pointer.size.
  102. */
  103. struct {
  104. char dest_file[BIOS_LINKER_LOADER_FILESZ];
  105. char src_file[BIOS_LINKER_LOADER_FILESZ];
  106. __le32 offset;
  107. uint8_t size;
  108. } pointer;
  109. /*
  110. * COMMAND_ADD_CHECKSUM - calculate checksum of the range
  111. * specified by @cksum_start and @cksum_length fields,
  112. * and then add the value at @cksum.offset.
  113. * Checksum simply sums -X for each byte X in the range
  114. * using 8-bit math.
  115. */
  116. struct {
  117. char file[BIOS_LINKER_LOADER_FILESZ];
  118. __le32 offset;
  119. __le32 start;
  120. __le32 length;
  121. } cksum;
  122. /* padding */
  123. char pad[124];
  124. };
  125. } __packed;
  126. /**
  127. * Initialize QEMU fw_cfg interface
  128. */
  129. void qemu_fwcfg_init(void);
  130. void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address);
  131. int qemu_fwcfg_read_firmware_list(void);
  132. struct fw_file *qemu_fwcfg_find_file(const char *name);
  133. void qemu_fwcfg_free_files(void);
  134. /**
  135. * Get system cpu number
  136. *
  137. * @return: cpu number in system
  138. */
  139. int qemu_fwcfg_online_cpus(void);
  140. #endif