cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]
authorMiao Yan <yanmiaobest@gmail.com>
Mon, 23 May 2016 02:37:17 +0000 (19:37 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Mon, 23 May 2016 07:18:00 +0000 (15:18 +0800)
Make file names consistent with CONFIG_QFW and CONFIG_CMD_QFW

Signed-off-by: Miao Yan <yanmiaobest@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
14 files changed:
arch/x86/cpu/mp_init.c
arch/x86/cpu/qemu/acpi_table.c
arch/x86/cpu/qemu/cpu.c
arch/x86/cpu/qemu/qemu.c
cmd/Kconfig
cmd/Makefile
cmd/qfw.c
configs/qemu-x86_defconfig
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/qemu_fw_cfg.c [deleted file]
drivers/misc/qfw.c [new file with mode: 0644]
include/qemu_fw_cfg.h [deleted file]
include/qfw.h [new file with mode: 0644]

index c44a286e5bb54c14a7346e9e890066d67f193bf4..8207274879ce67663eb682cb25b5d68bcfaafe1c 100644 (file)
@@ -11,7 +11,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
-#include <qemu_fw_cfg.h>
+#include <qfw.h>
 #include <asm/atomic.h>
 #include <asm/cpu.h>
 #include <asm/interrupt.h>
index b17fa03bc897cc54121f895d9680bb8039117b8e..5bb1756c53030e966e0f1fdfa9857e10d88ebe96 100644 (file)
@@ -8,7 +8,7 @@
 #include <command.h>
 #include <errno.h>
 #include <malloc.h>
-#include <qemu_fw_cfg.h>
+#include <qfw.h>
 #include <asm/io.h>
 #include <asm/tables.h>
 #include <asm/e820.h>
index 4d2989a7084f30f9a316b801cac1cf37471ae723..b1a965e7156d227e79af60eec90312de4780e780 100644 (file)
@@ -8,7 +8,7 @@
 #include <cpu.h>
 #include <dm.h>
 #include <errno.h>
-#include <qemu_fw_cfg.h>
+#include <qfw.h>
 #include <asm/cpu.h>
 
 DECLARE_GLOBAL_DATA_PTR;
index c29add39b26bfb1fa7bd3e15508a275410aa11cc..680e558ee8bb0a70bff58dac994f1228a99df1fe 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <common.h>
 #include <pci.h>
-#include <qemu_fw_cfg.h>
+#include <qfw.h>
 #include <asm/irq.h>
 #include <asm/post.h>
 #include <asm/processor.h>
index 08b761f6db9e1280b7cdf42deb829bffbd3644ea..c5a7a590644df472f6bcb385df539858ab978107 100644 (file)
@@ -593,7 +593,7 @@ config CMD_SOUND
             sound init   - set up sound system
             sound play   - play a sound
 
-config CMD_QEMU_FW_CFG
+config CMD_QFW
        bool "qfw"
        depends on X86
        select QFW
index ff4fc5b98e890ad27e6dd0d0d6b14753cecff199..9ce7861f8226b49db9ec484e5e70a81557b746e4 100644 (file)
@@ -105,7 +105,7 @@ endif
 obj-y += pcmcia.o
 obj-$(CONFIG_CMD_PORTIO) += portio.o
 obj-$(CONFIG_CMD_PXE) += pxe.o
-obj-$(CONFIG_CMD_QEMU_FW_CFG) += qfw.o
+obj-$(CONFIG_CMD_QFW) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
index 37f1aa6fc7bd8ac862e1e53b2538e287651d07fd..c6730bf2d3ef722eba8e538103b7e3ba47aafc7e 100644 (file)
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -7,7 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <qemu_fw_cfg.h>
+#include <qfw.h>
 
 /*
  * This function prepares kernel for zboot. It loads kernel data
index a813e5b438947ecef63d27220be924bd055474db..45bb3ec0e9e9f3656fbf28070caed21983abf118 100644 (file)
@@ -20,7 +20,7 @@ CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_QEMU_FW_CFG=y
+CONFIG_CMD_QFW=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
index fa537002d4b64d8d0365aa3a2724c11f7b9981d7..c40f6b577f3bc9a862e5616ccc9fb50859724224 100644 (file)
@@ -142,6 +142,6 @@ config QFW
        bool
        help
          Hidden option to enable QEMU fw_cfg interface. This will be selected by
-         either CONFIG_CMD_QEMU_FW_CFG or CONFIG_GENERATE_ACPI_TABLE.
+         either CONFIG_CMD_QFW or CONFIG_GENERATE_ACPI_TABLE.
 
 endmenu
index 4893086b72cfb68b784adde9c4f25c8ba8ef30a5..98704f2085d1be43351d680e9382753ac336fbbc 100644 (file)
@@ -43,4 +43,4 @@ obj-$(CONFIG_PCA9551_LED) += pca9551_led.o
 obj-$(CONFIG_RESET) += reset-uclass.o
 obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o
 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
-obj-$(CONFIG_QFW) += qemu_fw_cfg.o
+obj-$(CONFIG_QFW) += qfw.o
diff --git a/drivers/misc/qemu_fw_cfg.c b/drivers/misc/qemu_fw_cfg.c
deleted file mode 100644 (file)
index 0f72549..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <errno.h>
-#include <malloc.h>
-#include <qemu_fw_cfg.h>
-#include <asm/io.h>
-#include <linux/list.h>
-
-static bool fwcfg_present;
-static bool fwcfg_dma_present;
-static struct fw_cfg_arch_ops *fwcfg_arch_ops;
-
-static LIST_HEAD(fw_list);
-
-/* Read configuration item using fw_cfg PIO interface */
-static void qemu_fwcfg_read_entry_pio(uint16_t entry,
-               uint32_t size, void *address)
-{
-       debug("qemu_fwcfg_read_entry_pio: entry 0x%x, size %u address %p\n",
-             entry, size, address);
-
-       return fwcfg_arch_ops->arch_read_pio(entry, size, address);
-}
-
-/* Read configuration item using fw_cfg DMA interface */
-static void qemu_fwcfg_read_entry_dma(uint16_t entry,
-               uint32_t size, void *address)
-{
-       struct fw_cfg_dma_access dma;
-
-       dma.length = cpu_to_be32(size);
-       dma.address = cpu_to_be64((uintptr_t)address);
-       dma.control = cpu_to_be32(FW_CFG_DMA_READ);
-
-       /*
-        * writting FW_CFG_INVALID will cause read operation to resume at
-        * last offset, otherwise read will start at offset 0
-        */
-       if (entry != FW_CFG_INVALID)
-               dma.control |= cpu_to_be32(FW_CFG_DMA_SELECT | (entry << 16));
-
-       barrier();
-
-       debug("qemu_fwcfg_read_entry_dma: entry 0x%x, size %u address %p, control 0x%x\n",
-             entry, size, address, be32_to_cpu(dma.control));
-
-       fwcfg_arch_ops->arch_read_dma(&dma);
-}
-
-bool qemu_fwcfg_present(void)
-{
-       return fwcfg_present;
-}
-
-bool qemu_fwcfg_dma_present(void)
-{
-       return fwcfg_dma_present;
-}
-
-void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address)
-{
-       if (fwcfg_dma_present)
-               qemu_fwcfg_read_entry_dma(entry, length, address);
-       else
-               qemu_fwcfg_read_entry_pio(entry, length, address);
-}
-
-int qemu_fwcfg_online_cpus(void)
-{
-       uint16_t nb_cpus;
-
-       if (!fwcfg_present)
-               return -ENODEV;
-
-       qemu_fwcfg_read_entry(FW_CFG_NB_CPUS, 2, &nb_cpus);
-
-       return le16_to_cpu(nb_cpus);
-}
-
-int qemu_fwcfg_read_firmware_list(void)
-{
-       int i;
-       uint32_t count;
-       struct fw_file *file;
-       struct list_head *entry;
-
-       /* don't read it twice */
-       if (!list_empty(&fw_list))
-               return 0;
-
-       qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, &count);
-       if (!count)
-               return 0;
-
-       count = be32_to_cpu(count);
-       for (i = 0; i < count; i++) {
-               file = malloc(sizeof(*file));
-               if (!file) {
-                       printf("error: allocating resource\n");
-                       goto err;
-               }
-               qemu_fwcfg_read_entry(FW_CFG_INVALID,
-                                     sizeof(struct fw_cfg_file), &file->cfg);
-               file->addr = 0;
-               list_add_tail(&file->list, &fw_list);
-       }
-
-       return 0;
-
-err:
-       list_for_each(entry, &fw_list) {
-               file = list_entry(entry, struct fw_file, list);
-               free(file);
-       }
-
-       return -ENOMEM;
-}
-
-struct fw_file *qemu_fwcfg_find_file(const char *name)
-{
-       struct list_head *entry;
-       struct fw_file *file;
-
-       list_for_each(entry, &fw_list) {
-               file = list_entry(entry, struct fw_file, list);
-               if (!strcmp(file->cfg.name, name))
-                       return file;
-       }
-
-       return NULL;
-}
-
-struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
-{
-       iter->entry = fw_list.next;
-       return list_entry((struct list_head *)iter->entry,
-                         struct fw_file, list);
-}
-
-struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
-{
-       iter->entry = ((struct list_head *)iter->entry)->next;
-       return list_entry((struct list_head *)iter->entry,
-                         struct fw_file, list);
-}
-
-bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
-{
-       return iter->entry == &fw_list;
-}
-
-void qemu_fwcfg_init(struct fw_cfg_arch_ops *ops)
-{
-       uint32_t qemu;
-       uint32_t dma_enabled;
-
-       fwcfg_present = false;
-       fwcfg_dma_present = false;
-       fwcfg_arch_ops = NULL;
-
-       if (!ops || !ops->arch_read_pio || !ops->arch_read_dma)
-               return;
-       fwcfg_arch_ops = ops;
-
-       qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, &qemu);
-       if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
-               fwcfg_present = true;
-
-       if (fwcfg_present) {
-               qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, &dma_enabled);
-               if (dma_enabled & FW_CFG_DMA_ENABLED)
-                       fwcfg_dma_present = true;
-       }
-}
diff --git a/drivers/misc/qfw.c b/drivers/misc/qfw.c
new file mode 100644 (file)
index 0000000..59d9376
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <qfw.h>
+#include <asm/io.h>
+#include <linux/list.h>
+
+static bool fwcfg_present;
+static bool fwcfg_dma_present;
+static struct fw_cfg_arch_ops *fwcfg_arch_ops;
+
+static LIST_HEAD(fw_list);
+
+/* Read configuration item using fw_cfg PIO interface */
+static void qemu_fwcfg_read_entry_pio(uint16_t entry,
+               uint32_t size, void *address)
+{
+       debug("qemu_fwcfg_read_entry_pio: entry 0x%x, size %u address %p\n",
+             entry, size, address);
+
+       return fwcfg_arch_ops->arch_read_pio(entry, size, address);
+}
+
+/* Read configuration item using fw_cfg DMA interface */
+static void qemu_fwcfg_read_entry_dma(uint16_t entry,
+               uint32_t size, void *address)
+{
+       struct fw_cfg_dma_access dma;
+
+       dma.length = cpu_to_be32(size);
+       dma.address = cpu_to_be64((uintptr_t)address);
+       dma.control = cpu_to_be32(FW_CFG_DMA_READ);
+
+       /*
+        * writting FW_CFG_INVALID will cause read operation to resume at
+        * last offset, otherwise read will start at offset 0
+        */
+       if (entry != FW_CFG_INVALID)
+               dma.control |= cpu_to_be32(FW_CFG_DMA_SELECT | (entry << 16));
+
+       barrier();
+
+       debug("qemu_fwcfg_read_entry_dma: entry 0x%x, size %u address %p, control 0x%x\n",
+             entry, size, address, be32_to_cpu(dma.control));
+
+       fwcfg_arch_ops->arch_read_dma(&dma);
+}
+
+bool qemu_fwcfg_present(void)
+{
+       return fwcfg_present;
+}
+
+bool qemu_fwcfg_dma_present(void)
+{
+       return fwcfg_dma_present;
+}
+
+void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address)
+{
+       if (fwcfg_dma_present)
+               qemu_fwcfg_read_entry_dma(entry, length, address);
+       else
+               qemu_fwcfg_read_entry_pio(entry, length, address);
+}
+
+int qemu_fwcfg_online_cpus(void)
+{
+       uint16_t nb_cpus;
+
+       if (!fwcfg_present)
+               return -ENODEV;
+
+       qemu_fwcfg_read_entry(FW_CFG_NB_CPUS, 2, &nb_cpus);
+
+       return le16_to_cpu(nb_cpus);
+}
+
+int qemu_fwcfg_read_firmware_list(void)
+{
+       int i;
+       uint32_t count;
+       struct fw_file *file;
+       struct list_head *entry;
+
+       /* don't read it twice */
+       if (!list_empty(&fw_list))
+               return 0;
+
+       qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, &count);
+       if (!count)
+               return 0;
+
+       count = be32_to_cpu(count);
+       for (i = 0; i < count; i++) {
+               file = malloc(sizeof(*file));
+               if (!file) {
+                       printf("error: allocating resource\n");
+                       goto err;
+               }
+               qemu_fwcfg_read_entry(FW_CFG_INVALID,
+                                     sizeof(struct fw_cfg_file), &file->cfg);
+               file->addr = 0;
+               list_add_tail(&file->list, &fw_list);
+       }
+
+       return 0;
+
+err:
+       list_for_each(entry, &fw_list) {
+               file = list_entry(entry, struct fw_file, list);
+               free(file);
+       }
+
+       return -ENOMEM;
+}
+
+struct fw_file *qemu_fwcfg_find_file(const char *name)
+{
+       struct list_head *entry;
+       struct fw_file *file;
+
+       list_for_each(entry, &fw_list) {
+               file = list_entry(entry, struct fw_file, list);
+               if (!strcmp(file->cfg.name, name))
+                       return file;
+       }
+
+       return NULL;
+}
+
+struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
+{
+       iter->entry = fw_list.next;
+       return list_entry((struct list_head *)iter->entry,
+                         struct fw_file, list);
+}
+
+struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
+{
+       iter->entry = ((struct list_head *)iter->entry)->next;
+       return list_entry((struct list_head *)iter->entry,
+                         struct fw_file, list);
+}
+
+bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
+{
+       return iter->entry == &fw_list;
+}
+
+void qemu_fwcfg_init(struct fw_cfg_arch_ops *ops)
+{
+       uint32_t qemu;
+       uint32_t dma_enabled;
+
+       fwcfg_present = false;
+       fwcfg_dma_present = false;
+       fwcfg_arch_ops = NULL;
+
+       if (!ops || !ops->arch_read_pio || !ops->arch_read_dma)
+               return;
+       fwcfg_arch_ops = ops;
+
+       qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, &qemu);
+       if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
+               fwcfg_present = true;
+
+       if (fwcfg_present) {
+               qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, &dma_enabled);
+               if (dma_enabled & FW_CFG_DMA_ENABLED)
+                       fwcfg_dma_present = true;
+       }
+}
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
deleted file mode 100644 (file)
index b0b3b59..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#ifndef __FW_CFG__
-#define __FW_CFG__
-
-#include <linux/list.h>
-
-enum qemu_fwcfg_items {
-       FW_CFG_SIGNATURE        = 0x00,
-       FW_CFG_ID               = 0x01,
-       FW_CFG_UUID             = 0x02,
-       FW_CFG_RAM_SIZE         = 0x03,
-       FW_CFG_NOGRAPHIC        = 0x04,
-       FW_CFG_NB_CPUS          = 0x05,
-       FW_CFG_MACHINE_ID       = 0x06,
-       FW_CFG_KERNEL_ADDR      = 0x07,
-       FW_CFG_KERNEL_SIZE      = 0x08,
-       FW_CFG_KERNEL_CMDLINE   = 0x09,
-       FW_CFG_INITRD_ADDR      = 0x0a,
-       FW_CFG_INITRD_SIZE      = 0x0b,
-       FW_CFG_BOOT_DEVICE      = 0x0c,
-       FW_CFG_NUMA             = 0x0d,
-       FW_CFG_BOOT_MENU        = 0x0e,
-       FW_CFG_MAX_CPUS         = 0x0f,
-       FW_CFG_KERNEL_ENTRY     = 0x10,
-       FW_CFG_KERNEL_DATA      = 0x11,
-       FW_CFG_INITRD_DATA      = 0x12,
-       FW_CFG_CMDLINE_ADDR     = 0x13,
-       FW_CFG_CMDLINE_SIZE     = 0x14,
-       FW_CFG_CMDLINE_DATA     = 0x15,
-       FW_CFG_SETUP_ADDR       = 0x16,
-       FW_CFG_SETUP_SIZE       = 0x17,
-       FW_CFG_SETUP_DATA       = 0x18,
-       FW_CFG_FILE_DIR         = 0x19,
-       FW_CFG_FILE_FIRST       = 0x20,
-       FW_CFG_WRITE_CHANNEL    = 0x4000,
-       FW_CFG_ARCH_LOCAL       = 0x8000,
-       FW_CFG_INVALID          = 0xffff,
-};
-
-enum {
-       BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
-       BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
-       BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
-};
-
-enum {
-       BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
-       BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
-};
-
-#define FW_CFG_FILE_SLOTS      0x10
-#define FW_CFG_MAX_ENTRY       (FW_CFG_FILE_FIRST + FW_CFG_FILE_SLOTS)
-#define FW_CFG_ENTRY_MASK       ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
-
-#define FW_CFG_MAX_FILE_PATH   56
-#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
-
-#define QEMU_FW_CFG_SIGNATURE  (('Q' << 24) | ('E' << 16) | ('M' << 8) | 'U')
-
-#define FW_CFG_DMA_ERROR       (1 << 0)
-#define FW_CFG_DMA_READ        (1 << 1)
-#define FW_CFG_DMA_SKIP        (1 << 2)
-#define FW_CFG_DMA_SELECT      (1 << 3)
-
-#define FW_CFG_DMA_ENABLED     (1 << 1)
-
-struct fw_cfg_file {
-       __be32 size;
-       __be16 select;
-       __be16 reserved;
-       char name[FW_CFG_MAX_FILE_PATH];
-};
-
-struct fw_file {
-       struct fw_cfg_file cfg; /* firmware file information */
-       unsigned long addr;     /* firmware file in-memory address */
-       struct list_head list;  /* list node to link to fw_list */
-};
-
-struct fw_cfg_file_iter {
-       struct list_head *entry; /* structure to iterate file list */
-};
-
-struct fw_cfg_dma_access {
-       __be32 control;
-       __be32 length;
-       __be64 address;
-};
-
-struct fw_cfg_arch_ops {
-       void (*arch_read_pio)(uint16_t selector, uint32_t size,
-                       void *address);
-       void (*arch_read_dma)(struct fw_cfg_dma_access *dma);
-};
-
-struct bios_linker_entry {
-       __le32 command;
-       union {
-               /*
-                * COMMAND_ALLOCATE - allocate a table from @alloc.file
-                * subject to @alloc.align alignment (must be power of 2)
-                * and @alloc.zone (can be HIGH or FSEG) requirements.
-                *
-                * Must appear exactly once for each file, and before
-                * this file is referenced by any other command.
-                */
-               struct {
-                       char file[BIOS_LINKER_LOADER_FILESZ];
-                       __le32 align;
-                       uint8_t zone;
-               } alloc;
-
-               /*
-                * COMMAND_ADD_POINTER - patch the table (originating from
-                * @dest_file) at @pointer.offset, by adding a pointer to the
-                * table originating from @src_file. 1,2,4 or 8 byte unsigned
-                * addition is used depending on @pointer.size.
-                */
-               struct {
-                       char dest_file[BIOS_LINKER_LOADER_FILESZ];
-                       char src_file[BIOS_LINKER_LOADER_FILESZ];
-                       __le32 offset;
-                       uint8_t size;
-               } pointer;
-
-               /*
-                * COMMAND_ADD_CHECKSUM - calculate checksum of the range
-                * specified by @cksum_start and @cksum_length fields,
-                * and then add the value at @cksum.offset.
-                * Checksum simply sums -X for each byte X in the range
-                * using 8-bit math.
-                */
-               struct {
-                       char file[BIOS_LINKER_LOADER_FILESZ];
-                       __le32 offset;
-                       __le32 start;
-                       __le32 length;
-               } cksum;
-
-               /* padding */
-               char pad[124];
-       };
-} __packed;
-
-/**
- * Initialize QEMU fw_cfg interface
- *
- * @ops: arch specific read operations
- */
-void qemu_fwcfg_init(struct fw_cfg_arch_ops *ops);
-
-void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address);
-int qemu_fwcfg_read_firmware_list(void);
-struct fw_file *qemu_fwcfg_find_file(const char *name);
-
-/**
- * Get system cpu number
- *
- * @return:   cpu number in system
- */
-int qemu_fwcfg_online_cpus(void);
-
-/* helper functions to iterate firmware file list */
-struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter);
-struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter);
-bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter);
-
-bool qemu_fwcfg_present(void);
-bool qemu_fwcfg_dma_present(void);
-
-#endif
diff --git a/include/qfw.h b/include/qfw.h
new file mode 100644 (file)
index 0000000..b0b3b59
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __FW_CFG__
+#define __FW_CFG__
+
+#include <linux/list.h>
+
+enum qemu_fwcfg_items {
+       FW_CFG_SIGNATURE        = 0x00,
+       FW_CFG_ID               = 0x01,
+       FW_CFG_UUID             = 0x02,
+       FW_CFG_RAM_SIZE         = 0x03,
+       FW_CFG_NOGRAPHIC        = 0x04,
+       FW_CFG_NB_CPUS          = 0x05,
+       FW_CFG_MACHINE_ID       = 0x06,
+       FW_CFG_KERNEL_ADDR      = 0x07,
+       FW_CFG_KERNEL_SIZE      = 0x08,
+       FW_CFG_KERNEL_CMDLINE   = 0x09,
+       FW_CFG_INITRD_ADDR      = 0x0a,
+       FW_CFG_INITRD_SIZE      = 0x0b,
+       FW_CFG_BOOT_DEVICE      = 0x0c,
+       FW_CFG_NUMA             = 0x0d,
+       FW_CFG_BOOT_MENU        = 0x0e,
+       FW_CFG_MAX_CPUS         = 0x0f,
+       FW_CFG_KERNEL_ENTRY     = 0x10,
+       FW_CFG_KERNEL_DATA      = 0x11,
+       FW_CFG_INITRD_DATA      = 0x12,
+       FW_CFG_CMDLINE_ADDR     = 0x13,
+       FW_CFG_CMDLINE_SIZE     = 0x14,
+       FW_CFG_CMDLINE_DATA     = 0x15,
+       FW_CFG_SETUP_ADDR       = 0x16,
+       FW_CFG_SETUP_SIZE       = 0x17,
+       FW_CFG_SETUP_DATA       = 0x18,
+       FW_CFG_FILE_DIR         = 0x19,
+       FW_CFG_FILE_FIRST       = 0x20,
+       FW_CFG_WRITE_CHANNEL    = 0x4000,
+       FW_CFG_ARCH_LOCAL       = 0x8000,
+       FW_CFG_INVALID          = 0xffff,
+};
+
+enum {
+       BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
+       BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
+       BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
+};
+
+enum {
+       BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
+       BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
+};
+
+#define FW_CFG_FILE_SLOTS      0x10
+#define FW_CFG_MAX_ENTRY       (FW_CFG_FILE_FIRST + FW_CFG_FILE_SLOTS)
+#define FW_CFG_ENTRY_MASK       ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
+
+#define FW_CFG_MAX_FILE_PATH   56
+#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
+
+#define QEMU_FW_CFG_SIGNATURE  (('Q' << 24) | ('E' << 16) | ('M' << 8) | 'U')
+
+#define FW_CFG_DMA_ERROR       (1 << 0)
+#define FW_CFG_DMA_READ        (1 << 1)
+#define FW_CFG_DMA_SKIP        (1 << 2)
+#define FW_CFG_DMA_SELECT      (1 << 3)
+
+#define FW_CFG_DMA_ENABLED     (1 << 1)
+
+struct fw_cfg_file {
+       __be32 size;
+       __be16 select;
+       __be16 reserved;
+       char name[FW_CFG_MAX_FILE_PATH];
+};
+
+struct fw_file {
+       struct fw_cfg_file cfg; /* firmware file information */
+       unsigned long addr;     /* firmware file in-memory address */
+       struct list_head list;  /* list node to link to fw_list */
+};
+
+struct fw_cfg_file_iter {
+       struct list_head *entry; /* structure to iterate file list */
+};
+
+struct fw_cfg_dma_access {
+       __be32 control;
+       __be32 length;
+       __be64 address;
+};
+
+struct fw_cfg_arch_ops {
+       void (*arch_read_pio)(uint16_t selector, uint32_t size,
+                       void *address);
+       void (*arch_read_dma)(struct fw_cfg_dma_access *dma);
+};
+
+struct bios_linker_entry {
+       __le32 command;
+       union {
+               /*
+                * COMMAND_ALLOCATE - allocate a table from @alloc.file
+                * subject to @alloc.align alignment (must be power of 2)
+                * and @alloc.zone (can be HIGH or FSEG) requirements.
+                *
+                * Must appear exactly once for each file, and before
+                * this file is referenced by any other command.
+                */
+               struct {
+                       char file[BIOS_LINKER_LOADER_FILESZ];
+                       __le32 align;
+                       uint8_t zone;
+               } alloc;
+
+               /*
+                * COMMAND_ADD_POINTER - patch the table (originating from
+                * @dest_file) at @pointer.offset, by adding a pointer to the
+                * table originating from @src_file. 1,2,4 or 8 byte unsigned
+                * addition is used depending on @pointer.size.
+                */
+               struct {
+                       char dest_file[BIOS_LINKER_LOADER_FILESZ];
+                       char src_file[BIOS_LINKER_LOADER_FILESZ];
+                       __le32 offset;
+                       uint8_t size;
+               } pointer;
+
+               /*
+                * COMMAND_ADD_CHECKSUM - calculate checksum of the range
+                * specified by @cksum_start and @cksum_length fields,
+                * and then add the value at @cksum.offset.
+                * Checksum simply sums -X for each byte X in the range
+                * using 8-bit math.
+                */
+               struct {
+                       char file[BIOS_LINKER_LOADER_FILESZ];
+                       __le32 offset;
+                       __le32 start;
+                       __le32 length;
+               } cksum;
+
+               /* padding */
+               char pad[124];
+       };
+} __packed;
+
+/**
+ * Initialize QEMU fw_cfg interface
+ *
+ * @ops: arch specific read operations
+ */
+void qemu_fwcfg_init(struct fw_cfg_arch_ops *ops);
+
+void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address);
+int qemu_fwcfg_read_firmware_list(void);
+struct fw_file *qemu_fwcfg_find_file(const char *name);
+
+/**
+ * Get system cpu number
+ *
+ * @return:   cpu number in system
+ */
+int qemu_fwcfg_online_cpus(void);
+
+/* helper functions to iterate firmware file list */
+struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter);
+struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter);
+bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter);
+
+bool qemu_fwcfg_present(void);
+bool qemu_fwcfg_dma_present(void);
+
+#endif