qfw.h 4.3 KB

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