qfw.h 4.3 KB

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