Re: [U-Boot] [PATCH 2/2] x86: qemu: qfw: Implement acpi_get_rsdp_addr()

2018-02-04 Thread Miao Yan
On Tue, Jan 30, 2018 at 9:01 PM, Bin Meng  wrote:
> U-Boot on QEMU does not build ACPI table by ourself, instead it uses
> the prebuilt ACPI table via the qfw interface. This implements the
> qfw version of acpi_get_rsdp_addr() for setup_zimage().
>
> Signed-off-by: Bin Meng 
> ---
>
>  drivers/misc/qfw.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/misc/qfw.c b/drivers/misc/qfw.c
> index a8af9e0..9a54803 100644
> --- a/drivers/misc/qfw.c
> +++ b/drivers/misc/qfw.c
> @@ -222,6 +222,14 @@ out:
> free(table_loader);
> return addr;
>  }
> +
> +ulong acpi_get_rsdp_addr(void)
> +{
> +   struct fw_file *file;
> +
> +   file = qemu_fwcfg_find_file("etc/acpi/rsdp");
> +   return file->addr;

qemu_fwcfg_find_file() can return NULL. Don't we need to check that ? Or
can we assume etc/acpi/rsdp is always present ?

Sorry for the late response.

Miao

> +}
>  #endif
>
>  /* Read configuration item using fw_cfg PIO interface */
> --
> 2.7.4
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 13/13] config: sandbox: enable qfw and cmd_qfw for testing

2016-05-22 Thread Miao Yan
This patch enables qfw and cmd_qfw on sandbox for build coverage test

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v3:
 - fix config option order

 configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index afdf4a3..4cc3a14 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -47,6 +47,7 @@ CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
+CONFIG_CMD_QFW=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
@@ -96,6 +97,7 @@ CONFIG_CROS_EC_SPI=y
 CONFIG_PWRSEQ=y
 CONFIG_SPL_PWRSEQ=y
 CONFIG_RESET=y
+CONFIG_QFW=y
 CONFIG_DM_MMC=y
 CONFIG_SPI_FLASH_SANDBOX=y
 CONFIG_SPI_FLASH=y
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 09/13] cmd: qfw: do not require default macros when building qfw command

2016-05-22 Thread Miao Yan
The qfw command interface makes use of CONFIG_LOADADDR and
CONFIG_RAMDISKADDR to setup kernel. But not all boards have these macros,
which causes build problem on those platforms.

This patch fixes this issue.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 cmd/qfw.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/cmd/qfw.c b/cmd/qfw.c
index c6730bf..12436ec 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -126,12 +126,20 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
env = getenv("loadaddr");
load_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_LOADADDR
(void *)CONFIG_LOADADDR;
+#else
+   NULL;
+#endif
 
env = getenv("ramdiskaddr");
initrd_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_RAMDISK_ADDR
(void *)CONFIG_RAMDISK_ADDR;
+#else
+   NULL;
+#endif
 
if (argc == 2) {
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
@@ -140,6 +148,11 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
}
 
+   if (!load_addr || !initrd_addr) {
+   printf("missing load or initrd address\n");
+   return CMD_RET_FAILURE;
+   }
+
return qemu_fwcfg_setup_kernel(load_addr, initrd_addr);
 }
 
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 10/13] cmd: qfw: do not depend on x86

2016-05-22 Thread Miao Yan
The qfw command interface used to depend on X86, this patch removes
this restriction so it can be built for sandbox for testing. For normal
usage, it can only be used with CONFIG_QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 cmd/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index c5a7a59..d51645c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,7 +595,6 @@ config CMD_SOUND
 
 config CMD_QFW
bool "qfw"
-   depends on X86
select QFW
help
  This provides access to the QEMU firmware interface.  The main
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 11/13] cmd: qfw: bring ACPI generation code into qfw core

2016-05-22 Thread Miao Yan
Loading ACPI table from QEMU's fw_cfg interface is not x86 specific
(ARM64 may also make use of it). So move the code to common place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/cpu/qemu/acpi_table.c | 209 -
 drivers/misc/qfw.c | 206 
 2 files changed, 206 insertions(+), 209 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 5bb1756..63853e4 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -5,139 +5,7 @@
  */
 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-
-/*
- * This function allocates memory for ACPI tables
- *
- * @entry : BIOS linker command entry which tells where to allocate memory
- *  (either high memory or low memory)
- * @addr  : The address that should be used for low memory allcation. If the
- *  memory allocation request is 'ZONE_HIGH' then this parameter will
- *  be ignored.
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_allocate(struct bios_linker_entry *entry, u32 *addr)
-{
-   uint32_t size, align;
-   struct fw_file *file;
-   unsigned long aligned_addr;
-
-   align = le32_to_cpu(entry->alloc.align);
-   /* align must be power of 2 */
-   if (align & (align - 1)) {
-   printf("error: wrong alignment %u\n", align);
-   return -EINVAL;
-   }
-
-   file = qemu_fwcfg_find_file(entry->alloc.file);
-   if (!file) {
-   printf("error: can't find file %s\n", entry->alloc.file);
-   return -ENOENT;
-   }
-
-   size = be32_to_cpu(file->cfg.size);
-
-   /*
-* ZONE_HIGH means we need to allocate from high memory, since
-* malloc space is already at the end of RAM, so we directly use it.
-* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
-* in which is low memory
-*/
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
-   aligned_addr = (unsigned long)memalign(align, size);
-   if (!aligned_addr) {
-   printf("error: allocating resource\n");
-   return -ENOMEM;
-   }
-   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
-   aligned_addr = ALIGN(*addr, align);
-   } else {
-   printf("error: invalid allocation zone\n");
-   return -EINVAL;
-   }
-
-   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
- file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
-
-   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
- size, (void *)aligned_addr);
-   file->addr = aligned_addr;
-
-   /* adjust address for low memory allocation */
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
-   *addr = (aligned_addr + size);
-
-   return 0;
-}
-
-/*
- * This function patches ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells how to patch
- *  ACPI tables
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_pointer(struct bios_linker_entry *entry)
-{
-   struct fw_file *dest, *src;
-   uint32_t offset = le32_to_cpu(entry->pointer.offset);
-   uint64_t pointer = 0;
-
-   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
-   if (!dest || !dest->addr)
-   return -ENOENT;
-   src = qemu_fwcfg_find_file(entry->pointer.src_file);
-   if (!src || !src->addr)
-   return -ENOENT;
-
-   debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, 
offset 0x%x size %u, 0x%llx\n",
- dest->addr, src->addr, offset, entry->pointer.size, pointer);
-
-   memcpy(, (char *)dest->addr + offset, entry->pointer.size);
-   pointer = le64_to_cpu(pointer);
-   pointer += (unsigned long)src->addr;
-   pointer = cpu_to_le64(pointer);
-   memcpy((char *)dest->addr + offset, , entry->pointer.size);
-
-   return 0;
-}
-
-/*
- * This function updates checksum fields of ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells where to update ACPI table
- *  checksums
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_checksum(struct bios_linker_entry *entry)
-{
-   struct fw_file *file;
-   uint8_t *data, cksum = 0;
-   uint8_t *cksum_start;
-
-

[U-Boot] [PATCH v3 12/13] x86: qemu: rename qemu/acpi_table.c

2016-05-22 Thread Miao Yan
Rename qemu/acpi_table.c to qemu/e820.c, because ACPI stuff is moved
to qfw core, this file only contains code for installing e820 table.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/cpu/qemu/Makefile | 3 +--
 arch/x86/cpu/qemu/{acpi_table.c => e820.c} | 0
 2 files changed, 1 insertion(+), 2 deletions(-)
 rename arch/x86/cpu/qemu/{acpi_table.c => e820.c} (100%)

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 7c08c3d..a080c5e 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,5 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
-obj-$(CONFIG_QFW) += cpu.o
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_QFW) += cpu.o e820.o
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/e820.c
similarity index 100%
rename from arch/x86/cpu/qemu/acpi_table.c
rename to arch/x86/cpu/qemu/e820.c
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 06/13] x86: qemu: move x86 specific operations out of qfw core

2016-05-22 Thread Miao Yan
The original implementation of qfw includes several x86 specific
operations, like directly calling outb/inb and using some inline
assembly code which prevents it being ported to other architectures.

This patch adds callback functions and moves those to arch/x86/

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/cpu/qemu/qemu.c   | 39 ++-
 drivers/misc/qemu_fw_cfg.c | 30 +-
 include/qemu_fw_cfg.h  | 15 +--
 3 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 32a4351..6ff9947 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,6 +15,43 @@
 
 static bool i440fx;
 
+#ifdef CONFIG_QFW
+
+#define FW_CONTROL_PORT0x510
+#define FW_DATA_PORT   0x511
+#define FW_DMA_PORT_LOW0x514
+#define FW_DMA_PORT_HIGH   0x518
+
+static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
+   uint32_t size, void *address)
+{
+   uint32_t i = 0;
+   uint8_t *data = address;
+
+   /*
+* 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)
+   outw(entry, FW_CONTROL_PORT);
+   while (size--)
+   data[i++] = inb(FW_DATA_PORT);
+}
+
+static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
+{
+   outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
+
+   while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
+   __asm__ __volatile__ ("pause");
+}
+
+static struct fw_cfg_arch_ops fwcfg_x86_ops = {
+   .arch_read_pio = qemu_x86_fwcfg_read_entry_pio,
+   .arch_read_dma = qemu_x86_fwcfg_read_entry_dma
+};
+#endif
+
 static void enable_pm_piix(void)
 {
u8 en;
@@ -89,7 +126,7 @@ static void qemu_chipset_init(void)
}
 
 #ifdef CONFIG_QFW
-   qemu_fwcfg_init();
+   qemu_fwcfg_init(_x86_ops);
 #endif
 }
 
diff --git a/drivers/misc/qemu_fw_cfg.c b/drivers/misc/qemu_fw_cfg.c
index a574bd1..0f72549 100644
--- a/drivers/misc/qemu_fw_cfg.c
+++ b/drivers/misc/qemu_fw_cfg.c
@@ -14,6 +14,7 @@
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
+static struct fw_cfg_arch_ops *fwcfg_arch_ops;
 
 static LIST_HEAD(fw_list);
 
@@ -21,17 +22,10 @@ static LIST_HEAD(fw_list);
 static void qemu_fwcfg_read_entry_pio(uint16_t entry,
uint32_t size, void *address)
 {
-   uint32_t i = 0;
-   uint8_t *data = address;
+   debug("qemu_fwcfg_read_entry_pio: entry 0x%x, size %u address %p\n",
+ entry, size, address);
 
-   /*
-* 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)
-   outw(entry, FW_CONTROL_PORT);
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
+   return fwcfg_arch_ops->arch_read_pio(entry, size, address);
 }
 
 /* Read configuration item using fw_cfg DMA interface */
@@ -53,13 +47,10 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
 
barrier();
 
-   debug("qemu_fwcfg_dma_read_entry: addr %p, length %u control 0x%x\n",
- address, size, be32_to_cpu(dma.control));
-
-   outl(cpu_to_be32((uint32_t)), FW_DMA_PORT_HIGH);
+   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));
 
-   while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_ERROR)
-   __asm__ __volatile__ ("pause");
+   fwcfg_arch_ops->arch_read_dma();
 }
 
 bool qemu_fwcfg_present(void)
@@ -164,13 +155,18 @@ bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter 
*iter)
return iter->entry == _list;
 }
 
-void qemu_fwcfg_init(void)
+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, );
if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index f718e09..b0b3b59 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -7,11 +7,6 @@
 #ifndef __FW_CFG__
 #define __FW_CFG__
 
-#define FW_CONTROL_PORT0x510
-#define FW_DATA_PORT   0x511
-#define FW_DMA_PORT_LOW0x514
-#define FW_DMA_PORT_HIGH   0x518
-
 #include 
 
 enum qemu_fwcfg_items {
@@ -97,6 +92,12 @@ struct fw_cfg_dma_access {
__be64 

[U-Boot] [PATCH v3 08/13] cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]

2016-05-22 Thread Miao Yan
Make file names consistent with CONFIG_QFW and CONFIG_CMD_QFW

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - squash with patch v2 #13

 arch/x86/cpu/mp_init.c| 2 +-
 arch/x86/cpu/qemu/acpi_table.c| 2 +-
 arch/x86/cpu/qemu/cpu.c   | 2 +-
 arch/x86/cpu/qemu/qemu.c  | 2 +-
 cmd/Kconfig   | 2 +-
 cmd/Makefile  | 2 +-
 cmd/qfw.c | 2 +-
 configs/qemu-x86_defconfig| 2 +-
 drivers/misc/Kconfig  | 2 +-
 drivers/misc/Makefile | 2 +-
 drivers/misc/{qemu_fw_cfg.c => qfw.c} | 2 +-
 include/{qemu_fw_cfg.h => qfw.h}  | 0
 12 files changed, 11 insertions(+), 11 deletions(-)
 rename drivers/misc/{qemu_fw_cfg.c => qfw.c} (99%)
 rename include/{qemu_fw_cfg.h => qfw.h} (100%)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index c44a286..8207274 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index b17fa03..5bb1756 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c
index 4d2989a..b1a965e 100644
--- a/arch/x86/cpu/qemu/cpu.c
+++ b/arch/x86/cpu/qemu/cpu.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index c29add3..680e558 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -6,7 +6,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 08b761f..c5a7a59 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -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
diff --git a/cmd/Makefile b/cmd/Makefile
index 0b7f7a2..1bbd14f 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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
diff --git a/cmd/qfw.c b/cmd/qfw.c
index 37f1aa6..c6730bf 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * This function prepares kernel for zboot. It loads kernel data
diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig
index a813e5b..45bb3ec 100644
--- a/configs/qemu-x86_defconfig
+++ b/configs/qemu-x86_defconfig
@@ -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
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index fa53700..c40f6b5 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -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
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 4893086..98704f2 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -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/qfw.c
similarity index 99%
rename from drivers/misc/qemu_fw_cfg.c
rename to drivers/misc/qfw.c
index 0f72549..59d9376 100644
--- a/drivers/misc/qemu_fw_cfg.c
+++ b/drivers/misc/qfw.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/include/qemu_fw_cfg.h b/include/qfw.h
similarity index 100%
rename from include/qemu_fw_cfg.h
rename to include/qfw.h
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 05/13] x86: qemu: split qfw command interface and qfw core

2016-05-22 Thread Miao Yan
This patch splits qfw command interface and qfw core function into two
files, and introduces a new Kconfig option (CONFIG_QFW) for qfw core.

Now when qfw command interface is enabled, it will automatically select
qfw core. This patch also makes the ACPI table generation select
CONFIG_QFW.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - fix a typo in commit message

 arch/x86/Kconfig |   2 +-
 arch/x86/cpu/mp_init.c   |   4 +-
 arch/x86/cpu/qemu/Makefile   |   3 +-
 arch/x86/cpu/qemu/qemu.c |   2 +
 cmd/Kconfig  |   1 +
 cmd/Makefile |   2 +-
 cmd/{qemu_fw_cfg.c => qfw.c} | 172 
 drivers/misc/Kconfig |   6 ++
 drivers/misc/Makefile|   1 +
 drivers/misc/qemu_fw_cfg.c   | 184 +++
 10 files changed, 200 insertions(+), 177 deletions(-)
 rename cmd/{qemu_fw_cfg.c => qfw.c} (55%)
 create mode 100644 drivers/misc/qemu_fw_cfg.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 3e360ec..2f63170 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,7 +436,7 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
-   select CMD_QEMU_FW_CFG if QEMU
+   select QFW if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 13bec7a..c44a286 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -420,7 +420,7 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
 static int qemu_cpu_fixup(void)
 {
int ret;
@@ -496,7 +496,7 @@ int mp_init(struct mp_params *p)
if (ret)
return ret;
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
ret = qemu_cpu_fixup();
if (ret)
return ret;
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 43ee4bd..7c08c3d 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,6 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += cpu.o qemu.o
+obj-y += qemu.o
+obj-$(CONFIG_QFW) += cpu.o
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index b41e4ec..32a4351 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -88,7 +88,9 @@ static void qemu_chipset_init(void)
enable_pm_ich9();
}
 
+#ifdef CONFIG_QFW
qemu_fwcfg_init();
+#endif
 }
 
 int arch_cpu_init(void)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c0fffe3..08b761f 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -596,6 +596,7 @@ config CMD_SOUND
 config CMD_QEMU_FW_CFG
bool "qfw"
depends on X86
+   select QFW
help
  This provides access to the QEMU firmware interface.  The main
  feature is to allow easy loading of files passed to qemu-system
diff --git a/cmd/Makefile b/cmd/Makefile
index f99e67d..0b7f7a2 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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) += qemu_fw_cfg.o
+obj-$(CONFIG_CMD_QEMU_FW_CFG) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
diff --git a/cmd/qemu_fw_cfg.c b/cmd/qfw.c
similarity index 55%
rename from cmd/qemu_fw_cfg.c
rename to cmd/qfw.c
index aab6b1a..37f1aa6 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qfw.c
@@ -7,90 +7,7 @@
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
-#include 
-
-static bool fwcfg_present;
-static bool fwcfg_dma_present;
-
-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)
-{
-   uint32_t i = 0;
-   uint8_t *data = address;
-
-   /*
-* 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)
-   outw(entry, FW_CONTROL_PORT);
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
-}
-
-/* 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 operati

[U-Boot] [PATCH v3 03/13] cmd: qfw: remove qemu_fwcfg_free_files()

2016-05-22 Thread Miao Yan
This patch is part of the qfw refactor work.

The qemu_fwcfg_free_files() function is only used in error handling in
ACPI table generation, let's not make this a core function and move it
to the right place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/cpu/qemu/acpi_table.c | 13 +++--
 cmd/qemu_fw_cfg.c  | 12 
 include/qemu_fw_cfg.h  |  1 -
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 49381ac..b17fa03 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -235,8 +235,17 @@ u32 write_acpi_tables(u32 addr)
}
 
 out:
-   if (ret)
-   qemu_fwcfg_free_files();
+   if (ret) {
+   struct fw_cfg_file_iter iter;
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
+   if (file->addr) {
+   free((void *)file->addr);
+   file->addr = 0;
+   }
+   }
+   }
 
free(table_loader);
return addr;
diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 192b7d1..9f03ab6 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -217,18 +217,6 @@ struct fw_file *qemu_fwcfg_find_file(const char *name)
return NULL;
 }
 
-void qemu_fwcfg_free_files(void)
-{
-   struct fw_file *file;
-   struct list_head *list;
-
-   list_for_each(list, _list) {
-   file = list_entry(list, struct fw_file, list);
-   if (file->addr)
-   free((void *)file->addr);
-   }
-}
-
 struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
 {
iter->entry = fw_list.next;
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 19d0ba0..986f4b2 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -154,7 +154,6 @@ void qemu_fwcfg_init(void);
 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);
-void qemu_fwcfg_free_files(void);
 
 /**
  * Get system cpu number
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 04/13] cmd: qfw: make fwcfg_present and fwcfg_dma_present public

2016-05-22 Thread Miao Yan
This patch is part of the qfw refactor work. This patch makes
qemu_fwcfg_present() and qemu_fwcfg_dma_present() public functions.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 cmd/qemu_fw_cfg.c | 37 -
 include/qemu_fw_cfg.h |  3 +++
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 9f03ab6..aab6b1a 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -62,23 +62,14 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
__asm__ __volatile__ ("pause");
 }
 
-static bool qemu_fwcfg_present(void)
+bool qemu_fwcfg_present(void)
 {
-   uint32_t qemu;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
-   return be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE;
+   return fwcfg_present;
 }
 
-static bool qemu_fwcfg_dma_present(void)
+bool qemu_fwcfg_dma_present(void)
 {
-   uint8_t dma_enabled;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
-   if (dma_enabled & FW_CFG_DMA_ENABLED)
-   return true;
-
-   return false;
+   return fwcfg_dma_present;
 }
 
 void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address)
@@ -257,9 +248,21 @@ static int qemu_fwcfg_list_firmware(void)
 
 void qemu_fwcfg_init(void)
 {
-   fwcfg_present = qemu_fwcfg_present();
-   if (fwcfg_present)
-   fwcfg_dma_present = qemu_fwcfg_dma_present();
+   uint32_t qemu;
+   uint32_t dma_enabled;
+
+   fwcfg_present = false;
+   fwcfg_dma_present = false;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
+   if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
+   fwcfg_present = true;
+
+   if (fwcfg_present) {
+   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
+   if (dma_enabled & FW_CFG_DMA_ENABLED)
+   fwcfg_dma_present = true;
+   }
 }
 
 static int qemu_fwcfg_do_list(cmd_tbl_t *cmdtp, int flag,
@@ -323,7 +326,7 @@ static int do_qemu_fw(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
int ret;
cmd_tbl_t *fwcfg_cmd;
 
-   if (!fwcfg_present) {
+   if (!qemu_fwcfg_present()) {
printf("QEMU fw_cfg interface not found\n");
return CMD_RET_USAGE;
}
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 986f4b2..f718e09 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -167,4 +167,7 @@ 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
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 07/13] x86: qemu: add comment about qfw register endianness

2016-05-22 Thread Miao Yan
This patch adds some comments about qfw register endianness for clarity.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/cpu/qemu/qemu.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 6ff9947..c29add3 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -17,6 +17,7 @@ static bool i440fx;
 
 #ifdef CONFIG_QFW
 
+/* on x86, the qfw registers are all IO ports */
 #define FW_CONTROL_PORT0x510
 #define FW_DATA_PORT   0x511
 #define FW_DMA_PORT_LOW0x514
@@ -31,15 +32,21 @@ static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
/*
 * writting FW_CFG_INVALID will cause read operation to resume at
 * last offset, otherwise read will start at offset 0
+*
+* Note: on platform where the control register is IO port, the
+* endianness is little endian.
 */
if (entry != FW_CFG_INVALID)
-   outw(entry, FW_CONTROL_PORT);
+   outw(cpu_to_le16(entry), FW_CONTROL_PORT);
+
+   /* the endianness of data register is string-preserving */
while (size--)
data[i++] = inb(FW_DATA_PORT);
 }
 
 static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
 {
+   /* the DMA address register is big endian */
outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
 
while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 01/13] x86: qemu: fix ACPI Kconfig options

2016-05-22 Thread Miao Yan
CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
to load ACPI table from QEMU's fw_cfg interface.

But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
our own ACPI implementation", there is only one way to support ACPI table
for QEMU targets which is the fw_cfg interface. Having two Kconfig options
for this purpose is not necessary any more, so this patch consolidates
the two.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 arch/x86/Kconfig   | 10 +-
 arch/x86/cpu/qemu/Makefile |  2 +-
 arch/x86/lib/Makefile  |  2 +-
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ef27dc..3e360ec 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,21 +436,13 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
+   select CMD_QEMU_FW_CFG if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
-config QEMU_ACPI_TABLE
-   bool "Load ACPI table from QEMU fw_cfg interface"
-   depends on GENERATE_ACPI_TABLE && QEMU
-   default y
-   help
- By default, U-Boot generates its own ACPI tables. This option, if
- enabled, disables U-Boot's version and loads ACPI tables generated
- by QEMU.
-
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 97b965c..43ee4bd 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,4 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o qemu.o
-obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index dc90df2..ce5eb82 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y  += string.o
-ifndef CONFIG_QEMU_ACPI_TABLE
+ifndef CONFIG_QEMU
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y  += tables.o
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 02/13] cmd: qfw: add API to iterate firmware list

2016-05-22 Thread Miao Yan
This patch is part of the refactor work of qfw. It adds 3 APIs to qfw
core to iterate firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
 - none

 cmd/qemu_fw_cfg.c | 25 ++---
 include/qemu_fw_cfg.h |  9 +
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 48ae476..192b7d1 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -229,10 +229,27 @@ void qemu_fwcfg_free_files(void)
}
 }
 
+struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = fw_list.next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = iter->entry->next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
+{
+   return iter->entry == _list;
+}
+
 static int qemu_fwcfg_list_firmware(void)
 {
int ret;
-   struct list_head *entry;
+   struct fw_cfg_file_iter iter;
struct fw_file *file;
 
/* make sure fw_list is loaded */
@@ -240,8 +257,10 @@ static int qemu_fwcfg_list_firmware(void)
if (ret)
return ret;
 
-   list_for_each(entry, _list) {
-   file = list_entry(entry, struct fw_file, list);
+
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
printf("%-56s\n", file->cfg.name);
}
 
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index e21f150..19d0ba0 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -87,6 +87,10 @@ struct fw_file {
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;
@@ -159,4 +163,9 @@ void qemu_fwcfg_free_files(void);
  */
 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);
+
 #endif
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 00/13] cleanup QEMU fw_cfg code

2016-05-22 Thread Miao Yan
This patchset cleans the QEMU fw_cfg code:

  *) split qfw core and qfw command interface
  *) split x86 specific operations from qfw core
  *) move x86 ACPI generation code into qfw core as this can also
 be used by others like ARM64
  *) various cleanups

Changes in v2:

  *) make git format-patch detect renames
  *) add a patch to enable qfw for sandbox_defconfig
  *) address other trivial review comments

Changes in v3:
  *) correct config option order in sandbox_defconfig
  *) squash patch v2 #8 and patch v2 #13
  *) fix typos in commit message

Miao Yan (13):
  x86: qemu: fix ACPI Kconfig options
  cmd: qfw: add API to iterate firmware list
  cmd: qfw: remove qemu_fwcfg_free_files()
  cmd: qfw: make fwcfg_present and fwcfg_dma_present public
  x86: qemu: split qfw command interface and qfw core
  x86: qemu: move x86 specific operations out of qfw core
  x86: qemu: add comment about qfw register endianness
  cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]
  cmd: qfw: do not require default macros when building qfw command
  cmd: qfw: do not depend on x86
  cmd: qfw: bring ACPI generation code into qfw core
  x86: qemu: rename qemu/acpi_table.c
  config: sandbox: enable qfw and cmd_qfw for testing

 arch/x86/Kconfig   |  10 +-
 arch/x86/cpu/mp_init.c |   6 +-
 arch/x86/cpu/qemu/Makefile |   4 +-
 arch/x86/cpu/qemu/cpu.c|   2 +-
 arch/x86/cpu/qemu/e820.c   |  43 
 arch/x86/cpu/qemu/qemu.c   |  50 -
 arch/x86/lib/Makefile  |   2 +-
 cmd/Kconfig|   4 +-
 cmd/Makefile   |   2 +-
 cmd/{qemu_fw_cfg.c => qfw.c}   | 189 ++---
 configs/qemu-x86_defconfig |   2 +-
 configs/sandbox_defconfig  |   2 +
 drivers/misc/Kconfig   |   6 +
 drivers/misc/Makefile  |   1 +
 .../cpu/qemu/acpi_table.c => drivers/misc/qfw.c| 223 +
 include/{qemu_fw_cfg.h => qfw.h}   |  28 ++-
 16 files changed, 336 insertions(+), 238 deletions(-)
 create mode 100644 arch/x86/cpu/qemu/e820.c
 rename cmd/{qemu_fw_cfg.c => qfw.c} (54%)
 rename arch/x86/cpu/qemu/acpi_table.c => drivers/misc/qfw.c (57%)
 rename include/{qemu_fw_cfg.h => qfw.h} (84%)

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [v2 PATCH 14/14] config: sandbox: enable qfw and cmd_qfw for testing

2016-05-20 Thread Miao Yan
Hi Bin,

2016-05-20 10:29 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 20, 2016 at 10:06 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Hi Bin,
>>
>> 2016-05-19 17:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> Hi Miao,
>>>
>>> On Wed, May 18, 2016 at 5:40 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>> This patch enables qfw and cmd_qfw on sandbox for build coverage test
>>>>
>>>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>>> ---
>>>>  configs/sandbox_defconfig | 2 ++
>>>>  1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
>>>> index afdf4a3..f19308d 100644
>>>> --- a/configs/sandbox_defconfig
>>>> +++ b/configs/sandbox_defconfig
>>>> @@ -167,3 +167,5 @@ CONFIG_UNIT_TEST=y
>>>>  CONFIG_UT_TIME=y
>>>>  CONFIG_UT_DM=y
>>>>  CONFIG_UT_ENV=y
>>>> +CONFIG_QFW=y
>>>> +CONFIG_CMD_QFW=y
>>>> --
>>>
>>> Please do a 'make savedefconfig' and check the Kconfig options.
>>
>> I did a 'make savedefconfig' and there was a file generated
>> 'defconfig' but with zero content. So what am I supposed to check ?
>> Did you find something wrong with this one ?
>>
>
> We need make sure the option order is correct in a defconfig file.

Can you elaborate on this, what're the rules to add new config in
sandbox_defconfig ? Is is based on the order in kconfig file ?


>
> We can do it like this:
>
> $ make sandbox_defconfig
> $ make savedefconfig
>
> Then check the difference between our updated sandbox_defconfig and
> defconfig files.

And they are supposed to be identical ?

Thanks,
Miao


>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [v2 PATCH 13/14] cmd: qfw: rename QEMU_FW_CFG to CMD_QFW

2016-05-19 Thread Miao Yan
2016-05-20 10:30 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 20, 2016 at 10:07 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Hi Bin,
>>
>> 2016-05-19 17:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> Hi Miao,
>>>
>>> the title should say: CMD_QEMU_FW_CFG
>>>
>>> I can fix this when applying.
>>>
>>> On Wed, May 18, 2016 at 5:39 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>> Align macro names with the rest of qfw code
>>>>
>>>
>>> and I believe it's better to squash this commit into patch#8 in this
>>> series, as they both rename QEMU_FW_CFG to QFW.
>>
>> Thanks. Do I need a v3 ?
>>
>
> If you have time, let's do a v3 which saves my time. Sorry :(

OK, no problem.

Miao

>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [v2 PATCH 13/14] cmd: qfw: rename QEMU_FW_CFG to CMD_QFW

2016-05-19 Thread Miao Yan
Hi Bin,

2016-05-19 17:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> the title should say: CMD_QEMU_FW_CFG
>
> I can fix this when applying.
>
> On Wed, May 18, 2016 at 5:39 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Align macro names with the rest of qfw code
>>
>
> and I believe it's better to squash this commit into patch#8 in this
> series, as they both rename QEMU_FW_CFG to QFW.

Thanks. Do I need a v3 ?


Thanks,
Miao


>
>> Signed-off-by: Miao Yan <yanmiaob...@gmai.com>
>> ---
>>  cmd/Kconfig| 2 +-
>>  cmd/Makefile   | 2 +-
>>  configs/qemu-x86_defconfig | 2 +-
>>  drivers/misc/Kconfig   | 2 +-
>>  4 files changed, 4 insertions(+), 4 deletions(-)
>>
>
> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>
> [snip]
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [v2 PATCH 14/14] config: sandbox: enable qfw and cmd_qfw for testing

2016-05-19 Thread Miao Yan
Hi Bin,

2016-05-19 17:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Wed, May 18, 2016 at 5:40 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> This patch enables qfw and cmd_qfw on sandbox for build coverage test
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  configs/sandbox_defconfig | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
>> index afdf4a3..f19308d 100644
>> --- a/configs/sandbox_defconfig
>> +++ b/configs/sandbox_defconfig
>> @@ -167,3 +167,5 @@ CONFIG_UNIT_TEST=y
>>  CONFIG_UT_TIME=y
>>  CONFIG_UT_DM=y
>>  CONFIG_UT_ENV=y
>> +CONFIG_QFW=y
>> +CONFIG_CMD_QFW=y
>> --
>
> Please do a 'make savedefconfig' and check the Kconfig options.

I did a 'make savedefconfig' and there was a file generated
'defconfig' but with zero content. So what am I supposed to check ?
Did you find something wrong with this one ?

Thanks,
Miao


>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 14/14] config: sandbox: enable qfw and cmd_qfw for testing

2016-05-18 Thread Miao Yan
This patch enables qfw and cmd_qfw on sandbox for build coverage test

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index afdf4a3..f19308d 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -167,3 +167,5 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
+CONFIG_QFW=y
+CONFIG_CMD_QFW=y
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 13/14] cmd: qfw: rename QEMU_FW_CFG to CMD_QFW

2016-05-18 Thread Miao Yan
Align macro names with the rest of qfw code

Signed-off-by: Miao Yan <yanmiaob...@gmai.com>
---
 cmd/Kconfig| 2 +-
 cmd/Makefile   | 2 +-
 configs/qemu-x86_defconfig | 2 +-
 drivers/misc/Kconfig   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 01870cb..d51645c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -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"
select QFW
help
diff --git a/cmd/Makefile b/cmd/Makefile
index 0b7f7a2..1bbd14f 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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
diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig
index a813e5b..45bb3ec 100644
--- a/configs/qemu-x86_defconfig
+++ b/configs/qemu-x86_defconfig
@@ -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
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index fa53700..c40f6b5 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -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
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 11/14] cmd: qfw: bring ACPI generation code into qfw core

2016-05-18 Thread Miao Yan
Loading ACPI table from QEMU's fw_cfg interface is not x86 specific
(ARM64 may also make use of it). So move the code to common place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/qemu/acpi_table.c | 209 -
 drivers/misc/qfw.c | 206 
 2 files changed, 206 insertions(+), 209 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 5bb1756..63853e4 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -5,139 +5,7 @@
  */
 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-
-/*
- * This function allocates memory for ACPI tables
- *
- * @entry : BIOS linker command entry which tells where to allocate memory
- *  (either high memory or low memory)
- * @addr  : The address that should be used for low memory allcation. If the
- *  memory allocation request is 'ZONE_HIGH' then this parameter will
- *  be ignored.
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_allocate(struct bios_linker_entry *entry, u32 *addr)
-{
-   uint32_t size, align;
-   struct fw_file *file;
-   unsigned long aligned_addr;
-
-   align = le32_to_cpu(entry->alloc.align);
-   /* align must be power of 2 */
-   if (align & (align - 1)) {
-   printf("error: wrong alignment %u\n", align);
-   return -EINVAL;
-   }
-
-   file = qemu_fwcfg_find_file(entry->alloc.file);
-   if (!file) {
-   printf("error: can't find file %s\n", entry->alloc.file);
-   return -ENOENT;
-   }
-
-   size = be32_to_cpu(file->cfg.size);
-
-   /*
-* ZONE_HIGH means we need to allocate from high memory, since
-* malloc space is already at the end of RAM, so we directly use it.
-* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
-* in which is low memory
-*/
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
-   aligned_addr = (unsigned long)memalign(align, size);
-   if (!aligned_addr) {
-   printf("error: allocating resource\n");
-   return -ENOMEM;
-   }
-   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
-   aligned_addr = ALIGN(*addr, align);
-   } else {
-   printf("error: invalid allocation zone\n");
-   return -EINVAL;
-   }
-
-   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
- file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
-
-   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
- size, (void *)aligned_addr);
-   file->addr = aligned_addr;
-
-   /* adjust address for low memory allocation */
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
-   *addr = (aligned_addr + size);
-
-   return 0;
-}
-
-/*
- * This function patches ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells how to patch
- *  ACPI tables
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_pointer(struct bios_linker_entry *entry)
-{
-   struct fw_file *dest, *src;
-   uint32_t offset = le32_to_cpu(entry->pointer.offset);
-   uint64_t pointer = 0;
-
-   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
-   if (!dest || !dest->addr)
-   return -ENOENT;
-   src = qemu_fwcfg_find_file(entry->pointer.src_file);
-   if (!src || !src->addr)
-   return -ENOENT;
-
-   debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, 
offset 0x%x size %u, 0x%llx\n",
- dest->addr, src->addr, offset, entry->pointer.size, pointer);
-
-   memcpy(, (char *)dest->addr + offset, entry->pointer.size);
-   pointer = le64_to_cpu(pointer);
-   pointer += (unsigned long)src->addr;
-   pointer = cpu_to_le64(pointer);
-   memcpy((char *)dest->addr + offset, , entry->pointer.size);
-
-   return 0;
-}
-
-/*
- * This function updates checksum fields of ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells where to update ACPI table
- *  checksums
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_checksum(struct bios_linker_entry *entry)
-{
-   struct fw_file *file;
-   uint8_t *data, cksum = 0;
-   uint8_t *cksum_start;
-
-   file = qemu_fwcfg_f

[U-Boot] [v2 PATCH 10/14] cmd: qfw: do not depend on x86

2016-05-18 Thread Miao Yan
The qfw command interface used to depend on X86, this patch removes
this restriction so it can be built for sandbox for testing. For normal
usage, it can only be used with CONFIG_QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 cmd/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 08b761f..01870cb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,7 +595,6 @@ config CMD_SOUND
 
 config CMD_QEMU_FW_CFG
bool "qfw"
-   depends on X86
select QFW
help
  This provides access to the QEMU firmware interface.  The main
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 09/14] cmd: qfw: do not require default macros when building qfw command

2016-05-18 Thread Miao Yan
The qfw command interface makes use of CONFIG_LOADADDR and
CONFIG_RAMDISKADDR to setup kernel. But not all boards have these macro,
which causes build problem on those platforms.

This patch fixes this issue.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v2:
  - fix commit message

 cmd/qfw.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/cmd/qfw.c b/cmd/qfw.c
index c6730bf..12436ec 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -126,12 +126,20 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
env = getenv("loadaddr");
load_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_LOADADDR
(void *)CONFIG_LOADADDR;
+#else
+   NULL;
+#endif
 
env = getenv("ramdiskaddr");
initrd_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_RAMDISK_ADDR
(void *)CONFIG_RAMDISK_ADDR;
+#else
+   NULL;
+#endif
 
if (argc == 2) {
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
@@ -140,6 +148,11 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
}
 
+   if (!load_addr || !initrd_addr) {
+   printf("missing load or initrd address\n");
+   return CMD_RET_FAILURE;
+   }
+
return qemu_fwcfg_setup_kernel(load_addr, initrd_addr);
 }
 
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 07/14] x86: qemu: add comment about qfw register endianness

2016-05-18 Thread Miao Yan
This patch adds some comments about qfw register endianness for clarity.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/qemu/qemu.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 6ff9947..c29add3 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -17,6 +17,7 @@ static bool i440fx;
 
 #ifdef CONFIG_QFW
 
+/* on x86, the qfw registers are all IO ports */
 #define FW_CONTROL_PORT0x510
 #define FW_DATA_PORT   0x511
 #define FW_DMA_PORT_LOW0x514
@@ -31,15 +32,21 @@ static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
/*
 * writting FW_CFG_INVALID will cause read operation to resume at
 * last offset, otherwise read will start at offset 0
+*
+* Note: on platform where the control register is IO port, the
+* endianness is little endian.
 */
if (entry != FW_CFG_INVALID)
-   outw(entry, FW_CONTROL_PORT);
+   outw(cpu_to_le16(entry), FW_CONTROL_PORT);
+
+   /* the endianness of data register is string-preserving */
while (size--)
data[i++] = inb(FW_DATA_PORT);
 }
 
 static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
 {
+   /* the DMA address register is big endian */
outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
 
while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 12/14] x86: qemu: rename qemu/acpi_table.c

2016-05-18 Thread Miao Yan
Rename  qemu/acpi_table.c to qemu/e820.c, because ACPI stuff is moved
to qfw core, this file only contains code for installing e820 table.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/Makefile | 3 +--
 arch/x86/cpu/qemu/{acpi_table.c => e820.c} | 0
 2 files changed, 1 insertion(+), 2 deletions(-)
 rename arch/x86/cpu/qemu/{acpi_table.c => e820.c} (100%)

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 7c08c3d..a080c5e 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,5 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
-obj-$(CONFIG_QFW) += cpu.o
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_QFW) += cpu.o e820.o
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/e820.c
similarity index 100%
rename from arch/x86/cpu/qemu/acpi_table.c
rename to arch/x86/cpu/qemu/e820.c
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 04/14] cmd: qfw: make fwcfg_present and fwcfg_dma_present public

2016-05-18 Thread Miao Yan
This patch is part of the qfw refactor work. This patch makes
qemu_fwcfg_present() and qemu_fwcfg_dma_present() public functions.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 cmd/qemu_fw_cfg.c | 37 -
 include/qemu_fw_cfg.h |  3 +++
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 9f03ab6..aab6b1a 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -62,23 +62,14 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
__asm__ __volatile__ ("pause");
 }
 
-static bool qemu_fwcfg_present(void)
+bool qemu_fwcfg_present(void)
 {
-   uint32_t qemu;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
-   return be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE;
+   return fwcfg_present;
 }
 
-static bool qemu_fwcfg_dma_present(void)
+bool qemu_fwcfg_dma_present(void)
 {
-   uint8_t dma_enabled;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
-   if (dma_enabled & FW_CFG_DMA_ENABLED)
-   return true;
-
-   return false;
+   return fwcfg_dma_present;
 }
 
 void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address)
@@ -257,9 +248,21 @@ static int qemu_fwcfg_list_firmware(void)
 
 void qemu_fwcfg_init(void)
 {
-   fwcfg_present = qemu_fwcfg_present();
-   if (fwcfg_present)
-   fwcfg_dma_present = qemu_fwcfg_dma_present();
+   uint32_t qemu;
+   uint32_t dma_enabled;
+
+   fwcfg_present = false;
+   fwcfg_dma_present = false;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
+   if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
+   fwcfg_present = true;
+
+   if (fwcfg_present) {
+   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
+   if (dma_enabled & FW_CFG_DMA_ENABLED)
+   fwcfg_dma_present = true;
+   }
 }
 
 static int qemu_fwcfg_do_list(cmd_tbl_t *cmdtp, int flag,
@@ -323,7 +326,7 @@ static int do_qemu_fw(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
int ret;
cmd_tbl_t *fwcfg_cmd;
 
-   if (!fwcfg_present) {
+   if (!qemu_fwcfg_present()) {
printf("QEMU fw_cfg interface not found\n");
return CMD_RET_USAGE;
}
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 986f4b2..f718e09 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -167,4 +167,7 @@ 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
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 05/14] x86: qemu: split qfw command interface and qfw core

2016-05-18 Thread Miao Yan
This patch splits qfw command interface and qfw core function into two
files, and introduces a new Kconfig option (CONFIG_QFW). for
qfw core.

Now when qfw command interface is enabled, it will automatically select
qfw core. This patch also makes the ACPI table generation select
CONFIG_QFW.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v2:
  - do not use #ifdef...#end when including header files
  - cleanup blank line at the end of file
  - rename cmd_qfw.c to qfw.c
 
 arch/x86/Kconfig |   2 +-
 arch/x86/cpu/mp_init.c   |   4 +-
 arch/x86/cpu/qemu/Makefile   |   3 +-
 arch/x86/cpu/qemu/qemu.c |   2 +
 cmd/Kconfig  |   1 +
 cmd/Makefile |   2 +-
 cmd/{qemu_fw_cfg.c => qfw.c} | 172 
 drivers/misc/Kconfig |   6 ++
 drivers/misc/Makefile|   1 +
 drivers/misc/qemu_fw_cfg.c   | 184 +++
 10 files changed, 200 insertions(+), 177 deletions(-)
 rename cmd/{qemu_fw_cfg.c => qfw.c} (55%)
 create mode 100644 drivers/misc/qemu_fw_cfg.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 3e360ec..2f63170 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,7 +436,7 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
-   select CMD_QEMU_FW_CFG if QEMU
+   select QFW if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 13bec7a..c44a286 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -420,7 +420,7 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
 static int qemu_cpu_fixup(void)
 {
int ret;
@@ -496,7 +496,7 @@ int mp_init(struct mp_params *p)
if (ret)
return ret;
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
ret = qemu_cpu_fixup();
if (ret)
return ret;
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 43ee4bd..7c08c3d 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,6 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += cpu.o qemu.o
+obj-y += qemu.o
+obj-$(CONFIG_QFW) += cpu.o
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index b41e4ec..32a4351 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -88,7 +88,9 @@ static void qemu_chipset_init(void)
enable_pm_ich9();
}
 
+#ifdef CONFIG_QFW
qemu_fwcfg_init();
+#endif
 }
 
 int arch_cpu_init(void)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c0fffe3..08b761f 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -596,6 +596,7 @@ config CMD_SOUND
 config CMD_QEMU_FW_CFG
bool "qfw"
depends on X86
+   select QFW
help
  This provides access to the QEMU firmware interface.  The main
  feature is to allow easy loading of files passed to qemu-system
diff --git a/cmd/Makefile b/cmd/Makefile
index f99e67d..0b7f7a2 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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) += qemu_fw_cfg.o
+obj-$(CONFIG_CMD_QEMU_FW_CFG) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
diff --git a/cmd/qemu_fw_cfg.c b/cmd/qfw.c
similarity index 55%
rename from cmd/qemu_fw_cfg.c
rename to cmd/qfw.c
index aab6b1a..37f1aa6 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qfw.c
@@ -7,90 +7,7 @@
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
-#include 
-
-static bool fwcfg_present;
-static bool fwcfg_dma_present;
-
-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)
-{
-   uint32_t i = 0;
-   uint8_t *data = address;
-
-   /*
-* 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)
-   outw(entry, FW_CONTROL_PORT);
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
-}
-
-/* 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);
-
-   /*
- 

[U-Boot] [v2 PATCH 08/14] cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]

2016-05-18 Thread Miao Yan
Make file names aligned with CONFIG_QFW

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/mp_init.c| 2 +-
 arch/x86/cpu/qemu/acpi_table.c| 2 +-
 arch/x86/cpu/qemu/cpu.c   | 2 +-
 arch/x86/cpu/qemu/qemu.c  | 2 +-
 cmd/qfw.c | 2 +-
 drivers/misc/Makefile | 2 +-
 drivers/misc/{qemu_fw_cfg.c => qfw.c} | 2 +-
 include/{qemu_fw_cfg.h => qfw.h}  | 0
 8 files changed, 7 insertions(+), 7 deletions(-)
 rename drivers/misc/{qemu_fw_cfg.c => qfw.c} (99%)
 rename include/{qemu_fw_cfg.h => qfw.h} (100%)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index c44a286..8207274 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index b17fa03..5bb1756 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c
index 4d2989a..b1a965e 100644
--- a/arch/x86/cpu/qemu/cpu.c
+++ b/arch/x86/cpu/qemu/cpu.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index c29add3..680e558 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -6,7 +6,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/qfw.c b/cmd/qfw.c
index 37f1aa6..c6730bf 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * This function prepares kernel for zboot. It loads kernel data
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 4893086..98704f2 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -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/qfw.c
similarity index 99%
rename from drivers/misc/qemu_fw_cfg.c
rename to drivers/misc/qfw.c
index 0f72549..59d9376 100644
--- a/drivers/misc/qemu_fw_cfg.c
+++ b/drivers/misc/qfw.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/include/qemu_fw_cfg.h b/include/qfw.h
similarity index 100%
rename from include/qemu_fw_cfg.h
rename to include/qfw.h
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 06/14] x86: qemu: move x86 specific operations out of qfw core

2016-05-18 Thread Miao Yan
The original implementation of qfw includes several x86 specific
operations, like directly calling outb/inb and using some inline
assembly code which prevents it being ported to other architectures.

This patch adds callback functions and moves those to arch/x86/

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/qemu/qemu.c   | 39 ++-
 drivers/misc/qemu_fw_cfg.c | 30 +-
 include/qemu_fw_cfg.h  | 15 +--
 3 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 32a4351..6ff9947 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,6 +15,43 @@
 
 static bool i440fx;
 
+#ifdef CONFIG_QFW
+
+#define FW_CONTROL_PORT0x510
+#define FW_DATA_PORT   0x511
+#define FW_DMA_PORT_LOW0x514
+#define FW_DMA_PORT_HIGH   0x518
+
+static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
+   uint32_t size, void *address)
+{
+   uint32_t i = 0;
+   uint8_t *data = address;
+
+   /*
+* 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)
+   outw(entry, FW_CONTROL_PORT);
+   while (size--)
+   data[i++] = inb(FW_DATA_PORT);
+}
+
+static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
+{
+   outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
+
+   while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
+   __asm__ __volatile__ ("pause");
+}
+
+static struct fw_cfg_arch_ops fwcfg_x86_ops = {
+   .arch_read_pio = qemu_x86_fwcfg_read_entry_pio,
+   .arch_read_dma = qemu_x86_fwcfg_read_entry_dma
+};
+#endif
+
 static void enable_pm_piix(void)
 {
u8 en;
@@ -89,7 +126,7 @@ static void qemu_chipset_init(void)
}
 
 #ifdef CONFIG_QFW
-   qemu_fwcfg_init();
+   qemu_fwcfg_init(_x86_ops);
 #endif
 }
 
diff --git a/drivers/misc/qemu_fw_cfg.c b/drivers/misc/qemu_fw_cfg.c
index a574bd1..0f72549 100644
--- a/drivers/misc/qemu_fw_cfg.c
+++ b/drivers/misc/qemu_fw_cfg.c
@@ -14,6 +14,7 @@
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
+static struct fw_cfg_arch_ops *fwcfg_arch_ops;
 
 static LIST_HEAD(fw_list);
 
@@ -21,17 +22,10 @@ static LIST_HEAD(fw_list);
 static void qemu_fwcfg_read_entry_pio(uint16_t entry,
uint32_t size, void *address)
 {
-   uint32_t i = 0;
-   uint8_t *data = address;
+   debug("qemu_fwcfg_read_entry_pio: entry 0x%x, size %u address %p\n",
+ entry, size, address);
 
-   /*
-* 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)
-   outw(entry, FW_CONTROL_PORT);
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
+   return fwcfg_arch_ops->arch_read_pio(entry, size, address);
 }
 
 /* Read configuration item using fw_cfg DMA interface */
@@ -53,13 +47,10 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
 
barrier();
 
-   debug("qemu_fwcfg_dma_read_entry: addr %p, length %u control 0x%x\n",
- address, size, be32_to_cpu(dma.control));
-
-   outl(cpu_to_be32((uint32_t)), FW_DMA_PORT_HIGH);
+   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));
 
-   while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_ERROR)
-   __asm__ __volatile__ ("pause");
+   fwcfg_arch_ops->arch_read_dma();
 }
 
 bool qemu_fwcfg_present(void)
@@ -164,13 +155,18 @@ bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter 
*iter)
return iter->entry == _list;
 }
 
-void qemu_fwcfg_init(void)
+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, );
if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index f718e09..b0b3b59 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -7,11 +7,6 @@
 #ifndef __FW_CFG__
 #define __FW_CFG__
 
-#define FW_CONTROL_PORT0x510
-#define FW_DATA_PORT   0x511
-#define FW_DMA_PORT_LOW0x514
-#define FW_DMA_PORT_HIGH   0x518
-
 #include 
 
 enum qemu_fwcfg_items {
@@ -97,6 +92,12 @@ struct fw_cfg_dma_access {
__be64 address;
 };
 

[U-Boot] [v2 PATCH 03/14] cmd: qfw: remove qemu_fwcfg_free_files()

2016-05-18 Thread Miao Yan
This patch is part of the qfw refactor work.

The qemu_fwcfg_free_files() function is only used in error handling in
ACPI table generation, let's not make this a core function and move it
to the right place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/acpi_table.c | 13 +++--
 cmd/qemu_fw_cfg.c  | 12 
 include/qemu_fw_cfg.h  |  1 -
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 49381ac..b17fa03 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -235,8 +235,17 @@ u32 write_acpi_tables(u32 addr)
}
 
 out:
-   if (ret)
-   qemu_fwcfg_free_files();
+   if (ret) {
+   struct fw_cfg_file_iter iter;
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
+   if (file->addr) {
+   free((void *)file->addr);
+   file->addr = 0;
+   }
+   }
+   }
 
free(table_loader);
return addr;
diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 192b7d1..9f03ab6 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -217,18 +217,6 @@ struct fw_file *qemu_fwcfg_find_file(const char *name)
return NULL;
 }
 
-void qemu_fwcfg_free_files(void)
-{
-   struct fw_file *file;
-   struct list_head *list;
-
-   list_for_each(list, _list) {
-   file = list_entry(list, struct fw_file, list);
-   if (file->addr)
-   free((void *)file->addr);
-   }
-}
-
 struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
 {
iter->entry = fw_list.next;
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 19d0ba0..986f4b2 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -154,7 +154,6 @@ void qemu_fwcfg_init(void);
 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);
-void qemu_fwcfg_free_files(void);
 
 /**
  * Get system cpu number
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 02/14] cmd: qfw: add API to iterate firmware list

2016-05-18 Thread Miao Yan
This patch is part of the refactor work of qfw. It adds 3 APIs to qfw
core to iterate firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 cmd/qemu_fw_cfg.c | 25 ++---
 include/qemu_fw_cfg.h |  9 +
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 48ae476..192b7d1 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -229,10 +229,27 @@ void qemu_fwcfg_free_files(void)
}
 }
 
+struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = fw_list.next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = iter->entry->next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
+{
+   return iter->entry == _list;
+}
+
 static int qemu_fwcfg_list_firmware(void)
 {
int ret;
-   struct list_head *entry;
+   struct fw_cfg_file_iter iter;
struct fw_file *file;
 
/* make sure fw_list is loaded */
@@ -240,8 +257,10 @@ static int qemu_fwcfg_list_firmware(void)
if (ret)
return ret;
 
-   list_for_each(entry, _list) {
-   file = list_entry(entry, struct fw_file, list);
+
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
printf("%-56s\n", file->cfg.name);
}
 
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index e21f150..19d0ba0 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -87,6 +87,10 @@ struct fw_file {
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;
@@ -159,4 +163,9 @@ void qemu_fwcfg_free_files(void);
  */
 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);
+
 #endif
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 00/14] cleanup QEMU fw_cfg code

2016-05-18 Thread Miao Yan
This patchset cleans the QEMU fw_cfg code:

  *) split qfw core and qfw command interface
  *) split x86 specific operations from qfw core
  *) move x86 ACPI generation code into qfw core as this can also
 be used by others like ARM64
  *) various cleanups

Changes in v2:

  *) make git format-patch detect renames
  *) add a patch to enable qfw for sandbox_defconfig
  *) address other trivial review comments

Miao Yan (14):
  x86: qemu: fix ACPI Kconfig options
  cmd: qfw: add API to iterate firmware list
  cmd: qfw: remove qemu_fwcfg_free_files()
  cmd: qfw: make fwcfg_present and fwcfg_dma_present public
  x86: qemu: split qfw command interface and qfw core
  x86: qemu: move x86 specific operations out of qfw core
  x86: qemu: add comment about qfw register endianness
  cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]
  cmd: qfw: do not require default macros when building qfw command
  cmd: qfw: do not depend on x86
  cmd: qfw: bring ACPI generation code into qfw core
  x86: qemu: rename qemu/acpi_table.c
  cmd: qfw: rename QEMU_FW_CFG to CMD_QFW
  config: sandbox: enable qfw and cmd_qfw for testing

 arch/x86/Kconfig   |  10 +-
 arch/x86/cpu/mp_init.c |   6 +-
 arch/x86/cpu/qemu/Makefile |   4 +-
 arch/x86/cpu/qemu/cpu.c|   2 +-
 arch/x86/cpu/qemu/e820.c   |  43 
 arch/x86/cpu/qemu/qemu.c   |  50 -
 arch/x86/lib/Makefile  |   2 +-
 cmd/Kconfig|   4 +-
 cmd/Makefile   |   2 +-
 cmd/{qemu_fw_cfg.c => qfw.c}   | 189 ++---
 configs/qemu-x86_defconfig |   2 +-
 configs/sandbox_defconfig  |   2 +
 drivers/misc/Kconfig   |   6 +
 drivers/misc/Makefile  |   1 +
 .../cpu/qemu/acpi_table.c => drivers/misc/qfw.c| 223 +
 include/{qemu_fw_cfg.h => qfw.h}   |  28 ++-
 16 files changed, 336 insertions(+), 238 deletions(-)
 create mode 100644 arch/x86/cpu/qemu/e820.c
 rename cmd/{qemu_fw_cfg.c => qfw.c} (54%)
 rename arch/x86/cpu/qemu/acpi_table.c => drivers/misc/qfw.c (57%)
 rename include/{qemu_fw_cfg.h => qfw.h} (84%)

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [v2 PATCH 01/14] x86: qemu: fix ACPI Kconfig options

2016-05-18 Thread Miao Yan
CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
to load ACPI table from QEMU's fw_cfg interface.

But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
our own ACPI implementation", there is only one way to support ACPI table
for QEMU targets which is the fw_cfg interface. Having two Kconfig options
for this purpose is not necessary any more, so this patch consolidates
the two.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v2:
  - fix a wrong macro name

 arch/x86/Kconfig   | 10 +-
 arch/x86/cpu/qemu/Makefile |  2 +-
 arch/x86/lib/Makefile  |  2 +-
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ef27dc..3e360ec 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,21 +436,13 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
+   select CMD_QEMU_FW_CFG if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
-config QEMU_ACPI_TABLE
-   bool "Load ACPI table from QEMU fw_cfg interface"
-   depends on GENERATE_ACPI_TABLE && QEMU
-   default y
-   help
- By default, U-Boot generates its own ACPI tables. This option, if
- enabled, disables U-Boot's version and loads ACPI tables generated
- by QEMU.
-
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 97b965c..43ee4bd 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,4 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o qemu.o
-obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index dc90df2..ce5eb82 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y  += string.o
-ifndef CONFIG_QEMU_ACPI_TABLE
+ifndef CONFIG_QEMU
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y  += tables.o
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 12/12] x86: qemu: rename qemu/acpi_table.c

2016-05-16 Thread Miao Yan
2016-05-17 8:42 GMT+08:00 Tom Rini <tr...@konsulko.com>:
> On Mon, May 16, 2016 at 05:40:16PM +0800, Miao Yan wrote:
>> Hi Bin,
>>
>> 2016-05-13 22:01 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>> > Hi Miao,
>> >
>> > On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> >> Rename  qemu/acpi_table.c to qemu/e820.c, because ACPI stuff is moved
>> >> to qfw core, this file only contains code for installing e820 table.
>> >>
>> >> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> >> ---
>> >>  arch/x86/cpu/qemu/Makefile |  3 +--
>> >>  arch/x86/cpu/qemu/acpi_table.c | 43 
>> >> --
>> >>  arch/x86/cpu/qemu/e820.c   | 43 
>> >> ++
>> >
>> > Please use "git mv".
>>
>> I did use "git mv". I'll double check.
>
> I believe you need to tell git to work harder to detect renames.  You'll
> have to do git format-patch --find-copies-harder ... and git send-email
> ... rather than just using send-email by itself (or, there's a knob
> somewhere I've missed that lets you tweak the rename threshold via the
> config file).

Thanks Tom,  I'll try that.

Miao

>
> --
> Tom
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 05/12] x86: qemu: split qfw command interface and qfw core

2016-05-16 Thread Miao Yan
Hi Bin,

2016-05-16 16:47 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> This patch splits qfw command interface and qfw core function into two
>> files, and introduces a new Kconfig option (CONFIG_QFW). for
>> qfw core.
>>
>> Now when qfw command interface is enabled, it will automatically select
>> qfw core. This patch also makes the ACPI table generation select
>> CONFIG_QFW.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/Kconfig   |   2 +-
>>  arch/x86/cpu/mp_init.c |   6 +-
>>  arch/x86/cpu/qemu/Makefile |   3 +-
>>  arch/x86/cpu/qemu/acpi_table.c |   2 +
>>  arch/x86/cpu/qemu/qemu.c   |   4 +
>>  cmd/Kconfig|   1 +
>>  cmd/Makefile   |   2 +-
>>  cmd/cmd_qfw.c  | 182 +
>
> The file name should be qfw.c without cmd_
>
>>  cmd/qemu_fw_cfg.c  | 353 
>> -
>
> And I suspect you can also use "git mv" for cmd/qemu_fw_cfg.c. "git mv
> cmd/qemu_fw_cfg.c cmd/qfw.c"

But there is already a qfw.c under driver/misc/, having two files
using the same name seems a bit confusing.

Thanks,
Miao

>
>>  common/Kconfig |   1 +
>>  drivers/misc/Kconfig   |   6 +
>>  drivers/misc/Makefile  |   1 +
>>  drivers/misc/qemu_fw_cfg.c | 185 +
>>  13 files changed, 390 insertions(+), 358 deletions(-)
>>  create mode 100644 cmd/cmd_qfw.c
>>  delete mode 100644 cmd/qemu_fw_cfg.c
>>  create mode 100644 drivers/misc/qemu_fw_cfg.c
>>
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 03/12] cmd: qfw: remove qemu_fwcfg_free_files()

2016-05-16 Thread Miao Yan
2016-05-14 4:46 GMT+08:00 Tom Rini <tr...@konsulko.com>:
> On Fri, May 13, 2016 at 10:00:05PM +0800, Bin Meng wrote:
>> Hi Miao,
>>
>> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> > This patch is part of the qfw refactor work.
>> >
>> > The qemu_fwcfg_free_files() function is only used in error handling in
>> > ACPI table generation, let's not make this a core function and move it
>> > to the right place.
>> >
>>
>> But I suspect this API may still be needed in some other scenarioes?
>> eg: for future ARM64 ACPI?
>
> Yes, as it stands currently the code looks likely useful for non-x86
> QEMU+ACPI.

ARM64 and x86 should be able to share common ACPI code. As for now,
this function is not used anywhere but error handling in only one
place. I'd prefer not to make this public.

Thanks,
Miao


>
> --
> Tom
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 09/12] cmd: qfw: workaround qfw build issue

2016-05-16 Thread Miao Yan
2016-05-14 4:46 GMT+08:00 Tom Rini <tr...@konsulko.com>:
> On Fri, May 13, 2016 at 10:00:37PM +0800, Bin Meng wrote:
>> Hi Miao,
>>
>> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> > The qfw command interface makes use of CONFIG_LOADADDR and
>> > CONFIG_RAMDISKADDR to setup kernel. But not all boards have these macro,
>> > which causes build problem on those platforms.
>> >
>> > This patch fixes this issue.
>> >
>> > Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>
>> Looks good.
>>
>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>>
>> But the commit title "workaround" looks to be a workaround, which does
>> not sound that good.
>
> Yes, maybe just say that it's no longer requiring default values?

OK. Will fix.

Thanks,
Miao


>
> --
> Tom
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 10/12] cmd: qfw: do not depend on x86

2016-05-16 Thread Miao Yan
Hi Bin,

2016-05-13 22:00 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> The qfw command interface used to depend on X86, this patch removes
>> this restriction so it can be built for sandbox for testing. For normal
>> usage, it can only be used with CONFIG_QEMU.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>
> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>
> Would you prepare a patch to enable this on Sandbox?

I'll give it a try. Do you prefer to do that in this patch-set or submit later ?

Miao

>
>>  cmd/Kconfig | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/cmd/Kconfig b/cmd/Kconfig
>> index 08b761f..01870cb 100644
>> --- a/cmd/Kconfig
>> +++ b/cmd/Kconfig
>> @@ -595,7 +595,6 @@ config CMD_SOUND
>>
>>  config CMD_QEMU_FW_CFG
>> bool "qfw"
>> -   depends on X86
>> select QFW
>> help
>>   This provides access to the QEMU firmware interface.  The main
>> --
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 12/12] x86: qemu: rename qemu/acpi_table.c

2016-05-16 Thread Miao Yan
Hi Bin,

2016-05-13 22:01 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Rename  qemu/acpi_table.c to qemu/e820.c, because ACPI stuff is moved
>> to qfw core, this file only contains code for installing e820 table.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/cpu/qemu/Makefile |  3 +--
>>  arch/x86/cpu/qemu/acpi_table.c | 43 
>> --
>>  arch/x86/cpu/qemu/e820.c   | 43 
>> ++
>
> Please use "git mv".

I did use "git mv". I'll double check.

Miao


>
>>  3 files changed, 44 insertions(+), 45 deletions(-)
>>  delete mode 100644 arch/x86/cpu/qemu/acpi_table.c
>>  create mode 100644 arch/x86/cpu/qemu/e820.c
>>
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 05/12] x86: qemu: split qfw command interface and qfw core

2016-05-16 Thread Miao Yan
Hi Bin,

2016-05-13 22:00 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> This patch splits qfw command interface and qfw core function into two
>> files, and introduces a new Kconfig option (CONFIG_QFW). for
>> qfw core.
>>
>> Now when qfw command interface is enabled, it will automatically select
>> qfw core. This patch also makes the ACPI table generation select
>> CONFIG_QFW.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/Kconfig   |   2 +-
>>  arch/x86/cpu/mp_init.c |   6 +-
>>  arch/x86/cpu/qemu/Makefile |   3 +-
>>  arch/x86/cpu/qemu/acpi_table.c |   2 +
>>  arch/x86/cpu/qemu/qemu.c   |   4 +
>>  cmd/Kconfig|   1 +
>>  cmd/Makefile   |   2 +-
>>  cmd/cmd_qfw.c  | 182 +
>>  cmd/qemu_fw_cfg.c  | 353 
>> -
>>  common/Kconfig |   1 +
>>  drivers/misc/Kconfig   |   6 +
>>  drivers/misc/Makefile  |   1 +
>>  drivers/misc/qemu_fw_cfg.c | 185 +
>>  13 files changed, 390 insertions(+), 358 deletions(-)
>>  create mode 100644 cmd/cmd_qfw.c
>>  delete mode 100644 cmd/qemu_fw_cfg.c
>>  create mode 100644 drivers/misc/qemu_fw_cfg.c
>>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index a60e0da..2f63170 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -436,7 +436,7 @@ config GENERATE_MP_TABLE
>>  config GENERATE_ACPI_TABLE
>> bool "Generate an ACPI (Advanced Configuration and Power Interface) 
>> table"
>> default n
>> -   select QEMU_FW_CFG if QEMU
>> +   select QFW if QEMU
>> help
>>   The Advanced Configuration and Power Interface (ACPI) specification
>>   provides an open standard for device configuration and management
>> diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
>> index 13bec7a..109b3d7 100644
>> --- a/arch/x86/cpu/mp_init.c
>> +++ b/arch/x86/cpu/mp_init.c
>> @@ -11,7 +11,9 @@
>>  #include 
>>  #include 
>>  #include 
>> +#ifdef CONFIG_QFW
>>  #include 
>> +#endif
>
> There is no need to wrap header file with #ifdef.

OK. And will fix the reset of them.


>
>>  #include 
>>  #include 
>>  #include 
>> @@ -420,7 +422,7 @@ static int init_bsp(struct udevice **devp)
>> return 0;
>>  }
>>
>> -#ifdef CONFIG_QEMU
>> +#ifdef CONFIG_QFW
>>  static int qemu_cpu_fixup(void)
>>  {
>> int ret;
>> @@ -496,7 +498,7 @@ int mp_init(struct mp_params *p)
>> if (ret)
>> return ret;
>>
>> -#ifdef CONFIG_QEMU
>> +#ifdef CONFIG_QFW
>> ret = qemu_cpu_fixup();
>> if (ret)
>> return ret;
>> diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
>> index 43ee4bd..7c08c3d 100644
>> --- a/arch/x86/cpu/qemu/Makefile
>> +++ b/arch/x86/cpu/qemu/Makefile
>> @@ -7,5 +7,6 @@
>>  ifndef CONFIG_EFI_STUB
>>  obj-y += car.o dram.o
>>  endif
>> -obj-y += cpu.o qemu.o
>> +obj-y += qemu.o
>> +obj-$(CONFIG_QFW) += cpu.o
>>  obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
>> diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
>> index b17fa03..4584fc7 100644
>> --- a/arch/x86/cpu/qemu/acpi_table.c
>> +++ b/arch/x86/cpu/qemu/acpi_table.c
>> @@ -8,7 +8,9 @@
>>  #include 
>>  #include 
>>  #include 
>> +#ifdef CONFIG_QFW
>>  #include 
>> +#endif
>
> ditto.
>
>>  #include 
>>  #include 
>>  #include 
>> diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
>> index b41e4ec..2631e99 100644
>> --- a/arch/x86/cpu/qemu/qemu.c
>> +++ b/arch/x86/cpu/qemu/qemu.c
>> @@ -6,7 +6,9 @@
>>
>>  #include 
>>  #include 
>> +#ifdef CONFIG_QFW
>>  #include 
>> +#endif
>
> ditto.
>
>>  #include 
>>  #include 
>>  #include 
>> @@ -88,7 +90,9 @@ static void qemu_chipset_init(void)
>> enable_pm_ich9();
>> }
>>
>> +#ifdef CONFIG_QFW
>> qemu_fwcfg_init();
>> +#endif
>>  }
>>
>>  int arch_cpu_init(void)
>> diff --git a/cmd/Kconfig b/cmd/Kconfig
>> index c0fffe3..08b761f 100644
>> --- a/cmd/Kconf

Re: [U-Boot] [PATCH 01/12] x86: qemu: fix ACPI Kconfig options

2016-05-16 Thread Miao Yan
Hi Bin,

2016-05-13 21:59 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, May 13, 2016 at 2:29 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
>> uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
>> to load ACPI table from QEMU's fw_cfg interface.
>>
>> But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
>> our own ACPI implementation", there is only one way to support ACPI table
>> for QEMU targets which is the fw_cfg interface. Having two Kconfig options
>> for this purpose is not necessary any more, so this patch consolidates
>> the two.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/Kconfig   | 10 +-
>>  arch/x86/cpu/qemu/Makefile |  2 +-
>>  arch/x86/lib/Makefile  |  2 +-
>>  3 files changed, 3 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index 4ef27dc..a60e0da 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -436,21 +436,13 @@ config GENERATE_MP_TABLE
>>  config GENERATE_ACPI_TABLE
>> bool "Generate an ACPI (Advanced Configuration and Power Interface) 
>> table"
>> default n
>> +   select QEMU_FW_CFG if QEMU
>
> I think this should be CMD_QEMU_FW_CFG

Yes, will fix this. Thanks.

Miao


>
>> help
>>   The Advanced Configuration and Power Interface (ACPI) specification
>>   provides an open standard for device configuration and management
>>   by the operating system. It defines platform-independent interfaces
>>   for configuration and power management monitoring.
>>
>> -config QEMU_ACPI_TABLE
>> -   bool "Load ACPI table from QEMU fw_cfg interface"
>> -   depends on GENERATE_ACPI_TABLE && QEMU
>> -   default y
>> -   help
>> - By default, U-Boot generates its own ACPI tables. This option, if
>> - enabled, disables U-Boot's version and loads ACPI tables generated
>> - by QEMU.
>> -
>>  config GENERATE_SMBIOS_TABLE
>> bool "Generate an SMBIOS (System Management BIOS) table"
>> default y
>> diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
>> index 97b965c..43ee4bd 100644
>> --- a/arch/x86/cpu/qemu/Makefile
>> +++ b/arch/x86/cpu/qemu/Makefile
>> @@ -8,4 +8,4 @@ ifndef CONFIG_EFI_STUB
>>  obj-y += car.o dram.o
>>  endif
>>  obj-y += cpu.o qemu.o
>> -obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
>> +obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
>> diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
>> index dc90df2..ce5eb82 100644
>> --- a/arch/x86/lib/Makefile
>> +++ b/arch/x86/lib/Makefile
>> @@ -31,7 +31,7 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
>>  obj-y += sfi.o
>>  obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
>>  obj-y  += string.o
>> -ifndef CONFIG_QEMU_ACPI_TABLE
>> +ifndef CONFIG_QEMU
>>  obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
>>  endif
>>  obj-y  += tables.o
>> --
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 08/12] cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]

2016-05-13 Thread Miao Yan
Make file names aligned with CONFIG_QFW

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/mp_init.c |   2 +-
 arch/x86/cpu/qemu/acpi_table.c |   2 +-
 arch/x86/cpu/qemu/cpu.c|   2 +-
 arch/x86/cpu/qemu/qemu.c   |   2 +-
 cmd/cmd_qfw.c  |   2 +-
 drivers/misc/Makefile  |   2 +-
 drivers/misc/qemu_fw_cfg.c | 181 -
 drivers/misc/qfw.c | 181 +
 include/qemu_fw_cfg.h  | 176 ---
 include/qfw.h  | 176 +++
 10 files changed, 363 insertions(+), 363 deletions(-)
 delete mode 100644 drivers/misc/qemu_fw_cfg.c
 create mode 100644 drivers/misc/qfw.c
 delete mode 100644 include/qemu_fw_cfg.h
 create mode 100644 include/qfw.h

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 109b3d7..54285fa 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 #ifdef CONFIG_QFW
-#include 
+#include 
 #endif
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 4584fc7..0c54b80 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 #ifdef CONFIG_QFW
-#include 
+#include 
 #endif
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c
index 4d2989a..b1a965e 100644
--- a/arch/x86/cpu/qemu/cpu.c
+++ b/arch/x86/cpu/qemu/cpu.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 716a0ac..35cd107 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #ifdef CONFIG_QFW
-#include 
+#include 
 #endif
 #include 
 #include 
diff --git a/cmd/cmd_qfw.c b/cmd/cmd_qfw.c
index eefaf65..aeb576b 100644
--- a/cmd/cmd_qfw.c
+++ b/cmd/cmd_qfw.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * This function prepares kernel for zboot. It loads kernel data
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 4893086..98704f2 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -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
index 0700641..000
--- a/drivers/misc/qemu_fw_cfg.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-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();
-}
-
-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, _cpus);
-
- 

[U-Boot] [PATCH 12/12] x86: qemu: rename qemu/acpi_table.c

2016-05-13 Thread Miao Yan
Rename  qemu/acpi_table.c to qemu/e820.c, because ACPI stuff is moved
to qfw core, this file only contains code for installing e820 table.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/Makefile |  3 +--
 arch/x86/cpu/qemu/acpi_table.c | 43 --
 arch/x86/cpu/qemu/e820.c   | 43 ++
 3 files changed, 44 insertions(+), 45 deletions(-)
 delete mode 100644 arch/x86/cpu/qemu/acpi_table.c
 create mode 100644 arch/x86/cpu/qemu/e820.c

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 7c08c3d..a080c5e 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,5 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
-obj-$(CONFIG_QFW) += cpu.o
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_QFW) += cpu.o e820.o
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
deleted file mode 100644
index 63853e4..000
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#include 
-#include 
-
-unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
-{
-   entries[0].addr = 0;
-   entries[0].size = ISA_START_ADDRESS;
-   entries[0].type = E820_RAM;
-
-   entries[1].addr = ISA_START_ADDRESS;
-   entries[1].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
-   entries[1].type = E820_RESERVED;
-
-   /*
-* since we use memalign(malloc) to allocate high memory for
-* storing ACPI tables, we need to reserve them in e820 tables,
-* otherwise kernel will reclaim them and data will be corrupted
-*/
-   entries[2].addr = ISA_END_ADDRESS;
-   entries[2].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS;
-   entries[2].type = E820_RAM;
-
-   /* for simplicity, reserve entire malloc space */
-   entries[3].addr = gd->relocaddr - TOTAL_MALLOC_LEN;
-   entries[3].size = TOTAL_MALLOC_LEN;
-   entries[3].type = E820_RESERVED;
-
-   entries[4].addr = gd->relocaddr;
-   entries[4].size = gd->ram_size - gd->relocaddr;
-   entries[4].type = E820_RESERVED;
-
-   entries[5].addr = CONFIG_PCIE_ECAM_BASE;
-   entries[5].size = CONFIG_PCIE_ECAM_SIZE;
-   entries[5].type = E820_RESERVED;
-
-   return 6;
-}
diff --git a/arch/x86/cpu/qemu/e820.c b/arch/x86/cpu/qemu/e820.c
new file mode 100644
index 000..63853e4
--- /dev/null
+++ b/arch/x86/cpu/qemu/e820.c
@@ -0,0 +1,43 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+
+unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
+{
+   entries[0].addr = 0;
+   entries[0].size = ISA_START_ADDRESS;
+   entries[0].type = E820_RAM;
+
+   entries[1].addr = ISA_START_ADDRESS;
+   entries[1].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
+   entries[1].type = E820_RESERVED;
+
+   /*
+* since we use memalign(malloc) to allocate high memory for
+* storing ACPI tables, we need to reserve them in e820 tables,
+* otherwise kernel will reclaim them and data will be corrupted
+*/
+   entries[2].addr = ISA_END_ADDRESS;
+   entries[2].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS;
+   entries[2].type = E820_RAM;
+
+   /* for simplicity, reserve entire malloc space */
+   entries[3].addr = gd->relocaddr - TOTAL_MALLOC_LEN;
+   entries[3].size = TOTAL_MALLOC_LEN;
+   entries[3].type = E820_RESERVED;
+
+   entries[4].addr = gd->relocaddr;
+   entries[4].size = gd->ram_size - gd->relocaddr;
+   entries[4].type = E820_RESERVED;
+
+   entries[5].addr = CONFIG_PCIE_ECAM_BASE;
+   entries[5].size = CONFIG_PCIE_ECAM_SIZE;
+   entries[5].type = E820_RESERVED;
+
+   return 6;
+}
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 11/12] cmd: qfw: bring ACPI generation code into qfw core

2016-05-13 Thread Miao Yan
Loading ACPI table from QEMU's fw_cfg interface is not x86 specific
(ARM64 may also make user of it). So move the code common place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/acpi_table.c | 211 -
 drivers/misc/qfw.c | 206 
 2 files changed, 206 insertions(+), 211 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 0c54b80..63853e4 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -5,141 +5,7 @@
  */
 
 #include 
-#include 
-#include 
-#include 
-#ifdef CONFIG_QFW
-#include 
-#endif
-#include 
-#include 
 #include 
-#include 
-#include 
-
-/*
- * This function allocates memory for ACPI tables
- *
- * @entry : BIOS linker command entry which tells where to allocate memory
- *  (either high memory or low memory)
- * @addr  : The address that should be used for low memory allcation. If the
- *  memory allocation request is 'ZONE_HIGH' then this parameter will
- *  be ignored.
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_allocate(struct bios_linker_entry *entry, u32 *addr)
-{
-   uint32_t size, align;
-   struct fw_file *file;
-   unsigned long aligned_addr;
-
-   align = le32_to_cpu(entry->alloc.align);
-   /* align must be power of 2 */
-   if (align & (align - 1)) {
-   printf("error: wrong alignment %u\n", align);
-   return -EINVAL;
-   }
-
-   file = qemu_fwcfg_find_file(entry->alloc.file);
-   if (!file) {
-   printf("error: can't find file %s\n", entry->alloc.file);
-   return -ENOENT;
-   }
-
-   size = be32_to_cpu(file->cfg.size);
-
-   /*
-* ZONE_HIGH means we need to allocate from high memory, since
-* malloc space is already at the end of RAM, so we directly use it.
-* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
-* in which is low memory
-*/
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
-   aligned_addr = (unsigned long)memalign(align, size);
-   if (!aligned_addr) {
-   printf("error: allocating resource\n");
-   return -ENOMEM;
-   }
-   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
-   aligned_addr = ALIGN(*addr, align);
-   } else {
-   printf("error: invalid allocation zone\n");
-   return -EINVAL;
-   }
-
-   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
- file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
-
-   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
- size, (void *)aligned_addr);
-   file->addr = aligned_addr;
-
-   /* adjust address for low memory allocation */
-   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
-   *addr = (aligned_addr + size);
-
-   return 0;
-}
-
-/*
- * This function patches ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells how to patch
- *  ACPI tables
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_pointer(struct bios_linker_entry *entry)
-{
-   struct fw_file *dest, *src;
-   uint32_t offset = le32_to_cpu(entry->pointer.offset);
-   uint64_t pointer = 0;
-
-   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
-   if (!dest || !dest->addr)
-   return -ENOENT;
-   src = qemu_fwcfg_find_file(entry->pointer.src_file);
-   if (!src || !src->addr)
-   return -ENOENT;
-
-   debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, 
offset 0x%x size %u, 0x%llx\n",
- dest->addr, src->addr, offset, entry->pointer.size, pointer);
-
-   memcpy(, (char *)dest->addr + offset, entry->pointer.size);
-   pointer = le64_to_cpu(pointer);
-   pointer += (unsigned long)src->addr;
-   pointer = cpu_to_le64(pointer);
-   memcpy((char *)dest->addr + offset, , entry->pointer.size);
-
-   return 0;
-}
-
-/*
- * This function updates checksum fields of ACPI tables previously loaded
- * by bios_linker_allocate()
- *
- * @entry : BIOS linker command entry which tells where to update ACPI table
- *  checksums
- * @return: 0 on success, or negative value on failure
- */
-static int bios_linker_add_checksum(struct bios_linker_entry *entry)
-{
-   struct fw_file *file;
-   uint8_t *data, cksum = 0;
-   uint8_t *cksum_start;
-
-   file = qemu_fwcfg_find_file(entry->c

[U-Boot] [PATCH 10/12] cmd: qfw: do not depend on x86

2016-05-13 Thread Miao Yan
The qfw command interface used to depend on X86, this patch removes
this restriction so it can be built for sandbox for testing. For normal
usage, it can only be used with CONFIG_QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 cmd/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 08b761f..01870cb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -595,7 +595,6 @@ config CMD_SOUND
 
 config CMD_QEMU_FW_CFG
bool "qfw"
-   depends on X86
select QFW
help
  This provides access to the QEMU firmware interface.  The main
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 05/12] x86: qemu: split qfw command interface and qfw core

2016-05-13 Thread Miao Yan
This patch splits qfw command interface and qfw core function into two
files, and introduces a new Kconfig option (CONFIG_QFW). for
qfw core.

Now when qfw command interface is enabled, it will automatically select
qfw core. This patch also makes the ACPI table generation select
CONFIG_QFW.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/Kconfig   |   2 +-
 arch/x86/cpu/mp_init.c |   6 +-
 arch/x86/cpu/qemu/Makefile |   3 +-
 arch/x86/cpu/qemu/acpi_table.c |   2 +
 arch/x86/cpu/qemu/qemu.c   |   4 +
 cmd/Kconfig|   1 +
 cmd/Makefile   |   2 +-
 cmd/cmd_qfw.c  | 182 +
 cmd/qemu_fw_cfg.c  | 353 -
 common/Kconfig |   1 +
 drivers/misc/Kconfig   |   6 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/qemu_fw_cfg.c | 185 +
 13 files changed, 390 insertions(+), 358 deletions(-)
 create mode 100644 cmd/cmd_qfw.c
 delete mode 100644 cmd/qemu_fw_cfg.c
 create mode 100644 drivers/misc/qemu_fw_cfg.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index a60e0da..2f63170 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,7 +436,7 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
-   select QEMU_FW_CFG if QEMU
+   select QFW if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 13bec7a..109b3d7 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -11,7 +11,9 @@
 #include 
 #include 
 #include 
+#ifdef CONFIG_QFW
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -420,7 +422,7 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
 static int qemu_cpu_fixup(void)
 {
int ret;
@@ -496,7 +498,7 @@ int mp_init(struct mp_params *p)
if (ret)
return ret;
 
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QFW
ret = qemu_cpu_fixup();
if (ret)
return ret;
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 43ee4bd..7c08c3d 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,6 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += cpu.o qemu.o
+obj-y += qemu.o
+obj-$(CONFIG_QFW) += cpu.o
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index b17fa03..4584fc7 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -8,7 +8,9 @@
 #include 
 #include 
 #include 
+#ifdef CONFIG_QFW
 #include 
+#endif
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index b41e4ec..2631e99 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -6,7 +6,9 @@
 
 #include 
 #include 
+#ifdef CONFIG_QFW
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -88,7 +90,9 @@ static void qemu_chipset_init(void)
enable_pm_ich9();
}
 
+#ifdef CONFIG_QFW
qemu_fwcfg_init();
+#endif
 }
 
 int arch_cpu_init(void)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c0fffe3..08b761f 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -596,6 +596,7 @@ config CMD_SOUND
 config CMD_QEMU_FW_CFG
bool "qfw"
depends on X86
+   select QFW
help
  This provides access to the QEMU firmware interface.  The main
  feature is to allow easy loading of files passed to qemu-system
diff --git a/cmd/Makefile b/cmd/Makefile
index f99e67d..31e4da7 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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) += qemu_fw_cfg.o
+obj-$(CONFIG_CMD_QEMU_FW_CFG) += cmd_qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
diff --git a/cmd/cmd_qfw.c b/cmd/cmd_qfw.c
new file mode 100644
index 000..eefaf65
--- /dev/null
+++ b/cmd/cmd_qfw.c
@@ -0,0 +1,182 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This function prepares kernel for zboot. It loads kernel data
+ * to 'load_addr', initrd to 'initrd_addr' and kernel command
+ * line using qemu fw_cfg interface.
+ */
+static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr)
+{
+   char *data_addr;
+   uint32_t setup_size, kernel_size, cmdline_size, initrd_size;
+
+   qemu_fwcfg_read_entry(FW_CFG_SETUP_SIZE, 4, _size);
+   qemu_fwcfg_

[U-Boot] [PATCH 07/12] x86: qemu: add comment about qfw register endianness

2016-05-13 Thread Miao Yan
This patch adds some comments about qfw register endianness for clarity.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/qemu.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index d964283..716a0ac 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -19,6 +19,7 @@ static bool i440fx;
 
 #ifdef CONFIG_QFW
 
+/* on x86, the qfw registers are all IO ports */
 #define FW_CONTROL_PORT0x510
 #define FW_DATA_PORT   0x511
 #define FW_DMA_PORT_LOW0x514
@@ -33,15 +34,21 @@ static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
/*
 * writting FW_CFG_INVALID will cause read operation to resume at
 * last offset, otherwise read will start at offset 0
+*
+* Note: on platform where the control register is IO port, the
+* endianness is little endian.
 */
if (entry != FW_CFG_INVALID)
-   outw(entry, FW_CONTROL_PORT);
+   outw(cpu_to_le16(entry), FW_CONTROL_PORT);
+
+   /* the endianness of data register is string-preserving */
while (size--)
data[i++] = inb(FW_DATA_PORT);
 }
 
 static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
 {
+   /* the DMA address register is big endian */
outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
 
while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 09/12] cmd: qfw: workaround qfw build issue

2016-05-13 Thread Miao Yan
The qfw command interface makes use of CONFIG_LOADADDR and
CONFIG_RAMDISKADDR to setup kernel. But not all boards have these macro,
which causes build problem on those platforms.

This patch fixes this issue.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 cmd/cmd_qfw.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/cmd/cmd_qfw.c b/cmd/cmd_qfw.c
index aeb576b..13ad673 100644
--- a/cmd/cmd_qfw.c
+++ b/cmd/cmd_qfw.c
@@ -126,12 +126,20 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
env = getenv("loadaddr");
load_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_LOADADDR
(void *)CONFIG_LOADADDR;
+#else
+   NULL;
+#endif
 
env = getenv("ramdiskaddr");
initrd_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
+#ifdef CONFIG_RAMDISK_ADDR
(void *)CONFIG_RAMDISK_ADDR;
+#else
+   NULL;
+#endif
 
if (argc == 2) {
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
@@ -140,6 +148,11 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
load_addr = (void *)simple_strtoul(argv[0], NULL, 16);
}
 
+   if (!load_addr || !initrd_addr) {
+   printf("missing load or initrd address\n");
+   return CMD_RET_FAILURE;
+   }
+
return qemu_fwcfg_setup_kernel(load_addr, initrd_addr);
 }
 
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 03/12] cmd: qfw: remove qemu_fwcfg_free_files()

2016-05-13 Thread Miao Yan
This patch is part of the qfw refactor work.

The qemu_fwcfg_free_files() function is only used in error handling in
ACPI table generation, let's not make this a core function and move it
to the right place.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/acpi_table.c | 13 +++--
 cmd/qemu_fw_cfg.c  | 12 
 include/qemu_fw_cfg.h  |  1 -
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
index 49381ac..b17fa03 100644
--- a/arch/x86/cpu/qemu/acpi_table.c
+++ b/arch/x86/cpu/qemu/acpi_table.c
@@ -235,8 +235,17 @@ u32 write_acpi_tables(u32 addr)
}
 
 out:
-   if (ret)
-   qemu_fwcfg_free_files();
+   if (ret) {
+   struct fw_cfg_file_iter iter;
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
+   if (file->addr) {
+   free((void *)file->addr);
+   file->addr = 0;
+   }
+   }
+   }
 
free(table_loader);
return addr;
diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 192b7d1..9f03ab6 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -217,18 +217,6 @@ struct fw_file *qemu_fwcfg_find_file(const char *name)
return NULL;
 }
 
-void qemu_fwcfg_free_files(void)
-{
-   struct fw_file *file;
-   struct list_head *list;
-
-   list_for_each(list, _list) {
-   file = list_entry(list, struct fw_file, list);
-   if (file->addr)
-   free((void *)file->addr);
-   }
-}
-
 struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
 {
iter->entry = fw_list.next;
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 19d0ba0..986f4b2 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -154,7 +154,6 @@ void qemu_fwcfg_init(void);
 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);
-void qemu_fwcfg_free_files(void);
 
 /**
  * Get system cpu number
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 06/12] x86: qemu: move x86 specific operations out of qfw core

2016-05-13 Thread Miao Yan
The original implementation of qfw includes several x86 specific
operations, like directly calling outb/inb and using some inline
assembly code which prevents it being ported to other architectures.

This patch adds callback functions and moves those to arch/x86/

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/qemu.c   | 39 ++-
 drivers/misc/qemu_fw_cfg.c | 30 +-
 include/qemu_fw_cfg.h  | 15 +--
 3 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 2631e99..d964283 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -17,6 +17,43 @@
 
 static bool i440fx;
 
+#ifdef CONFIG_QFW
+
+#define FW_CONTROL_PORT0x510
+#define FW_DATA_PORT   0x511
+#define FW_DMA_PORT_LOW0x514
+#define FW_DMA_PORT_HIGH   0x518
+
+static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
+   uint32_t size, void *address)
+{
+   uint32_t i = 0;
+   uint8_t *data = address;
+
+   /*
+* 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)
+   outw(entry, FW_CONTROL_PORT);
+   while (size--)
+   data[i++] = inb(FW_DATA_PORT);
+}
+
+static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
+{
+   outl(cpu_to_be32((uint32_t)dma), FW_DMA_PORT_HIGH);
+
+   while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
+   __asm__ __volatile__ ("pause");
+}
+
+static struct fw_cfg_arch_ops fwcfg_x86_ops = {
+   .arch_read_pio = qemu_x86_fwcfg_read_entry_pio,
+   .arch_read_dma = qemu_x86_fwcfg_read_entry_dma
+};
+#endif
+
 static void enable_pm_piix(void)
 {
u8 en;
@@ -91,7 +128,7 @@ static void qemu_chipset_init(void)
}
 
 #ifdef CONFIG_QFW
-   qemu_fwcfg_init();
+   qemu_fwcfg_init(_x86_ops);
 #endif
 }
 
diff --git a/drivers/misc/qemu_fw_cfg.c b/drivers/misc/qemu_fw_cfg.c
index e726059..0700641 100644
--- a/drivers/misc/qemu_fw_cfg.c
+++ b/drivers/misc/qemu_fw_cfg.c
@@ -14,6 +14,7 @@
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
+static struct fw_cfg_arch_ops *fwcfg_arch_ops;
 
 static LIST_HEAD(fw_list);
 
@@ -21,17 +22,10 @@ static LIST_HEAD(fw_list);
 static void qemu_fwcfg_read_entry_pio(uint16_t entry,
uint32_t size, void *address)
 {
-   uint32_t i = 0;
-   uint8_t *data = address;
+   debug("qemu_fwcfg_read_entry_pio: entry 0x%x, size %u address %p\n",
+ entry, size, address);
 
-   /*
-* 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)
-   outw(entry, FW_CONTROL_PORT);
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
+   return fwcfg_arch_ops->arch_read_pio(entry, size, address);
 }
 
 /* Read configuration item using fw_cfg DMA interface */
@@ -53,13 +47,10 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
 
barrier();
 
-   debug("qemu_fwcfg_dma_read_entry: addr %p, length %u control 0x%x\n",
- address, size, be32_to_cpu(dma.control));
-
-   outl(cpu_to_be32((uint32_t)), FW_DMA_PORT_HIGH);
+   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));
 
-   while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_ERROR)
-   __asm__ __volatile__ ("pause");
+   fwcfg_arch_ops->arch_read_dma();
 }
 
 bool qemu_fwcfg_present(void)
@@ -164,13 +155,18 @@ bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter 
*iter)
return iter->entry == _list;
 }
 
-void qemu_fwcfg_init(void)
+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, );
if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index f718e09..b0b3b59 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -7,11 +7,6 @@
 #ifndef __FW_CFG__
 #define __FW_CFG__
 
-#define FW_CONTROL_PORT0x510
-#define FW_DATA_PORT   0x511
-#define FW_DMA_PORT_LOW0x514
-#define FW_DMA_PORT_HIGH   0x518
-
 #include 
 
 enum qemu_fwcfg_items {
@@ -97,6 +92,12 @@ struct fw_cfg_dma_access {
__be64 address;
 };
 
+struct fw_cfg_arch_ops {
+   void (*arch_read_pio)(uint

[U-Boot] [PATCH 04/12] cmd: qfw: make fwcfg_present and fwcfg_dma_present public

2016-05-13 Thread Miao Yan
This patch is part of the qfw refactor work. This patch makes
qemu_fwcfg_present() and qemu_fwcfg_dma_present() public functions.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 cmd/qemu_fw_cfg.c | 37 -
 include/qemu_fw_cfg.h |  3 +++
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 9f03ab6..aab6b1a 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -62,23 +62,14 @@ static void qemu_fwcfg_read_entry_dma(uint16_t entry,
__asm__ __volatile__ ("pause");
 }
 
-static bool qemu_fwcfg_present(void)
+bool qemu_fwcfg_present(void)
 {
-   uint32_t qemu;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
-   return be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE;
+   return fwcfg_present;
 }
 
-static bool qemu_fwcfg_dma_present(void)
+bool qemu_fwcfg_dma_present(void)
 {
-   uint8_t dma_enabled;
-
-   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
-   if (dma_enabled & FW_CFG_DMA_ENABLED)
-   return true;
-
-   return false;
+   return fwcfg_dma_present;
 }
 
 void qemu_fwcfg_read_entry(uint16_t entry, uint32_t length, void *address)
@@ -257,9 +248,21 @@ static int qemu_fwcfg_list_firmware(void)
 
 void qemu_fwcfg_init(void)
 {
-   fwcfg_present = qemu_fwcfg_present();
-   if (fwcfg_present)
-   fwcfg_dma_present = qemu_fwcfg_dma_present();
+   uint32_t qemu;
+   uint32_t dma_enabled;
+
+   fwcfg_present = false;
+   fwcfg_dma_present = false;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
+   if (be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE)
+   fwcfg_present = true;
+
+   if (fwcfg_present) {
+   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
+   if (dma_enabled & FW_CFG_DMA_ENABLED)
+   fwcfg_dma_present = true;
+   }
 }
 
 static int qemu_fwcfg_do_list(cmd_tbl_t *cmdtp, int flag,
@@ -323,7 +326,7 @@ static int do_qemu_fw(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
int ret;
cmd_tbl_t *fwcfg_cmd;
 
-   if (!fwcfg_present) {
+   if (!qemu_fwcfg_present()) {
printf("QEMU fw_cfg interface not found\n");
return CMD_RET_USAGE;
}
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index 986f4b2..f718e09 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -167,4 +167,7 @@ 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
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 02/12] cmd: qfw: add API to iterate firmware list

2016-05-13 Thread Miao Yan
This patch is part of the refactor work of qfw. It adds 3 APIs to qfw
core to iterate firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 cmd/qemu_fw_cfg.c | 25 ++---
 include/qemu_fw_cfg.h |  9 +
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/cmd/qemu_fw_cfg.c b/cmd/qemu_fw_cfg.c
index 48ae476..192b7d1 100644
--- a/cmd/qemu_fw_cfg.c
+++ b/cmd/qemu_fw_cfg.c
@@ -229,10 +229,27 @@ void qemu_fwcfg_free_files(void)
}
 }
 
+struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = fw_list.next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
+{
+   iter->entry = iter->entry->next;
+   return list_entry(iter->entry, struct fw_file, list);
+}
+
+bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
+{
+   return iter->entry == _list;
+}
+
 static int qemu_fwcfg_list_firmware(void)
 {
int ret;
-   struct list_head *entry;
+   struct fw_cfg_file_iter iter;
struct fw_file *file;
 
/* make sure fw_list is loaded */
@@ -240,8 +257,10 @@ static int qemu_fwcfg_list_firmware(void)
if (ret)
return ret;
 
-   list_for_each(entry, _list) {
-   file = list_entry(entry, struct fw_file, list);
+
+   for (file = qemu_fwcfg_file_iter_init();
+!qemu_fwcfg_file_iter_end();
+file = qemu_fwcfg_file_iter_next()) {
printf("%-56s\n", file->cfg.name);
}
 
diff --git a/include/qemu_fw_cfg.h b/include/qemu_fw_cfg.h
index e21f150..19d0ba0 100644
--- a/include/qemu_fw_cfg.h
+++ b/include/qemu_fw_cfg.h
@@ -87,6 +87,10 @@ struct fw_file {
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;
@@ -159,4 +163,9 @@ void qemu_fwcfg_free_files(void);
  */
 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);
+
 #endif
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 01/12] x86: qemu: fix ACPI Kconfig options

2016-05-13 Thread Miao Yan
CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
to load ACPI table from QEMU's fw_cfg interface.

But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
our own ACPI implementation", there is only one way to support ACPI table
for QEMU targets which is the fw_cfg interface. Having two Kconfig options
for this purpose is not necessary any more, so this patch consolidates
the two.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/Kconfig   | 10 +-
 arch/x86/cpu/qemu/Makefile |  2 +-
 arch/x86/lib/Makefile  |  2 +-
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ef27dc..a60e0da 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -436,21 +436,13 @@ config GENERATE_MP_TABLE
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
default n
+   select QEMU_FW_CFG if QEMU
help
  The Advanced Configuration and Power Interface (ACPI) specification
  provides an open standard for device configuration and management
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
-config QEMU_ACPI_TABLE
-   bool "Load ACPI table from QEMU fw_cfg interface"
-   depends on GENERATE_ACPI_TABLE && QEMU
-   default y
-   help
- By default, U-Boot generates its own ACPI tables. This option, if
- enabled, disables U-Boot's version and loads ACPI tables generated
- by QEMU.
-
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 97b965c..43ee4bd 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,4 +8,4 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o qemu.o
-obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index dc90df2..ce5eb82 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y  += string.o
-ifndef CONFIG_QEMU_ACPI_TABLE
+ifndef CONFIG_QEMU
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y  += tables.o
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 00/12] cleanup QEMU fw_cfg code

2016-05-13 Thread Miao Yan
This patchset cleans the QEMU fw_cfg code:

  *) split qfw core and qfw command interface
  *) split x86 specific operations from qfw core
  *) move x86 ACPI generation code into qfw core as this can also
 be used by others like ARM64
  *) various cleanups

Miao Yan (12):
  x86: qemu: fix ACPI Kconfig options
  cmd: qfw: add API to iterate firmware list
  cmd: qfw: remove qemu_fwcfg_free_files()
  cmd: qfw: make fwcfg_present and fwcfg_dma_present public
  x86: qemu: split qfw command interface and qfw core
  x86: qemu: move x86 specific operations out of qfw core
  x86: qemu: add comment about qfw register endianness
  cmd: qfw: rename qemu_fw_cfg.[c|h] to qfw.[c|h]
  cmd: qfw: workaround qfw build issue
  cmd: qfw: do not depend on x86
  cmd: qfw: bring ACPI generation code into qfw core
  x86: qemu: rename qemu/acpi_table.c

 arch/x86/Kconfig   |  10 +-
 arch/x86/cpu/mp_init.c |   8 +-
 arch/x86/cpu/qemu/Makefile |   4 +-
 arch/x86/cpu/qemu/acpi_table.c | 243 --
 arch/x86/cpu/qemu/cpu.c|   2 +-
 arch/x86/cpu/qemu/e820.c   |  43 +
 arch/x86/cpu/qemu/qemu.c   |  52 +-
 arch/x86/lib/Makefile  |   2 +-
 cmd/Kconfig|   2 +-
 cmd/Makefile   |   2 +-
 cmd/cmd_qfw.c  | 195 +
 cmd/qemu_fw_cfg.c  | 343 
 common/Kconfig |   1 +
 drivers/misc/Kconfig   |   6 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/qfw.c | 387 +
 include/qemu_fw_cfg.h  | 162 -
 include/qfw.h  | 176 +++
 18 files changed, 871 insertions(+), 768 deletions(-)
 delete mode 100644 arch/x86/cpu/qemu/acpi_table.c
 create mode 100644 arch/x86/cpu/qemu/e820.c
 create mode 100644 cmd/cmd_qfw.c
 delete mode 100644 cmd/qemu_fw_cfg.c
 create mode 100644 drivers/misc/qfw.c
 delete mode 100644 include/qemu_fw_cfg.h
 create mode 100644 include/qfw.h

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-11 Thread Miao Yan
2016-05-11 10:11 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Tue, May 10, 2016 at 10:10 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>>
>>>> +config CMD_QEMU_FW_CFG
>>>> +   bool "qfw"
>>>> +   depends on X86
>>>> +   help
>>>> + This provides access to the QEMU firmware interface.  The main
>>>> + feature is to allow easy loading of files passed to qemu-system
>>>> + via -kernel / -initrd
>>>>  endmenu
>>>
>>> This should really be "depends on QEMU". Sorry for my earlier comment.
>>
>>
>> This line should be "depends on X86 && QEMU". Sorry I wasn't thinking right.
>>
>
> This "depends on X86 && QEMU" still does not work as users can still
> unselect this qfw command from menuconfig.

The qfw commands are not mandatory, so users should be able to disable it.

> We should make QEMU select this qfw command when CONFIG_GENERATE_ACPI_TABLE.

GENERATE_ACPI_TABLE should select qfw core, not qfw command interface.

Anyway I'll prepare patches for you guys to review.

Thanks,
Miao

>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-11 Thread Miao Yan
Hi Tom,

>
> Well, this patch was a first pass at trying to separate out the logic.
> My end goal is to be able to use -kernel / -initrd / -dtb to pass in
> files "directly" to say vexpress_ca9x4 rather than have to fiddle with
> fake networking.  So we need to keep that in mind when splitting the

Well, about that, the fw_cfg is only exposed on certain QEMU emulated boards.
For ARM, it is only available on arm_virt which supports cortexA15/53/57.
Does U-boot have out-of-box support for that ?

Thanks,
Miao

> code into cmd/ common/ and arch/x86/ (I'll set aside ACPI tables on ARM
> in QEMU for the moment, but lets also not forget that will be something
> someone will talk about in the future).
>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] x86: qemu: fix ACPI Kconfig options

2016-05-10 Thread Miao Yan
Hi Bin,

2016-05-11 10:13 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Wed, May 11, 2016 at 10:02 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Hi Bin,
>>
>> 2016-05-10 11:11 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> On Mon, May 9, 2016 at 8:57 PM, Bin Meng <bmeng...@gmail.com> wrote:
>>>> On Mon, May 9, 2016 at 3:27 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>>> CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
>>>>> uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
>>>>> to load ACPI table from QEMU's fw_cfg interface.
>>>>>
>>>>> But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
>>>>> our own ACPI implementation", there is only one way to support ACPI table
>>>>> for QEMU targets which is the fw_cfg interface. Having two Kconfig options
>>>>> for this purpose is not necessary any more, so this patch consolidates
>>>>> the two.
>>>>>
>>>>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>>>> ---
>>>>>  arch/x86/Kconfig   | 9 -
>>>>>  arch/x86/cpu/qemu/fw_cfg.c | 2 +-
>>>>>  arch/x86/lib/Makefile  | 2 +-
>>>>>  3 files changed, 2 insertions(+), 11 deletions(-)
>>>>>
>>>>
>>>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>>>
>>> Miao, please rebase this patch on top of u-boot-x86/next since Tom's
>>> patch was applied first.
>>
>> Sure, I'll send v2.
>>
>
> When you rework the v2, could you please submit changes in addition to
> Tom's patch to make sure there is no build errors as the workflow you
> described. And maybe split the qfw command into two pieces? Sorry for
> asking for a lot.

OK, I'll think about it and send some patches.

Miao


>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] x86: qemu: fix ACPI Kconfig options

2016-05-10 Thread Miao Yan
Hi Bin,

2016-05-10 11:11 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> On Mon, May 9, 2016 at 8:57 PM, Bin Meng <bmeng...@gmail.com> wrote:
>> On Mon, May 9, 2016 at 3:27 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>> CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
>>> uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
>>> to load ACPI table from QEMU's fw_cfg interface.
>>>
>>> But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
>>> our own ACPI implementation", there is only one way to support ACPI table
>>> for QEMU targets which is the fw_cfg interface. Having two Kconfig options
>>> for this purpose is not necessary any more, so this patch consolidates
>>> the two.
>>>
>>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>> ---
>>>  arch/x86/Kconfig   | 9 -
>>>  arch/x86/cpu/qemu/fw_cfg.c | 2 +-
>>>  arch/x86/lib/Makefile  | 2 +-
>>>  3 files changed, 2 insertions(+), 11 deletions(-)
>>>
>>
>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>
> Miao, please rebase this patch on top of u-boot-x86/next since Tom's
> patch was applied first.

Sure, I'll send v2.

Thanks,
Miao
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-10 Thread Miao Yan
Hi Bin,

2016-05-10 13:12 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Tue, May 10, 2016 at 12:35 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> 2016-05-10 11:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> On Tue, May 10, 2016 at 10:17 AM, Tom Rini <tr...@konsulko.com> wrote:
>>>> On Tue, May 10, 2016 at 09:20:45AM +0800, Bin Meng wrote:
>>>>> On Fri, May 6, 2016 at 10:40 PM, Tom Rini <tr...@konsulko.com> wrote:
>>>>> > - Move the command portion of arch/x86/cpu/qemu/fw_cfg.c into
>>>>> >   cmd/qemu_fw_cfg.c
>>>>> > - Move arch/x86/include/asm/fw_cfg.h to include/qemu_fw_cfg.h
>>>>> > - Rename ACPI table portion to arch/x86/cpu/qemu/acpi_table.c
>>>>> >
>>>>> > Signed-off-by: Tom Rini <tr...@konsulko.com>
>>>>> > ---
>>>>> > Changes in v2:
>>>>> > - Depend on X86 (per Miao Yan)
>>>>> > ---
>>>>> >  arch/x86/cpu/mp_init.c |   2 +-
>>>>> >  arch/x86/cpu/qemu/Makefile |   3 +-
>>>>> >  arch/x86/cpu/qemu/acpi_table.c | 243 ++
>>>>> >  arch/x86/cpu/qemu/cpu.c|   2 +-
>>>>> >  arch/x86/cpu/qemu/fw_cfg.c | 570 
>>>>> > -
>>>>> >  arch/x86/cpu/qemu/qemu.c   |   2 +-
>>>>> >  arch/x86/include/asm/fw_cfg.h  | 157 
>>>>> >  arch/x86/lib/acpi_table.c  |   2 +-
>>>>> >  cmd/Kconfig|   7 +
>>>>> >  cmd/Makefile   |   1 +
>>>>> >  cmd/qemu_fw_cfg.c  | 343 +
>>>>> >  configs/qemu-x86_defconfig |   1 +
>>>>> >  include/qemu_fw_cfg.h  | 162 
>>>>> >  13 files changed, 763 insertions(+), 732 deletions(-)
>>>>> >  create mode 100644 arch/x86/cpu/qemu/acpi_table.c
>>>>> >  delete mode 100644 arch/x86/cpu/qemu/fw_cfg.c
>>>>> >  delete mode 100644 arch/x86/include/asm/fw_cfg.h
>>>>> >  create mode 100644 cmd/qemu_fw_cfg.c
>>>>> >  create mode 100644 include/qemu_fw_cfg.h
>>>>> >
>>>>>
>>>>> Looks good.
>>>>>
>>>>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>>>>>
>>>>> Tom, will you pick this for this release, or next release?
>>>>>
>>>>> Miao has a patch [1] to remove CONFIG_QEMU_ACPI_TABLE. If your patch
>>>>> comes first, Miao needs to rebase his and submit v2.
>>>>
>>>> For the next release, and I'll leave it to you to pull in.  Thanks!
>>>
>>> applied to u-boot-x86/next, thanks!
>>
>>
>> Wait, you applied this already ? Did you include the diff I mentioned
>
> The patch is not in mainline. It's currently in x86 tree and we can
> always fix issues before a pull request is sent out.
>
>> ? This patch has build issues. Before the patch, the qfw is built
>> unconditionally for x86-qemu, after applying this patch, qfw depends
>> on CONFIG_CMD_QEMU_FW_CFG. This is a change of behavior, so you need
>> to test:
>>
>> 1) defconfig build
>> 2) defconfig with CONFIG_CMD_QEMU_FW_CFG disabled because it's
>> user visible now
>>
>> This patch breaks 2):
>>
>
> I doubt everything can be build error free if we randomly switch
> something on or off from the Kconfig GUI. I did buildman testing for

Well I don't think it's "random", we have mature tools to deal with
dependencies,
it's not like I was directly modifying random stuff in .config with a
text editor.
Kconfig options should be there for a reason, otherwise why bother.
And if it doesn't work then it's a bug.

> this patch and nothing breaks by default. Having said that, I agree
> the build error you reported is something we should fix.

OK. So can you please apply the diff or ask for v3 if you like ?

>
>>
>> arch/x86/cpu/built-in.o: In function `cpu_qemu_get_count':
>> /home/myan/work/u-boot/arch/x86/cpu/qemu/cpu.c:28: undefined reference
>> to `qemu_fwcfg_online_cpus'
>> arch/x86/cpu/built-in.o: In function `qemu_chipset_init':
>> /home/myan/work/u-boot/arch/x86/cpu/qemu/qemu.c:91: undefined
>> reference to `qemu_fwcfg_init'
>> arch/x86/cpu/built-in.o: In function `write_acpi_tables':
>> /home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:187: undefined
>> reference to `

Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-09 Thread Miao Yan
2016-05-10 11:08 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> On Tue, May 10, 2016 at 10:17 AM, Tom Rini <tr...@konsulko.com> wrote:
>> On Tue, May 10, 2016 at 09:20:45AM +0800, Bin Meng wrote:
>>> On Fri, May 6, 2016 at 10:40 PM, Tom Rini <tr...@konsulko.com> wrote:
>>> > - Move the command portion of arch/x86/cpu/qemu/fw_cfg.c into
>>> >   cmd/qemu_fw_cfg.c
>>> > - Move arch/x86/include/asm/fw_cfg.h to include/qemu_fw_cfg.h
>>> > - Rename ACPI table portion to arch/x86/cpu/qemu/acpi_table.c
>>> >
>>> > Signed-off-by: Tom Rini <tr...@konsulko.com>
>>> > ---
>>> > Changes in v2:
>>> > - Depend on X86 (per Miao Yan)
>>> > ---
>>> >  arch/x86/cpu/mp_init.c |   2 +-
>>> >  arch/x86/cpu/qemu/Makefile |   3 +-
>>> >  arch/x86/cpu/qemu/acpi_table.c | 243 ++
>>> >  arch/x86/cpu/qemu/cpu.c|   2 +-
>>> >  arch/x86/cpu/qemu/fw_cfg.c | 570 
>>> > -
>>> >  arch/x86/cpu/qemu/qemu.c   |   2 +-
>>> >  arch/x86/include/asm/fw_cfg.h  | 157 
>>> >  arch/x86/lib/acpi_table.c  |   2 +-
>>> >  cmd/Kconfig|   7 +
>>> >  cmd/Makefile   |   1 +
>>> >  cmd/qemu_fw_cfg.c  | 343 +
>>> >  configs/qemu-x86_defconfig |   1 +
>>> >  include/qemu_fw_cfg.h  | 162 
>>> >  13 files changed, 763 insertions(+), 732 deletions(-)
>>> >  create mode 100644 arch/x86/cpu/qemu/acpi_table.c
>>> >  delete mode 100644 arch/x86/cpu/qemu/fw_cfg.c
>>> >  delete mode 100644 arch/x86/include/asm/fw_cfg.h
>>> >  create mode 100644 cmd/qemu_fw_cfg.c
>>> >  create mode 100644 include/qemu_fw_cfg.h
>>> >
>>>
>>> Looks good.
>>>
>>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>>>
>>> Tom, will you pick this for this release, or next release?
>>>
>>> Miao has a patch [1] to remove CONFIG_QEMU_ACPI_TABLE. If your patch
>>> comes first, Miao needs to rebase his and submit v2.
>>
>> For the next release, and I'll leave it to you to pull in.  Thanks!
>
> applied to u-boot-x86/next, thanks!


Wait, you applied this already ? Did you include the diff I mentioned
? This patch has build issues. Before the patch, the qfw is built
unconditionally for x86-qemu, after applying this patch, qfw depends
on CONFIG_CMD_QEMU_FW_CFG. This is a change of behavior, so you need
to test:

1) defconfig build
2) defconfig with CONFIG_CMD_QEMU_FW_CFG disabled because it's
user visible now

This patch breaks 2):


arch/x86/cpu/built-in.o: In function `cpu_qemu_get_count':
/home/myan/work/u-boot/arch/x86/cpu/qemu/cpu.c:28: undefined reference
to `qemu_fwcfg_online_cpus'
arch/x86/cpu/built-in.o: In function `qemu_chipset_init':
/home/myan/work/u-boot/arch/x86/cpu/qemu/qemu.c:91: undefined
reference to `qemu_fwcfg_init'
arch/x86/cpu/built-in.o: In function `write_acpi_tables':
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:187: undefined
reference to `qemu_fwcfg_read_firmware_list'
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:193: undefined
reference to `qemu_fwcfg_find_file'
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:211: undefined
reference to `qemu_fwcfg_read_entry'
arch/x86/cpu/built-in.o: In function `bios_linker_allocate':
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:41: undefined
reference to `qemu_fwcfg_find_file'
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:71: undefined
reference to `qemu_fwcfg_read_entry'
arch/x86/cpu/built-in.o: In function `bios_linker_add_pointer':
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:96: undefined
reference to `qemu_fwcfg_find_file'
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:99: undefined
reference to `qemu_fwcfg_find_file'
arch/x86/cpu/built-in.o: In function `bios_linker_add_checksum':
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:129: undefined
reference to `qemu_fwcfg_find_file'
arch/x86/cpu/built-in.o: In function `write_acpi_tables':
/home/myan/work/u-boot/arch/x86/cpu/qemu/acpi_table.c:239: undefined
reference to `qemu_fwcfg_free_files'
arch/x86/cpu/built-in.o: In function `qemu_cpu_fixup':
/home/myan/work/u-boot/arch/x86/cpu/mp_init.c:454: undefined reference
to `qemu_fwcfg_online_cpus'
make: *** [u-boot] Error 1


And I still think for this patch, it should depend on x86 && qemu. It
doesn't make sense to build qfw for other non-qemu boards.

Miao
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-09 Thread Miao Yan
>>
>> +config CMD_QEMU_FW_CFG
>> +   bool "qfw"
>> +   depends on X86
>> +   help
>> + This provides access to the QEMU firmware interface.  The main
>> + feature is to allow easy loading of files passed to qemu-system
>> + via -kernel / -initrd
>>  endmenu
>
> This should really be "depends on QEMU". Sorry for my earlier comment.


This line should be "depends on X86 && QEMU". Sorry I wasn't thinking right.

Miao
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] x86: qemu: fix ACPI Kconfig options

2016-05-09 Thread Miao Yan
CONFIG_GENENRATE_ACPI_TABLE controls the generation of ACPI table which
uses U-Boot's built-in methods and CONFIG_QEMU_ACPI_TABLE controls whether
to load ACPI table from QEMU's fw_cfg interface.

But with commit "697ec431469ce0a4c2fc2c02d8685d907491af84 x86: qemu: Drop
our own ACPI implementation", there is only one way to support ACPI table
for QEMU targets which is the fw_cfg interface. Having two Kconfig options
for this purpose is not necessary any more, so this patch consolidates
the two.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/Kconfig   | 9 -
 arch/x86/cpu/qemu/fw_cfg.c | 2 +-
 arch/x86/lib/Makefile  | 2 +-
 3 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ef27dc..f12cb9d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -442,15 +442,6 @@ config GENERATE_ACPI_TABLE
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
-config QEMU_ACPI_TABLE
-   bool "Load ACPI table from QEMU fw_cfg interface"
-   depends on GENERATE_ACPI_TABLE && QEMU
-   default y
-   help
- By default, U-Boot generates its own ACPI tables. This option, if
- enabled, disables U-Boot's version and loads ACPI tables generated
- by QEMU.
-
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index 2e2794e..63d3077 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -207,7 +207,7 @@ err:
return -ENOMEM;
 }
 
-#ifdef CONFIG_QEMU_ACPI_TABLE
+#ifdef CONFIG_GENERATE_ACPI_TABLE
 static struct fw_file *qemu_fwcfg_find_file(const char *name)
 {
struct list_head *entry;
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index dc90df2..ce5eb82 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y  += string.o
-ifndef CONFIG_QEMU_ACPI_TABLE
+ifndef CONFIG_QEMU
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y  += tables.o
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-09 Thread Miao Yan
2016-05-06 22:40 GMT+08:00 Tom Rini <tr...@konsulko.com>:
> - Move the command portion of arch/x86/cpu/qemu/fw_cfg.c into
>   cmd/qemu_fw_cfg.c
> - Move arch/x86/include/asm/fw_cfg.h to include/qemu_fw_cfg.h
> - Rename ACPI table portion to arch/x86/cpu/qemu/acpi_table.c
>
> Signed-off-by: Tom Rini <tr...@konsulko.com>
> ---
> Changes in v2:
> - Depend on X86 (per Miao Yan)

I am afraid this still doesn't build. At least you need to make the
ACPI stuff depend on the new config option CONFIG_CMD_QEMU_FW_CFG, as
well as some tweaks in qemu.c and mp_init.c because they call
functions from the origin fw_cfg.c and they used to be guarded by
CONFIG_QEMU, something like the following diff:


diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ef27dc..efede32 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -444,7 +444,7 @@ config GENERATE_ACPI_TABLE

 config QEMU_ACPI_TABLE
bool "Load ACPI table from QEMU fw_cfg interface"
-   depends on GENERATE_ACPI_TABLE && QEMU
+   depends on GENERATE_ACPI_TABLE && CMD_QEMU_FW_CFG
default y
help
  By default, U-Boot generates its own ACPI tables. This option, if
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 13bec7a..7b870b7 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -420,7 +420,7 @@ static int init_bsp(struct udevice **devp)
return 0;
 }

-#ifdef CONFIG_QEMU
+#ifdef CONFIG_CMD_QEMU_FW_CFG
 static int qemu_cpu_fixup(void)
 {
int ret;
@@ -496,7 +496,7 @@ int mp_init(struct mp_params *p)
if (ret)
return ret;

-#ifdef CONFIG_QEMU
+#ifdef CONFIG_CMD_QEMU_FW_CFG
ret = qemu_cpu_fixup();
if (ret)
return ret;
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 97b965c..d0e146e 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,11 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += cpu.o qemu.o
+
+obj-y += qemu.o
+
+ifdef CONFIG_CMD_QEMU_FW_CFG
+obj-y += cpu.o
 obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
+endif
+
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index b41e4ec..2730a5f 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -88,7 +88,9 @@ static void qemu_chipset_init(void)
enable_pm_ich9();
}

+#ifdef CONFIG_CMD_QEMU_FW_CFG
qemu_fwcfg_init();
+#endif
 }

 int arch_cpu_init(void)




> ---
>  arch/x86/cpu/mp_init.c |   2 +-
>  arch/x86/cpu/qemu/Makefile |   3 +-
>  arch/x86/cpu/qemu/acpi_table.c | 243 ++
>  arch/x86/cpu/qemu/cpu.c|   2 +-
>  arch/x86/cpu/qemu/fw_cfg.c | 570 
> -
>  arch/x86/cpu/qemu/qemu.c   |   2 +-
>  arch/x86/include/asm/fw_cfg.h  | 157 
>  arch/x86/lib/acpi_table.c  |   2 +-
>  cmd/Kconfig|   7 +
>  cmd/Makefile   |   1 +
>  cmd/qemu_fw_cfg.c  | 343 +
>  configs/qemu-x86_defconfig |   1 +
>  include/qemu_fw_cfg.h  | 162 
>  13 files changed, 763 insertions(+), 732 deletions(-)
>  create mode 100644 arch/x86/cpu/qemu/acpi_table.c
>  delete mode 100644 arch/x86/cpu/qemu/fw_cfg.c
>  delete mode 100644 arch/x86/include/asm/fw_cfg.h
>  create mode 100644 cmd/qemu_fw_cfg.c
>  create mode 100644 include/qemu_fw_cfg.h
>
> diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
> index 2604a68..13bec7a 100644
> --- a/arch/x86/cpu/mp_init.c
> +++ b/arch/x86/cpu/mp_init.c
> @@ -11,6 +11,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -21,7 +22,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
> index 6eeddf1..97b965c 100644
> --- a/arch/x86/cpu/qemu/Makefile
> +++ b/arch/x86/cpu/qemu/Makefile
> @@ -7,4 +7,5 @@
>  ifndef CONFIG_EFI_STUB
>  obj-y += car.o dram.o
>  endif
> -obj-y += cpu.o fw_cfg.o qemu.o
> +obj-y += cpu.o qemu.o
> +obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
> diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
> new file mode 100644
> index 000..49381ac
> --- /dev/null
> +++ b/arch/x86/cpu/qemu/acpi_table.c
> @@ -0,0 +1,243 @@
> +/*
> + * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
> + *
> + * SPDX-License-Identifier:GPL-2.0+
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * This function allocates memory 

Re: [U-Boot] [PATCH] x86: qemu: Move qfw command over to cmd and add Kconfig entry

2016-05-02 Thread Miao Yan
Hi Tom,

2016-04-30 9:39 GMT+08:00 Tom Rini <tr...@konsulko.com>:
> - Move the command portion of arch/x86/cpu/qemu/fw_cfg.c into
>   cmd/qemu_fw_cfg.c
> - Move arch/x86/include/asm/fw_cfg.h to include/qemu_fw_cfg.h
> - Rename ACPI table portion to arch/x86/cpu/qemu/acpi_table.c
>
> Signed-off-by: Tom Rini <tr...@konsulko.com>
> ---
> The QEMU firmware interface is more generic feature than just x86/qemu so
> we need to start by moving the code out of arch/x86 and into cmd
>
>  arch/x86/cpu/mp_init.c |   2 +-
>  arch/x86/cpu/qemu/Makefile |   3 +-
>  arch/x86/cpu/qemu/acpi_table.c | 243 
>  arch/x86/cpu/qemu/cpu.c|   2 +-
>  arch/x86/cpu/qemu/qemu.c   |   2 +-
>  arch/x86/lib/acpi_table.c  |   2 +-
>  cmd/Kconfig|   6 +
>  cmd/Makefile   |   1 +
>  arch/x86/cpu/qemu/fw_cfg.c => cmd/qemu_fw_cfg.c| 245 
> +
>  configs/qemu-x86_defconfig |   1 +
>  .../include/asm/fw_cfg.h => include/qemu_fw_cfg.h  |   5 +
>  11 files changed, 271 insertions(+), 241 deletions(-)
>  create mode 100644 arch/x86/cpu/qemu/acpi_table.c
>  rename arch/x86/cpu/qemu/fw_cfg.c => cmd/qemu_fw_cfg.c (53%)
>  rename arch/x86/include/asm/fw_cfg.h => include/qemu_fw_cfg.h (94%)
>
> diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
> index 2604a68..13bec7a 100644
> --- a/arch/x86/cpu/mp_init.c
> +++ b/arch/x86/cpu/mp_init.c
> @@ -11,6 +11,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -21,7 +22,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
> index 6eeddf1..97b965c 100644
> --- a/arch/x86/cpu/qemu/Makefile
> +++ b/arch/x86/cpu/qemu/Makefile
> @@ -7,4 +7,5 @@
>  ifndef CONFIG_EFI_STUB
>  obj-y += car.o dram.o
>  endif
> -obj-y += cpu.o fw_cfg.o qemu.o
> +obj-y += cpu.o qemu.o
> +obj-$(CONFIG_QEMU_ACPI_TABLE) += acpi_table.o
> diff --git a/arch/x86/cpu/qemu/acpi_table.c b/arch/x86/cpu/qemu/acpi_table.c
> new file mode 100644
> index 000..49381ac
> --- /dev/null
> +++ b/arch/x86/cpu/qemu/acpi_table.c
> @@ -0,0 +1,243 @@
> +/*
> + * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
> + *
> + * SPDX-License-Identifier:GPL-2.0+
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * This function allocates memory for ACPI tables
> + *
> + * @entry : BIOS linker command entry which tells where to allocate memory
> + *  (either high memory or low memory)
> + * @addr  : The address that should be used for low memory allcation. If the
> + *  memory allocation request is 'ZONE_HIGH' then this parameter will
> + *  be ignored.
> + * @return: 0 on success, or negative value on failure
> + */
> +static int bios_linker_allocate(struct bios_linker_entry *entry, u32 *addr)
> +{
> +   uint32_t size, align;
> +   struct fw_file *file;
> +   unsigned long aligned_addr;
> +
> +   align = le32_to_cpu(entry->alloc.align);
> +   /* align must be power of 2 */
> +   if (align & (align - 1)) {
> +   printf("error: wrong alignment %u\n", align);
> +   return -EINVAL;
> +   }
> +
> +   file = qemu_fwcfg_find_file(entry->alloc.file);
> +   if (!file) {
> +   printf("error: can't find file %s\n", entry->alloc.file);
> +   return -ENOENT;
> +   }
> +
> +   size = be32_to_cpu(file->cfg.size);
> +
> +   /*
> +* ZONE_HIGH means we need to allocate from high memory, since
> +* malloc space is already at the end of RAM, so we directly use it.
> +* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
> +* in which is low memory
> +*/
> +   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
> +   aligned_addr = (unsigned long)memalign(align, size);
> +   if (!aligned_addr) {
> +   printf("error: allocating resource\n");
> +   return -ENOMEM;
> +   }
> +   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
> +   aligned_addr = ALIGN(*addr, align);
&

Re: [U-Boot] [PATCH] x86: Correct typo of Miao Yan's email address

2016-04-13 Thread Miao Yan
2016-04-13 16:00 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Miao Yan's email address is wrong in fw_cfg.c. Fix it.
>
> Signed-off-by: Bin Meng <bmeng...@gmail.com>
> ---
>
>  arch/x86/cpu/qemu/fw_cfg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
> index a0a3d08..2e2794e 100644
> --- a/arch/x86/cpu/qemu/fw_cfg.c
> +++ b/arch/x86/cpu/qemu/fw_cfg.c
> @@ -1,5 +1,5 @@
>  /*
> - * (C) Copyright 2015 Miao Yan <yanmiaoe...@gmail.com>
> + * (C) Copyright 2015 Miao Yan <yanmiaob...@gmail.com>
>   *
>   * SPDX-License-Identifier:GPL-2.0+
>   */
> --
> 1.8.2.1
>

Oops, thanks for catching this, Bin!

Miao
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 3/4] x86: config option for loading ACPI table from QEMU

2016-01-20 Thread Miao Yan
Hi Bin,

2016-01-20 17:18 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Wed, Jan 20, 2016 at 5:15 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Hi Bin,
>>
>> 2016-01-20 16:46 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> On Wed, Jan 20, 2016 at 12:24 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>> This patch adds a config option for loading ACPI table from QEMU. When 
>>>> enabled,
>>>> U-Boot won't generate ACPI tables, but use those provided by QEMU.
>>>>
>>>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>>> ---
>>>>  arch/x86/Kconfig   | 9 +
>>>>  arch/x86/cpu/qemu/Makefile | 2 ++
>>>>  arch/x86/lib/Makefile  | 2 ++
>>>>  3 files changed, 13 insertions(+)
>>>>
>>>
>>> Reviewed-by: Bin Meng <bmeng...@gmail.com>
>>> Tested-by: Bin Meng <bmeng...@gmail.com>
>>>
>>> But please see one nits below:
>>>
>>>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>>>> index f07567c..26c8d83 100644
>>>> --- a/arch/x86/Kconfig
>>>> +++ b/arch/x86/Kconfig
>>>> @@ -358,6 +358,15 @@ config GENERATE_ACPI_TABLE
>>>>   by the operating system. It defines platform-independent 
>>>> interfaces
>>>>   for configuration and power management monitoring.
>>>>
>>>> +config QEMU_ACPI_TABLE
>>>> +   bool "load ACPI table from QEMU fw_cfg interface"
>>>
>>> nits: load -> Load
>>>
>>> I can fix this when applying.
>>
>> Thanks, I just found this patch breaks git bisect, I'll submit v3 to
>> fix this as well as the typo.
>>
>>
>
> Uh, I've tested building your patches via buildman, no errors. What do you 
> see?

If you enable CONFIG_GENERATE_ACPI_TABLE and QEMU_ACPI_TABLE, you'll see:

arch/x86/lib/built-in.o: In function `write_tables':
/home/myan/work/u-boot-x86/arch/x86/lib/tables.c:57: undefined
reference to `write_acpi_tables'
make: *** [u-boot] Error

Because write_acpi_tables() are defined in [PATCH 0/4]. With default
config you won't see it. Is this OK ?


>
>>>
>>>> +   depends on GENERATE_ACPI_TABLE && QEMU
>>>> +   default y
>>>> +   help
>>>> + By default, U-Boot generates its own ACPI tables. This option, if
>>>> + enabled, disables U-Boot's version and loads ACPI tables 
>>>> generated
>>>> + by QEMU.
>>>> +
>>>
>>> [snip]
>>>
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 3/4] x86: config option for loading ACPI table from QEMU

2016-01-20 Thread Miao Yan
Hi Bin,

2016-01-20 16:46 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> On Wed, Jan 20, 2016 at 12:24 PM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> This patch adds a config option for loading ACPI table from QEMU. When 
>> enabled,
>> U-Boot won't generate ACPI tables, but use those provided by QEMU.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/Kconfig   | 9 +
>>  arch/x86/cpu/qemu/Makefile | 2 ++
>>  arch/x86/lib/Makefile  | 2 ++
>>  3 files changed, 13 insertions(+)
>>
>
> Reviewed-by: Bin Meng <bmeng...@gmail.com>
> Tested-by: Bin Meng <bmeng...@gmail.com>
>
> But please see one nits below:
>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index f07567c..26c8d83 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -358,6 +358,15 @@ config GENERATE_ACPI_TABLE
>>   by the operating system. It defines platform-independent interfaces
>>   for configuration and power management monitoring.
>>
>> +config QEMU_ACPI_TABLE
>> +   bool "load ACPI table from QEMU fw_cfg interface"
>
> nits: load -> Load
>
> I can fix this when applying.

Thanks, I just found this patch breaks git bisect, I'll submit v3 to
fix this as well as the typo.


>
>> +   depends on GENERATE_ACPI_TABLE && QEMU
>> +   default y
>> +   help
>> + By default, U-Boot generates its own ACPI tables. This option, if
>> + enabled, disables U-Boot's version and loads ACPI tables generated
>> + by QEMU.
>> +
>
> [snip]
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 1/4] x86: qemu: re-structure qemu_fwcfg_list_firmware()

2016-01-20 Thread Miao Yan
Re-write the logic in qemu_fwcfg_list_firmware(), add a function
qemu_fwcfg_read_firmware_list() to handle reading firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/qemu/fw_cfg.c| 63 +--
 arch/x86/include/asm/fw_cfg.h |  9 ---
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index 0599214..bcd34af 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,10 +10,13 @@
 #include 
 #include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
 
+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)
@@ -162,29 +165,61 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void 
*initrd_addr)
return 0;
 }
 
-static int qemu_fwcfg_list_firmware(void)
+static int qemu_fwcfg_read_firmware_list(void)
 {
int i;
uint32_t count;
-   struct fw_cfg_files *files;
+   struct fw_file *file;
+   struct list_head *entry;
+
+   /* don't read it twice */
+   if (!list_empty(_list))
+   return 0;
 
qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, );
if (!count)
return 0;
 
count = be32_to_cpu(count);
-   files = malloc(count * sizeof(struct fw_cfg_file));
-   if (!files)
-   return -ENOMEM;
-
-   files->count = count;
-   qemu_fwcfg_read_entry(FW_CFG_INVALID,
- count * sizeof(struct fw_cfg_file),
- files->files);
-
-   for (i = 0; i < files->count; i++)
-   printf("%-56s\n", files->files[i].name);
-   free(files);
+   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), >cfg);
+   file->addr = 0;
+   list_add_tail(>list, _list);
+   }
+
+   return 0;
+
+err:
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   free(file);
+   }
+
+   return -ENOMEM;
+}
+
+static int qemu_fwcfg_list_firmware(void)
+{
+   int ret;
+   struct list_head *entry;
+   struct fw_file *file;
+
+   /* make sure fw_list is loaded */
+   ret = qemu_fwcfg_read_firmware_list();
+   if (ret)
+   return ret;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   printf("%-56s\n", file->cfg.name);
+   }
+
return 0;
 }
 
diff --git a/arch/x86/include/asm/fw_cfg.h b/arch/x86/include/asm/fw_cfg.h
index fb110fa..2acf43e 100644
--- a/arch/x86/include/asm/fw_cfg.h
+++ b/arch/x86/include/asm/fw_cfg.h
@@ -12,6 +12,8 @@
 #define FW_DMA_PORT_LOW0x514
 #define FW_DMA_PORT_HIGH   0x518
 
+#include 
+
 enum qemu_fwcfg_items {
FW_CFG_SIGNATURE= 0x00,
FW_CFG_ID   = 0x01,
@@ -67,9 +69,10 @@ struct fw_cfg_file {
char name[FW_CFG_MAX_FILE_PATH];
 };
 
-struct fw_cfg_files {
-   __be32 count;
-   struct fw_cfg_file files[];
+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_dma_access {
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 4/4] x86: config option for loading ACPI table from QEMU

2016-01-20 Thread Miao Yan
This patch adds a config option for loading ACPI table from QEMU. When enabled,
U-Boot won't generate ACPI tables, but use those provided by QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v3:
  - fix a build error
  - make it [PATCH 4/4]

 arch/x86/Kconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f07567c..a995e32 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -358,6 +358,15 @@ config GENERATE_ACPI_TABLE
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
+config QEMU_ACPI_TABLE
+   bool "Load ACPI table from QEMU fw_cfg interface"
+   depends on GENERATE_ACPI_TABLE && QEMU
+   default y
+   help
+ By default, U-Boot generates its own ACPI tables. This option, if
+ enabled, disables U-Boot's version and loads ACPI tables generated
+ by QEMU.
+
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 2/4] x86: qemu: setup PM IO base for ACPI in southbridge

2016-01-20 Thread Miao Yan
Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/qemu/Kconfig   |  7 +++
 arch/x86/cpu/qemu/qemu.c| 29 +
 arch/x86/include/asm/arch-qemu/device.h |  2 ++
 arch/x86/include/asm/arch-qemu/qemu.h   |  5 +
 4 files changed, 43 insertions(+)

diff --git a/arch/x86/cpu/qemu/Kconfig b/arch/x86/cpu/qemu/Kconfig
index 4f98621..6808c9a 100644
--- a/arch/x86/cpu/qemu/Kconfig
+++ b/arch/x86/cpu/qemu/Kconfig
@@ -17,4 +17,11 @@ config SYS_CAR_SIZE
hex
default 0x1
 
+config ACPI_PM1_BASE
+   hex
+   default 0xe400
+   help
+ ACPI Power Managment 1 (PM1) i/o-mapped base address.
+ This device is defined in ACPI specification, with 16 bytes in size.
+
 endif
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 46111c9..b794cfe 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,6 +15,31 @@
 
 static bool i440fx;
 
+static void enable_pm_piix(void)
+{
+   u8 en;
+   u16 cmd;
+
+   /* Set the PM I/O base */
+   x86_pci_write_config32(PIIX_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+
+   /* Enable access to the PM I/O space */
+   cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
+   cmd |= PCI_COMMAND_IO;
+   x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
+
+   /* PM I/O Space Enable (PMIOSE) */
+   en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
+   en |= PMIOSE;
+   x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
+}
+
+static void enable_pm_ich9(void)
+{
+   /* Set the PM I/O base */
+   x86_pci_write_config32(ICH9_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+}
+
 static void qemu_chipset_init(void)
 {
u16 device, xbcs;
@@ -53,10 +78,14 @@ static void qemu_chipset_init(void)
xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
xbcs |= APIC_EN;
x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
+
+   enable_pm_piix();
} else {
/* Configure PCIe ECAM base address */
x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
   CONFIG_PCIE_ECAM_BASE | BAR_EN);
+
+   enable_pm_ich9();
}
 
qemu_fwcfg_init();
diff --git a/arch/x86/include/asm/arch-qemu/device.h 
b/arch/x86/include/asm/arch-qemu/device.h
index 75a435e..38ab798 100644
--- a/arch/x86/include/asm/arch-qemu/device.h
+++ b/arch/x86/include/asm/arch-qemu/device.h
@@ -13,6 +13,8 @@
 #define PIIX_ISA   PCI_BDF(0, 1, 0)
 #define PIIX_IDE   PCI_BDF(0, 1, 1)
 #define PIIX_USB   PCI_BDF(0, 1, 2)
+#define PIIX_PMPCI_BDF(0, 1, 3)
+#define ICH9_PMPCI_BDF(0, 0x1f, 0)
 #define I440FX_VGA PCI_BDF(0, 2, 0)
 
 #define QEMU_Q35   PCI_BDF(0, 0, 0)
diff --git a/arch/x86/include/asm/arch-qemu/qemu.h 
b/arch/x86/include/asm/arch-qemu/qemu.h
index b67d342..a85eee8 100644
--- a/arch/x86/include/asm/arch-qemu/qemu.h
+++ b/arch/x86/include/asm/arch-qemu/qemu.h
@@ -33,4 +33,9 @@
 #define LOW_RAM_ADDR   0x34
 #define HIGH_RAM_ADDR  0x35
 
+/* PM registers */
+#define PMBA   0x40
+#define PMREGMISC  0x80
+#define PMIOSE (1 << 0)
+
 #endif /* _ARCH_QEMU_H_ */
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 0/4] add support for loading ACPI tables from QEMU

2016-01-20 Thread Miao Yan
Currently, if CONFIG_GENERATE_ACPI_TABLE is defined, U-Boot will generate ACPI
tables itlself, this patchset adds the ability to load the ACPI tables generated
by QEMU.

Changes in v3:
  - fix a build error in patch 3/4
  - re-order patch 3/4 and patch 4/4 in v2

Changes in v2:
  - Drop [PATCH 4/4] x86: qemu: loading ACPI table from QEMU, add a config 
option
CONFIG_QEMU_ACPI_TABLE
  - various cleanups

Miao Yan (4):
  x86: qemu: re-structure qemu_fwcfg_list_firmware()
  x86: qemu: setup PM IO base for ACPI in southbridge
  x86: qemu: add the ability to load and link ACPI tables from QEMU
  x86: config option for loading ACPI table from QEMU

 arch/x86/Kconfig|   9 +
 arch/x86/cpu/qemu/Kconfig   |   7 +
 arch/x86/cpu/qemu/Makefile  |   2 +
 arch/x86/cpu/qemu/fw_cfg.c  | 316 ++--
 arch/x86/cpu/qemu/qemu.c|  29 +++
 arch/x86/include/asm/arch-qemu/device.h |   2 +
 arch/x86/include/asm/arch-qemu/qemu.h   |   5 +
 arch/x86/include/asm/fw_cfg.h   |  70 ++-
 arch/x86/lib/Makefile   |   2 +
 arch/x86/lib/acpi_table.c   |   4 +
 10 files changed, 429 insertions(+), 17 deletions(-)

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 3/4] x86: qemu: add the ability to load and link ACPI tables from QEMU

2016-01-20 Thread Miao Yan
This patch adds the ability to load and link ACPI tables provided by QEMU.
QEMU tells guests how to load and patch ACPI tables through its fw_cfg
interface, by adding a firmware file 'etc/table-loader'. Guests are
supposed to parse this file and execute corresponding QEMU commands.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
Change in v3:
  - fix a build error
  - make it [PATCH 3/4]

 arch/x86/cpu/qemu/Makefile|   2 +
 arch/x86/cpu/qemu/fw_cfg.c| 253 ++
 arch/x86/include/asm/fw_cfg.h |  61 ++
 arch/x86/lib/Makefile |   2 +
 arch/x86/lib/acpi_table.c |   4 +
 5 files changed, 322 insertions(+)

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 176ea54..801413a 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,4 +8,6 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o fw_cfg.o qemu.o
+ifndef CONFIG_QEMU_ACPI_TABLE
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
+endif
diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index bcd34af..5ea7a6e 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,7 +10,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
@@ -204,6 +207,256 @@ err:
return -ENOMEM;
 }
 
+#ifdef CONFIG_QEMU_ACPI_TABLE
+static struct fw_file *qemu_fwcfg_find_file(const char *name)
+{
+   struct list_head *entry;
+   struct fw_file *file;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   if (!strcmp(file->cfg.name, name))
+   return file;
+   }
+
+   return NULL;
+}
+
+/*
+ * This function allocates memory for ACPI tables
+ *
+ * @entry : BIOS linker command entry which tells where to allocate memory
+ *  (either high memory or low memory)
+ * @addr  : The address that should be used for low memory allcation. If the
+ *  memory allocation request is 'ZONE_HIGH' then this parameter will
+ *  be ignored.
+ * @return: 0 on success, or negative value on failure
+ */
+static int bios_linker_allocate(struct bios_linker_entry *entry,
+  unsigned long *addr)
+{
+   uint32_t size, align;
+   struct fw_file *file;
+   unsigned long aligned_addr;
+
+   align = le32_to_cpu(entry->alloc.align);
+   /* align must be power of 2 */
+   if (align & (align - 1)) {
+   printf("error: wrong alignment %u\n", align);
+   return -EINVAL;
+   }
+
+   file = qemu_fwcfg_find_file(entry->alloc.file);
+   if (!file) {
+   printf("error: can't find file %s\n", entry->alloc.file);
+   return -ENOENT;
+   }
+
+   size = be32_to_cpu(file->cfg.size);
+
+   /*
+* ZONE_HIGH means we need to allocate from high memory, since
+* malloc space is already at the end of RAM, so we directly use it.
+* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
+* in which is low memory
+*/
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
+   aligned_addr = (unsigned long)memalign(align, size);
+   if (!aligned_addr) {
+   printf("error: allocating resource\n");
+   return -ENOMEM;
+   }
+   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
+   aligned_addr = ALIGN(*addr, align);
+   } else {
+   printf("error: invalid allocation zone\n");
+   return -EINVAL;
+   }
+
+   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
+ file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
+
+   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
+ size, (void *)aligned_addr);
+   file->addr = aligned_addr;
+
+   /* adjust address for low memory allocation */
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
+   *addr = (aligned_addr + size);
+
+   return 0;
+}
+
+/*
+ * This function patches ACPI tables previously loaded
+ * by bios_linker_allocate()
+ *
+ * @entry : BIOS linker command entry which tells how to patch
+ *  ACPI tables
+ * @return: 0 on success, or negative value on failure
+ */
+static int bios_linker_add_pointer(struct bios_linker_entry *entry)
+{
+   struct fw_file *dest, *src;
+   uint32_t offset = le32_to_cpu(entry->pointer.offset);
+   uint64_t pointer = 0;
+
+   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
+   if

Re: [U-Boot] [PATCH 2/4] x86: qemu: setup PM IO base for ACPI in southbridge

2016-01-19 Thread Miao Yan
Hi Bin,

2016-01-19 17:25 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Tue, Jan 19, 2016 at 10:46 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Hi Bin,
>>
>> 2016-01-16 21:23 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
>>> Hi Miao,
>>>
>>> On Fri, Jan 15, 2016 at 11:12 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>>>> Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)
>>>>
>>>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>>>> ---
>>>>  arch/x86/cpu/qemu/qemu.c| 39 
>>>> +
>>>>  arch/x86/include/asm/arch-qemu/device.h |  8 +++
>>>>  2 files changed, 47 insertions(+)
>>>>
>>>> diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
>>>> index 46111c9..e7d8a6c 100644
>>>> --- a/arch/x86/cpu/qemu/qemu.c
>>>> +++ b/arch/x86/cpu/qemu/qemu.c
>>>> @@ -15,6 +15,41 @@
>>>>
>>>>  static bool i440fx;
>>>>
>>>> +static void enable_pm_piix(void)
>>>> +{
>>>> +   u8 en;
>>>> +   u16 device, cmd;
>>>> +
>>>> +   device = x86_pci_read_config16(PIIX_PM, PCI_DEVICE_ID);
>>>> +   if (device != PCI_DEVICE_ID_INTEL_82371AB_3)
>>>> +   return;
>>>
>>> Guess the check is already covered in qemu_chipset_init().
>>
>>
>> Do you mean this check ?
>>
>> device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
>> i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
>>
>> So is it guaranteed that PIIX_PM is always on that BDF ?
>
> I believe so. If you look at the codes in qemu.c, the variable "static
> bool i440fx" is used to distinguish QEMU machine pc and q35. It does
> not check whether the chipset is i440fx, or PIIX which is the chipset
> connected to i440fx.
>
>>
>> IMO, we are operating on another chipset, and we better make
>> sure it's the one we expect, besides, an extra check won't do any harm.
>>
>
> Yes, that makes sense. So if we go with your way, maybe we need expand
> "static bool i440fx" to multiple variables and use correct variable to
> check? But this looks a bit complex than a single variable.
>

Yes, that's a little bit complex and not necessary if their PCI
addresses are fixed . And I don't think we should do it in this
patchset.

So how do you suggest we do this ? Either I remove the two checks to
make it aligned with the rest or create a separate patch to do the
checks ?



>>
>>>
>>>> +
>>>> +   /* Set the PM I/O base. */
>>>
>>> nits: please remove the ending period. Please fix this globally in this 
>>> file.
>>>
>>>> +   x86_pci_write_config32(PIIX_PM, PMBA, DEFAULT_PMBASE | 1);
>>>> +
>>>> +   /* Enable access to the PM I/O space. */
>>>> +   cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
>>>> +   cmd |= PCI_COMMAND_IO;
>>>> +   x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
>>>> +
>>>> +   /* PM I/O Space Enable (PMIOSE). */
>>>> +   en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
>>>> +   en |= PMIOSE;
>>>> +   x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
>>>> +}
>>>> +
>>>> +static void enable_pm_ich9(void)
>>>> +{
>>>> +   u16 device;
>>>> +
>>>> +   device = x86_pci_read_config16(ICH9_PM, PCI_DEVICE_ID);
>>>> +   if (device != PCI_DEVICE_ID_INTEL_ICH9_8)
>>>> +   return;
>>>
>>> Guess the check is already covered in qemu_chipset_init().
>>>
>>>> +
>>>> +   /* Set the PM I/O base. */
>>>> +   x86_pci_write_config32(ICH9_PM, PMBA, DEFAULT_PMBASE | 1);
>>>> +}
>>>> +
>>>>  static void qemu_chipset_init(void)
>>>>  {
>>>> u16 device, xbcs;
>>>> @@ -53,10 +88,14 @@ static void qemu_chipset_init(void)
>>>> xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
>>>> xbcs |= APIC_EN;
>>>> x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
>>>> +
>>>> +   enable_pm_piix();
>>>> } else {
>>>> /* Configure PCIe ECAM base address */
>>>> x86_pci_wri

[U-Boot] [PATCH v2 4/4] x86: qemu: add the ability to load and link ACPI tables from QEMU

2016-01-19 Thread Miao Yan
This patch adds the ability to load and link ACPI tables provided by QEMU.
QEMU tells guests how to load and patch ACPI tables through its fw_cfg
interface, by adding a firmware file 'etc/table-loader'. Guests are
supposed to parse this file and execute corresponding QEMU commands.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v2:
  - add function comment
  - improve error handling

 arch/x86/cpu/qemu/fw_cfg.c| 253 ++
 arch/x86/include/asm/fw_cfg.h |  61 ++
 arch/x86/lib/acpi_table.c |   4 +
 3 files changed, 318 insertions(+)

diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index bcd34af..5ea7a6e 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,7 +10,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
@@ -204,6 +207,256 @@ err:
return -ENOMEM;
 }
 
+#ifdef CONFIG_QEMU_ACPI_TABLE
+static struct fw_file *qemu_fwcfg_find_file(const char *name)
+{
+   struct list_head *entry;
+   struct fw_file *file;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   if (!strcmp(file->cfg.name, name))
+   return file;
+   }
+
+   return NULL;
+}
+
+/*
+ * This function allocates memory for ACPI tables
+ *
+ * @entry : BIOS linker command entry which tells where to allocate memory
+ *  (either high memory or low memory)
+ * @addr  : The address that should be used for low memory allcation. If the
+ *  memory allocation request is 'ZONE_HIGH' then this parameter will
+ *  be ignored.
+ * @return: 0 on success, or negative value on failure
+ */
+static int bios_linker_allocate(struct bios_linker_entry *entry,
+  unsigned long *addr)
+{
+   uint32_t size, align;
+   struct fw_file *file;
+   unsigned long aligned_addr;
+
+   align = le32_to_cpu(entry->alloc.align);
+   /* align must be power of 2 */
+   if (align & (align - 1)) {
+   printf("error: wrong alignment %u\n", align);
+   return -EINVAL;
+   }
+
+   file = qemu_fwcfg_find_file(entry->alloc.file);
+   if (!file) {
+   printf("error: can't find file %s\n", entry->alloc.file);
+   return -ENOENT;
+   }
+
+   size = be32_to_cpu(file->cfg.size);
+
+   /*
+* ZONE_HIGH means we need to allocate from high memory, since
+* malloc space is already at the end of RAM, so we directly use it.
+* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
+* in which is low memory
+*/
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
+   aligned_addr = (unsigned long)memalign(align, size);
+   if (!aligned_addr) {
+   printf("error: allocating resource\n");
+   return -ENOMEM;
+   }
+   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
+   aligned_addr = ALIGN(*addr, align);
+   } else {
+   printf("error: invalid allocation zone\n");
+   return -EINVAL;
+   }
+
+   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
+ file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
+
+   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
+ size, (void *)aligned_addr);
+   file->addr = aligned_addr;
+
+   /* adjust address for low memory allocation */
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
+   *addr = (aligned_addr + size);
+
+   return 0;
+}
+
+/*
+ * This function patches ACPI tables previously loaded
+ * by bios_linker_allocate()
+ *
+ * @entry : BIOS linker command entry which tells how to patch
+ *  ACPI tables
+ * @return: 0 on success, or negative value on failure
+ */
+static int bios_linker_add_pointer(struct bios_linker_entry *entry)
+{
+   struct fw_file *dest, *src;
+   uint32_t offset = le32_to_cpu(entry->pointer.offset);
+   uint64_t pointer = 0;
+
+   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
+   if (!dest || !dest->addr)
+   return -ENOENT;
+   src = qemu_fwcfg_find_file(entry->pointer.src_file);
+   if (!src || !src->addr)
+   return -ENOENT;
+
+   debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, 
offset 0x%x size %u, 0x%llx\n",
+ dest->addr, src->addr, offset, entry->pointer.size, pointer);
+
+   memcpy(, (char *)dest->addr + offset, entry->pointer.size);
+   pointer = le64_to_cpu(pointer);
+   

[U-Boot] [PATCH v2 0/4] add support for loading ACPI tables from QEMU

2016-01-19 Thread Miao Yan
Currently, if CONFIG_GENERATE_ACPI_TABLE is defined, U-Boot will generate ACPI
tables itlself, this patchset adds the ability to load the ACPI tables generated
by QEMU.

Changes in v2:
  - Drop [PATCH 4/4] x86: qemu: loading ACPI table from QEMU, add a config 
option
CONFIG_QEMU_ACPI_TABLE
  - various cleanups

Miao Yan (4):
  x86: qemu: re-structure qemu_fwcfg_list_firmware()
  x86: qemu: setup PM IO base for ACPI in southbridge
  x86: config option for loading ACPI table from QEMU
  x86: qemu: add the ability to load and link ACPI tables from QEMU

 arch/x86/Kconfig|   9 +
 arch/x86/cpu/qemu/Kconfig   |   7 +
 arch/x86/cpu/qemu/Makefile  |   2 +
 arch/x86/cpu/qemu/fw_cfg.c  | 316 ++--
 arch/x86/cpu/qemu/qemu.c|  29 +++
 arch/x86/include/asm/arch-qemu/device.h |   2 +
 arch/x86/include/asm/arch-qemu/qemu.h   |   5 +
 arch/x86/include/asm/fw_cfg.h   |  70 ++-
 arch/x86/lib/Makefile   |   2 +
 arch/x86/lib/acpi_table.c   |   4 +
 10 files changed, 429 insertions(+), 17 deletions(-)

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 1/4] x86: qemu: re-structure qemu_fwcfg_list_firmware()

2016-01-19 Thread Miao Yan
Re-write the logic in qemu_fwcfg_list_firmware(), add a function
qemu_fwcfg_read_firmware_list() to handle reading firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v2:
  - coding style fix
  - add comments in header file

 arch/x86/cpu/qemu/fw_cfg.c| 63 +--
 arch/x86/include/asm/fw_cfg.h |  9 ---
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index 0599214..bcd34af 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,10 +10,13 @@
 #include 
 #include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
 
+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)
@@ -162,29 +165,61 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void 
*initrd_addr)
return 0;
 }
 
-static int qemu_fwcfg_list_firmware(void)
+static int qemu_fwcfg_read_firmware_list(void)
 {
int i;
uint32_t count;
-   struct fw_cfg_files *files;
+   struct fw_file *file;
+   struct list_head *entry;
+
+   /* don't read it twice */
+   if (!list_empty(_list))
+   return 0;
 
qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, );
if (!count)
return 0;
 
count = be32_to_cpu(count);
-   files = malloc(count * sizeof(struct fw_cfg_file));
-   if (!files)
-   return -ENOMEM;
-
-   files->count = count;
-   qemu_fwcfg_read_entry(FW_CFG_INVALID,
- count * sizeof(struct fw_cfg_file),
- files->files);
-
-   for (i = 0; i < files->count; i++)
-   printf("%-56s\n", files->files[i].name);
-   free(files);
+   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), >cfg);
+   file->addr = 0;
+   list_add_tail(>list, _list);
+   }
+
+   return 0;
+
+err:
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   free(file);
+   }
+
+   return -ENOMEM;
+}
+
+static int qemu_fwcfg_list_firmware(void)
+{
+   int ret;
+   struct list_head *entry;
+   struct fw_file *file;
+
+   /* make sure fw_list is loaded */
+   ret = qemu_fwcfg_read_firmware_list();
+   if (ret)
+   return ret;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   printf("%-56s\n", file->cfg.name);
+   }
+
return 0;
 }
 
diff --git a/arch/x86/include/asm/fw_cfg.h b/arch/x86/include/asm/fw_cfg.h
index fb110fa..2acf43e 100644
--- a/arch/x86/include/asm/fw_cfg.h
+++ b/arch/x86/include/asm/fw_cfg.h
@@ -12,6 +12,8 @@
 #define FW_DMA_PORT_LOW0x514
 #define FW_DMA_PORT_HIGH   0x518
 
+#include 
+
 enum qemu_fwcfg_items {
FW_CFG_SIGNATURE= 0x00,
FW_CFG_ID   = 0x01,
@@ -67,9 +69,10 @@ struct fw_cfg_file {
char name[FW_CFG_MAX_FILE_PATH];
 };
 
-struct fw_cfg_files {
-   __be32 count;
-   struct fw_cfg_file files[];
+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_dma_access {
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 3/4] x86: config option for loading ACPI table from QEMU

2016-01-19 Thread Miao Yan
This patch adds a config option for loading ACPI table from QEMU. When enabled,
U-Boot won't generate ACPI tables, but use those provided by QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/Kconfig   | 9 +
 arch/x86/cpu/qemu/Makefile | 2 ++
 arch/x86/lib/Makefile  | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f07567c..26c8d83 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -358,6 +358,15 @@ config GENERATE_ACPI_TABLE
  by the operating system. It defines platform-independent interfaces
  for configuration and power management monitoring.
 
+config QEMU_ACPI_TABLE
+   bool "load ACPI table from QEMU fw_cfg interface"
+   depends on GENERATE_ACPI_TABLE && QEMU
+   default y
+   help
+ By default, U-Boot generates its own ACPI tables. This option, if
+ enabled, disables U-Boot's version and loads ACPI tables generated
+ by QEMU.
+
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 176ea54..801413a 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -8,4 +8,6 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o fw_cfg.o qemu.o
+ifndef CONFIG_QEMU_ACPI_TABLE
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
+endif
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index cd5ecb6..75719e3 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -32,7 +32,9 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y  += string.o
+ifndef CONFIG_QEMU_ACPI_TABLE
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+endif
 obj-y  += tables.o
 obj-$(CONFIG_CMD_ZBOOT)+= zimage.o
 obj-$(CONFIG_HAVE_FSP) += fsp/
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 2/4] x86: qemu: setup PM IO base for ACPI in southbridge

2016-01-19 Thread Miao Yan
Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
Changes in v2:
  - add ACPI_PM1_BASE in Kconfig
  - drop PCI device ID checks

 arch/x86/cpu/qemu/Kconfig   |  7 +++
 arch/x86/cpu/qemu/qemu.c| 29 +
 arch/x86/include/asm/arch-qemu/device.h |  2 ++
 arch/x86/include/asm/arch-qemu/qemu.h   |  5 +
 4 files changed, 43 insertions(+)

diff --git a/arch/x86/cpu/qemu/Kconfig b/arch/x86/cpu/qemu/Kconfig
index 4f98621..6808c9a 100644
--- a/arch/x86/cpu/qemu/Kconfig
+++ b/arch/x86/cpu/qemu/Kconfig
@@ -17,4 +17,11 @@ config SYS_CAR_SIZE
hex
default 0x1
 
+config ACPI_PM1_BASE
+   hex
+   default 0xe400
+   help
+ ACPI Power Managment 1 (PM1) i/o-mapped base address.
+ This device is defined in ACPI specification, with 16 bytes in size.
+
 endif
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 46111c9..b794cfe 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,6 +15,31 @@
 
 static bool i440fx;
 
+static void enable_pm_piix(void)
+{
+   u8 en;
+   u16 cmd;
+
+   /* Set the PM I/O base */
+   x86_pci_write_config32(PIIX_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+
+   /* Enable access to the PM I/O space */
+   cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
+   cmd |= PCI_COMMAND_IO;
+   x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
+
+   /* PM I/O Space Enable (PMIOSE) */
+   en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
+   en |= PMIOSE;
+   x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
+}
+
+static void enable_pm_ich9(void)
+{
+   /* Set the PM I/O base */
+   x86_pci_write_config32(ICH9_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+}
+
 static void qemu_chipset_init(void)
 {
u16 device, xbcs;
@@ -53,10 +78,14 @@ static void qemu_chipset_init(void)
xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
xbcs |= APIC_EN;
x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
+
+   enable_pm_piix();
} else {
/* Configure PCIe ECAM base address */
x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
   CONFIG_PCIE_ECAM_BASE | BAR_EN);
+
+   enable_pm_ich9();
}
 
qemu_fwcfg_init();
diff --git a/arch/x86/include/asm/arch-qemu/device.h 
b/arch/x86/include/asm/arch-qemu/device.h
index 75a435e..38ab798 100644
--- a/arch/x86/include/asm/arch-qemu/device.h
+++ b/arch/x86/include/asm/arch-qemu/device.h
@@ -13,6 +13,8 @@
 #define PIIX_ISA   PCI_BDF(0, 1, 0)
 #define PIIX_IDE   PCI_BDF(0, 1, 1)
 #define PIIX_USB   PCI_BDF(0, 1, 2)
+#define PIIX_PMPCI_BDF(0, 1, 3)
+#define ICH9_PMPCI_BDF(0, 0x1f, 0)
 #define I440FX_VGA PCI_BDF(0, 2, 0)
 
 #define QEMU_Q35   PCI_BDF(0, 0, 0)
diff --git a/arch/x86/include/asm/arch-qemu/qemu.h 
b/arch/x86/include/asm/arch-qemu/qemu.h
index b67d342..a85eee8 100644
--- a/arch/x86/include/asm/arch-qemu/qemu.h
+++ b/arch/x86/include/asm/arch-qemu/qemu.h
@@ -33,4 +33,9 @@
 #define LOW_RAM_ADDR   0x34
 #define HIGH_RAM_ADDR  0x35
 
+/* PM registers */
+#define PMBA   0x40
+#define PMREGMISC  0x80
+#define PMIOSE (1 << 0)
+
 #endif /* _ARCH_QEMU_H_ */
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 3/4] x86: qemu: add the ability to load and link ACPI tables from QEMU

2016-01-18 Thread Miao Yan
Hi Bin,

2016-01-16 21:24 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, Jan 15, 2016 at 11:12 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> This patch adds the ability to load and link ACPI tables provided by QEMU.
>> QEMU tells guests how to load and patch ACPI tables through its fw_cfg
>> interface, by adding a firmware file 'etc/table-loader'. Guests are
>> supposed to parse this file and execute corresponding QEMU commands.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/cpu/qemu/fw_cfg.c| 214 
>> ++
>>  arch/x86/include/asm/fw_cfg.h |  70 ++
>>  2 files changed, 284 insertions(+)
>>
>> diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
>> index b22026c..755676c 100644
>> --- a/arch/x86/cpu/qemu/fw_cfg.c
>> +++ b/arch/x86/cpu/qemu/fw_cfg.c
>> @@ -10,7 +10,10 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +#include 
>>  #include 
>> +#include 
>>
>>  static bool fwcfg_present;
>>  static bool fwcfg_dma_present;
>> @@ -202,6 +205,217 @@ err:
>> return -ENOMEM;
>>  }
>>
>> +static struct fw_file *qemu_fwcfg_find_file(const char *name)
>> +{
>> +   struct list_head *entry;
>> +   struct fw_file *file;
>> +
>> +   list_for_each(entry, _list) {
>> +   file = list_entry(entry, struct fw_file, list);
>> +   if (!strcmp(file->cfg.name, name))
>> +   return file;
>> +   }
>> +
>> +   return NULL;
>> +}
>> +
>> +static int bios_linker_allocate(struct bios_linker_entry *entry,
>> +  unsigned long *addr)
>
> Please add a comment block for what this function is doing, its
> parameters, return value, etc. Please do the same for the other 2
> functions below.
>
>> +{
>> +   uint32_t size, align;
>> +   struct fw_file *file;
>> +   unsigned long aligned_addr;
>> +
>> +   align = le32_to_cpu(entry->alloc.align);
>> +   /* align must be power of 2 */
>> +   if (align & (align - 1)) {
>> +   printf("error: wrong alignment %u\n", align);
>> +   return -EINVAL;
>> +   }
>> +
>> +   file = qemu_fwcfg_find_file(entry->alloc.file);
>> +   if (!file) {
>> +   printf("error: can't find file %s\n", entry->alloc.file);
>> +   return -ENOENT;
>> +   }
>> +
>> +   size = be32_to_cpu(file->cfg.size);
>> +
>> +   /*
>> +* ZONE_HIGH means we need to allocate from high memory, since
>> +* malloc space is already at the end of RAM, so we directly use it.
>> +* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
>> +* in which is low memory
>> +*/
>> +   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
>> +   aligned_addr = (unsigned long)memalign(align, size);
>> +   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
>> +   aligned_addr = ALIGN(*addr, align);
>> +   } else {
>> +   printf("error: invalid allocation zone\n");
>> +   return -EINVAL;
>> +   }
>> +
>> +   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, 
>> align %u, addr 0x%lx\n",
>> + file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
>> +
>> +   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
>> + size, (void *)aligned_addr);
>> +   file->addr = aligned_addr;
>> +
>> +   /* adjust address for low memory allocation */
>> +   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
>> +   *addr = (aligned_addr + size);
>> +
>> +   return 0;
>> +}
>> +
>> +static int bios_linker_add_pointer(struct bios_linker_entry *entry)
>> +{
>> +   struct fw_file *dest, *src;
>> +   uint32_t offset = le32_to_cpu(entry->pointer.offset);
>> +   uint64_t pointer = 0;
>> +
>> +   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
>> +   if (!dest || !dest->addr)
>> +   return -ENOENT;
>> +   src = qemu_fwcfg_find_file(entry->pointer.src_file);
>> +   if (!src || !src->addr)
>> +  

Re: [U-Boot] [PATCH 4/4] x86: qemu: loading ACPI table from QEMU

2016-01-18 Thread Miao Yan
Hi Bin,

2016-01-16 21:24 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, Jan 15, 2016 at 11:12 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> If CONFIG_GENERATE_ACPI_TABLE is not defined, then use ACPI table created
>> by QEMU.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/lib/tables.c | 5 -
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
>> index 14b15cf..1671385 100644
>> --- a/arch/x86/lib/tables.c
>> +++ b/arch/x86/lib/tables.c
>> @@ -10,6 +10,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>
>>  u8 table_compute_checksum(void *v, int len)
>>  {
>> @@ -55,8 +56,10 @@ void write_tables(void)
>>  #endif
>>  #ifdef CONFIG_GENERATE_ACPI_TABLE
>> rom_table_end = write_acpi_tables(rom_table_end);
>> -   rom_table_end = ALIGN(rom_table_end, 1024);
>> +#else
>> +   rom_table_end = qemu_fwcfg_write_acpi_tables(rom_table_end);
>
> This breaks other x86 boards.Can we hide this changes in acpi_table.c
> with proper #ifdef and some comments?
>
> For QEMU ACPI, how about:
>
> - GENERATE_ACPI_TABLE is the overall switch to turn on ACPI table by U-Boot
> - Introduce another Kconfig option for QEMU to generate ACPI tables
> from firmware interface. If this is turned on, the original method
> provided in acpi_tables.c will not be used.

Sounds OK, I'll drop this one. Thanks.

>
>>  #endif
>> +   rom_table_end = ALIGN(rom_table_end, 1024);
>>  #ifdef CONFIG_GENERATE_SMBIOS_TABLE
>> rom_table_end = write_smbios_table(rom_table_end);
>> rom_table_end = ALIGN(rom_table_end, 1024);
>> --
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/4] x86: qemu: setup PM IO base for ACPI in southbridge

2016-01-18 Thread Miao Yan
Hi Bin,

2016-01-16 21:23 GMT+08:00 Bin Meng <bmeng...@gmail.com>:
> Hi Miao,
>
> On Fri, Jan 15, 2016 at 11:12 AM, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/cpu/qemu/qemu.c| 39 
>> +
>>  arch/x86/include/asm/arch-qemu/device.h |  8 +++
>>  2 files changed, 47 insertions(+)
>>
>> diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
>> index 46111c9..e7d8a6c 100644
>> --- a/arch/x86/cpu/qemu/qemu.c
>> +++ b/arch/x86/cpu/qemu/qemu.c
>> @@ -15,6 +15,41 @@
>>
>>  static bool i440fx;
>>
>> +static void enable_pm_piix(void)
>> +{
>> +   u8 en;
>> +   u16 device, cmd;
>> +
>> +   device = x86_pci_read_config16(PIIX_PM, PCI_DEVICE_ID);
>> +   if (device != PCI_DEVICE_ID_INTEL_82371AB_3)
>> +   return;
>
> Guess the check is already covered in qemu_chipset_init().


Do you mean this check ?

device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
i440fx = (device == PCI_DEVICE_ID_INTEL_82441);

So is it guaranteed that PIIX_PM is always on that BDF ?

IMO, we are operating on another chipset, and we better make
sure it's the one we expect, besides, an extra check won't do any harm.


>
>> +
>> +   /* Set the PM I/O base. */
>
> nits: please remove the ending period. Please fix this globally in this file.
>
>> +   x86_pci_write_config32(PIIX_PM, PMBA, DEFAULT_PMBASE | 1);
>> +
>> +   /* Enable access to the PM I/O space. */
>> +   cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
>> +   cmd |= PCI_COMMAND_IO;
>> +   x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
>> +
>> +   /* PM I/O Space Enable (PMIOSE). */
>> +   en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
>> +   en |= PMIOSE;
>> +   x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
>> +}
>> +
>> +static void enable_pm_ich9(void)
>> +{
>> +   u16 device;
>> +
>> +   device = x86_pci_read_config16(ICH9_PM, PCI_DEVICE_ID);
>> +   if (device != PCI_DEVICE_ID_INTEL_ICH9_8)
>> +   return;
>
> Guess the check is already covered in qemu_chipset_init().
>
>> +
>> +   /* Set the PM I/O base. */
>> +   x86_pci_write_config32(ICH9_PM, PMBA, DEFAULT_PMBASE | 1);
>> +}
>> +
>>  static void qemu_chipset_init(void)
>>  {
>> u16 device, xbcs;
>> @@ -53,10 +88,14 @@ static void qemu_chipset_init(void)
>> xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
>> xbcs |= APIC_EN;
>> x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
>> +
>> +   enable_pm_piix();
>> } else {
>> /* Configure PCIe ECAM base address */
>> x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
>>CONFIG_PCIE_ECAM_BASE | BAR_EN);
>> +
>> +   enable_pm_ich9();
>> }
>>
>> qemu_fwcfg_init();
>> diff --git a/arch/x86/include/asm/arch-qemu/device.h 
>> b/arch/x86/include/asm/arch-qemu/device.h
>> index 75a435e..2e11100 100644
>> --- a/arch/x86/include/asm/arch-qemu/device.h
>> +++ b/arch/x86/include/asm/arch-qemu/device.h
>> @@ -13,9 +13,17 @@
>>  #define PIIX_ISA   PCI_BDF(0, 1, 0)
>>  #define PIIX_IDE   PCI_BDF(0, 1, 1)
>>  #define PIIX_USB   PCI_BDF(0, 1, 2)
>> +#define PIIX_PMPCI_BDF(0, 1, 3)
>> +#define ICH9_PMPCI_BDF(0, 0x1f, 0)
>>  #define I440FX_VGA PCI_BDF(0, 2, 0)
>>
>>  #define QEMU_Q35   PCI_BDF(0, 0, 0)
>>  #define Q35_VGAPCI_BDF(0, 1, 0)
>>
>> +#define PMBA   0x40
>> +#define DEFAULT_PMBASE 0xe400
>
> See arch/x86/cpu/quark/Kconfig we have ACPI_PM1_BASE already. Maybe we
> need consolidate this to introduce a similar one for QEMU.

OK, will fix this.

>
>> +#define PM_IO_BASE DEFAULT_PMBASE
>
> PM_IO_BASE is not referenced anywhere.
>
>> +#define PMREGMISC  0x80
>> +#define PMIOSE (1 << 0)
>> +
>
> Please move these register defines to include/asm/arch-qemu/qemu.h

OK, will fix this.

>
>>  #endif /* _QEMU_DEVICE_H_ */
>> --
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] x86: x86-common.h: Add CONFIG_BOOTDELAY

2016-01-18 Thread Miao Yan
2016-01-18 21:49 GMT+08:00 Stefan Roese <s...@denx.de>:
> Without this CONFIG_BOOTDELAY, autobooting does not work at all. As
> autoboot_command() from common/* will not get called. So lets define
> CONFIG_BOOTDELAY, so that auto-booting works on x86.
>
> Signed-off-by: Stefan Roese <s...@denx.de>
> Cc: Miao Yan <yanmiaob...@gmail.com>
> Cc: Bin Meng <bmeng...@gmail.com>
> Cc: Simon Glass <s...@chromium.org>
> ---
>  include/configs/x86-common.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h
> index 4182a3b..6e73656 100644
> --- a/include/configs/x86-common.h
> +++ b/include/configs/x86-common.h
> @@ -235,4 +235,6 @@
> "tftpboot $loadaddr $bootfile;" \
> "zboot $loadaddr"
>
> +#define CONFIG_BOOTDELAY   2
> +
>  #endif /* __CONFIG_H */
> --
> 2.6.5
>

Tested-by: Miao Yan <yanmiaob...@gmail.com>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/4] x86: qemu: setup PM IO base for ACPI in southbridge

2016-01-14 Thread Miao Yan
Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/qemu.c| 39 +
 arch/x86/include/asm/arch-qemu/device.h |  8 +++
 2 files changed, 47 insertions(+)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 46111c9..e7d8a6c 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,6 +15,41 @@
 
 static bool i440fx;
 
+static void enable_pm_piix(void)
+{
+   u8 en;
+   u16 device, cmd;
+
+   device = x86_pci_read_config16(PIIX_PM, PCI_DEVICE_ID);
+   if (device != PCI_DEVICE_ID_INTEL_82371AB_3)
+   return;
+
+   /* Set the PM I/O base. */
+   x86_pci_write_config32(PIIX_PM, PMBA, DEFAULT_PMBASE | 1);
+
+   /* Enable access to the PM I/O space. */
+   cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
+   cmd |= PCI_COMMAND_IO;
+   x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
+
+   /* PM I/O Space Enable (PMIOSE). */
+   en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
+   en |= PMIOSE;
+   x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
+}
+
+static void enable_pm_ich9(void)
+{
+   u16 device;
+
+   device = x86_pci_read_config16(ICH9_PM, PCI_DEVICE_ID);
+   if (device != PCI_DEVICE_ID_INTEL_ICH9_8)
+   return;
+
+   /* Set the PM I/O base. */
+   x86_pci_write_config32(ICH9_PM, PMBA, DEFAULT_PMBASE | 1);
+}
+
 static void qemu_chipset_init(void)
 {
u16 device, xbcs;
@@ -53,10 +88,14 @@ static void qemu_chipset_init(void)
xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
xbcs |= APIC_EN;
x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
+
+   enable_pm_piix();
} else {
/* Configure PCIe ECAM base address */
x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
   CONFIG_PCIE_ECAM_BASE | BAR_EN);
+
+   enable_pm_ich9();
}
 
qemu_fwcfg_init();
diff --git a/arch/x86/include/asm/arch-qemu/device.h 
b/arch/x86/include/asm/arch-qemu/device.h
index 75a435e..2e11100 100644
--- a/arch/x86/include/asm/arch-qemu/device.h
+++ b/arch/x86/include/asm/arch-qemu/device.h
@@ -13,9 +13,17 @@
 #define PIIX_ISA   PCI_BDF(0, 1, 0)
 #define PIIX_IDE   PCI_BDF(0, 1, 1)
 #define PIIX_USB   PCI_BDF(0, 1, 2)
+#define PIIX_PMPCI_BDF(0, 1, 3)
+#define ICH9_PMPCI_BDF(0, 0x1f, 0)
 #define I440FX_VGA PCI_BDF(0, 2, 0)
 
 #define QEMU_Q35   PCI_BDF(0, 0, 0)
 #define Q35_VGAPCI_BDF(0, 1, 0)
 
+#define PMBA   0x40
+#define DEFAULT_PMBASE 0xe400
+#define PM_IO_BASE DEFAULT_PMBASE
+#define PMREGMISC  0x80
+#define PMIOSE (1 << 0)
+
 #endif /* _QEMU_DEVICE_H_ */
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/4] x86: qemu: re-structure qemu_fwcfg_list_firmware()

2016-01-14 Thread Miao Yan
Re-write the logic in qemu_fwcfg_list_firmware(), add a function
qemu_cfg_read_firmware_list() to handle reading firmware list.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/fw_cfg.c| 60 +--
 arch/x86/include/asm/fw_cfg.h |  8 ++
 2 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index 0599214..b22026c 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,10 +10,13 @@
 #include 
 #include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
 
+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)
@@ -162,29 +165,58 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void 
*initrd_addr)
return 0;
 }
 
-static int qemu_fwcfg_list_firmware(void)
+static int qemu_fwcfg_read_firmware_list(void)
 {
int i;
uint32_t count;
-   struct fw_cfg_files *files;
+   struct fw_file *file;
+   struct list_head *entry;
+
+   /* don't read it twice */
+   if (!list_empty(_list))
+   return 0;
 
qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, );
if (!count)
return 0;
 
count = be32_to_cpu(count);
-   files = malloc(count * sizeof(struct fw_cfg_file));
-   if (!files)
-   return -ENOMEM;
-
-   files->count = count;
-   qemu_fwcfg_read_entry(FW_CFG_INVALID,
- count * sizeof(struct fw_cfg_file),
- files->files);
-
-   for (i = 0; i < files->count; i++)
-   printf("%-56s\n", files->files[i].name);
-   free(files);
+   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), >cfg);
+   file->addr = 0;
+   list_add_tail(>list, _list);
+   }
+   return 0;
+
+err:
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   free(file);
+   }
+   return -ENOMEM;
+}
+
+static int qemu_fwcfg_list_firmware(void)
+{
+   int ret;
+   struct list_head *entry;
+   struct fw_file *file;
+
+   /* make sure fw_list is loaded */
+   ret = qemu_fwcfg_read_firmware_list();
+   if (ret)
+   return ret;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   printf("%-56s\n", file->cfg.name);
+   }
return 0;
 }
 
diff --git a/arch/x86/include/asm/fw_cfg.h b/arch/x86/include/asm/fw_cfg.h
index fb110fa..285d805 100644
--- a/arch/x86/include/asm/fw_cfg.h
+++ b/arch/x86/include/asm/fw_cfg.h
@@ -12,6 +12,8 @@
 #define FW_DMA_PORT_LOW0x514
 #define FW_DMA_PORT_HIGH   0x518
 
+#include 
+
 enum qemu_fwcfg_items {
FW_CFG_SIGNATURE= 0x00,
FW_CFG_ID   = 0x01,
@@ -67,6 +69,12 @@ struct fw_cfg_file {
char name[FW_CFG_MAX_FILE_PATH];
 };
 
+struct fw_file {
+   struct fw_cfg_file cfg;
+   unsigned long addr;
+   struct list_head list;
+};
+
 struct fw_cfg_files {
__be32 count;
struct fw_cfg_file files[];
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 0/4] add support for loading ACPI tables from QEMU

2016-01-14 Thread Miao Yan
Currently, if CONFIG_GENERATE_ACPI_TABLE is defined, U-Boot will generate ACPI
tables itlself, this patchset adds the ability to load the ACPI tables generated
by QEMU.

Miao Yan (4):
  x86: qemu: re-structure qemu_fwcfg_list_firmware()
  x86: qemu: setup PM IO base for ACPI in southbridge
  x86: qemu: add the ability to load and link ACPI tables from QEMU
  x86: qemu: loading ACPI table from QEMU

 arch/x86/cpu/qemu/fw_cfg.c  | 274 ++--
 arch/x86/cpu/qemu/qemu.c|  39 +
 arch/x86/include/asm/arch-qemu/device.h |   8 +
 arch/x86/include/asm/fw_cfg.h   |  78 +
 arch/x86/lib/tables.c   |   5 +-
 5 files changed, 389 insertions(+), 15 deletions(-)

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/4] x86: qemu: add the ability to load and link ACPI tables from QEMU

2016-01-14 Thread Miao Yan
This patch adds the ability to load and link ACPI tables provided by QEMU.
QEMU tells guests how to load and patch ACPI tables through its fw_cfg
interface, by adding a firmware file 'etc/table-loader'. Guests are
supposed to parse this file and execute corresponding QEMU commands.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/cpu/qemu/fw_cfg.c| 214 ++
 arch/x86/include/asm/fw_cfg.h |  70 ++
 2 files changed, 284 insertions(+)

diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
index b22026c..755676c 100644
--- a/arch/x86/cpu/qemu/fw_cfg.c
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -10,7 +10,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
@@ -202,6 +205,217 @@ err:
return -ENOMEM;
 }
 
+static struct fw_file *qemu_fwcfg_find_file(const char *name)
+{
+   struct list_head *entry;
+   struct fw_file *file;
+
+   list_for_each(entry, _list) {
+   file = list_entry(entry, struct fw_file, list);
+   if (!strcmp(file->cfg.name, name))
+   return file;
+   }
+
+   return NULL;
+}
+
+static int bios_linker_allocate(struct bios_linker_entry *entry,
+  unsigned long *addr)
+{
+   uint32_t size, align;
+   struct fw_file *file;
+   unsigned long aligned_addr;
+
+   align = le32_to_cpu(entry->alloc.align);
+   /* align must be power of 2 */
+   if (align & (align - 1)) {
+   printf("error: wrong alignment %u\n", align);
+   return -EINVAL;
+   }
+
+   file = qemu_fwcfg_find_file(entry->alloc.file);
+   if (!file) {
+   printf("error: can't find file %s\n", entry->alloc.file);
+   return -ENOENT;
+   }
+
+   size = be32_to_cpu(file->cfg.size);
+
+   /*
+* ZONE_HIGH means we need to allocate from high memory, since
+* malloc space is already at the end of RAM, so we directly use it.
+* If allocation zone is ZONE_FSEG, then we use the 'addr' passed
+* in which is low memory
+*/
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) {
+   aligned_addr = (unsigned long)memalign(align, size);
+   } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) {
+   aligned_addr = ALIGN(*addr, align);
+   } else {
+   printf("error: invalid allocation zone\n");
+   return -EINVAL;
+   }
+
+   debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align 
%u, addr 0x%lx\n",
+ file->cfg.name, size, entry->alloc.zone, align, aligned_addr);
+
+   qemu_fwcfg_read_entry(be16_to_cpu(file->cfg.select),
+ size, (void *)aligned_addr);
+   file->addr = aligned_addr;
+
+   /* adjust address for low memory allocation */
+   if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG)
+   *addr = (aligned_addr + size);
+
+   return 0;
+}
+
+static int bios_linker_add_pointer(struct bios_linker_entry *entry)
+{
+   struct fw_file *dest, *src;
+   uint32_t offset = le32_to_cpu(entry->pointer.offset);
+   uint64_t pointer = 0;
+
+   dest = qemu_fwcfg_find_file(entry->pointer.dest_file);
+   if (!dest || !dest->addr)
+   return -ENOENT;
+   src = qemu_fwcfg_find_file(entry->pointer.src_file);
+   if (!src || !src->addr)
+   return -ENOENT;
+
+
+   memcpy(, (char *)dest->addr + offset, entry->pointer.size);
+   pointer = le64_to_cpu(pointer);
+
+
+   debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, 
offset 0x%x size %u, 0x%llx\n",
+ dest->addr, src->addr, offset, entry->pointer.size, pointer);
+
+   pointer += (unsigned long)src->addr;
+   pointer = cpu_to_le64(pointer);
+   memcpy((char *)dest->addr + offset, , entry->pointer.size);
+
+   return 0;
+}
+
+static int bios_linker_add_checksum(struct bios_linker_entry *entry)
+{
+   struct fw_file *file;
+   uint8_t *data, cksum = 0;
+   uint8_t *cksum_start;
+
+   file = qemu_fwcfg_find_file(entry->cksum.file);
+   if (!file || !file->addr)
+   return -ENOENT;
+
+   data = (uint8_t *)(file->addr + le32_to_cpu(entry->cksum.offset));
+   cksum_start = (uint8_t *)(file->addr + le32_to_cpu(entry->cksum.start));
+   cksum = table_compute_checksum(cksum_start,
+  le32_to_cpu(entry->cksum.length));
+   *data = cksum;
+
+   return 0;
+}
+
+unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
+{
+   entries[0].addr = 0;
+   entries[0].size = I

[U-Boot] [PATCH 4/4] x86: qemu: loading ACPI table from QEMU

2016-01-14 Thread Miao Yan
If CONFIG_GENERATE_ACPI_TABLE is not defined, then use ACPI table created
by QEMU.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
---
 arch/x86/lib/tables.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
index 14b15cf..1671385 100644
--- a/arch/x86/lib/tables.c
+++ b/arch/x86/lib/tables.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 u8 table_compute_checksum(void *v, int len)
 {
@@ -55,8 +56,10 @@ void write_tables(void)
 #endif
 #ifdef CONFIG_GENERATE_ACPI_TABLE
rom_table_end = write_acpi_tables(rom_table_end);
-   rom_table_end = ALIGN(rom_table_end, 1024);
+#else
+   rom_table_end = qemu_fwcfg_write_acpi_tables(rom_table_end);
 #endif
+   rom_table_end = ALIGN(rom_table_end, 1024);
 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
rom_table_end = write_smbios_table(rom_table_end);
rom_table_end = ALIGN(rom_table_end, 1024);
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v6 0/8] x86: qemu: add fw_cfg interface support for qemu-x86 targets

2016-01-11 Thread Miao Yan
Hi Bin,

2016-01-07 17:31 GMT+08:00 Miao Yan <yanmiaob...@gmail.com>:
> The fw_cfg interface provided by QEMU allow guests to retrieve various 
> information
> about the system, e.g. cpu number, variaous firmware data, kernel setup, etc. 
> The
> fw_cfg interface can be accessed through 3 IO ports (on x86), using x86 in/out
> instructions.
>
>   - 0x510: select configuration items to access
>   - 0x511: reading this port will return data selected in 0x510
>   - 0x514: this can be used to detect if DMA interface is available
>
> If fw_cfg DMA interface is available, it can be used to accelerate
> accesses.
>
> This patchset adds the following supports for qemu-x86 targets:
>
>   + the fw_cfg driver itself
>
>   + add a U-Boot command 'fw' to support direct accessing kernel informtion
> from fw_cfg interface, this saves the time of loading them from hard disk 
> or
> network again, through emulated devices.
>
>   + use fw_cfg to get cpu number at runtime, so smp boot no longer relies on
> the cpu node hard-coded in dts files.
>
> Changes in v6:
>   - fix oneline comment
>   - do not update bootargs when kernel cmdline only contains '\0'
>
> Miao Yan (8):
>   x86: adjust ramdisk load address
>   x86: qemu: add fw_cfg support
>   x86: qemu: add a cpu uclass driver for qemu target
>   x86: fix a typo in function name
>   x86: use actual CPU number for allocating memory
>   x86: qemu: fix cpu device in smp boot
>   x86: qemu: remove cpu node in device tree
>   x86: qemu: add documentaion for the fw_cfg interface
>
>  arch/x86/cpu/mp_init.c   |  84 +++-
>  arch/x86/cpu/qemu/Makefile   |   2 +-
>  arch/x86/cpu/qemu/cpu.c  |  46 +++
>  arch/x86/cpu/qemu/fw_cfg.c   | 283 
> +++
>  arch/x86/cpu/qemu/qemu.c |   3 +
>  arch/x86/dts/qemu-x86_i440fx.dts |   9 +-
>  arch/x86/dts/qemu-x86_q35.dts|   9 +-
>  arch/x86/include/asm/fw_cfg.h|  93 +
>  doc/README.x86   |  34 -
>  include/configs/x86-common.h |   3 +-
>  10 files changed, 539 insertions(+), 27 deletions(-)
>  create mode 100644 arch/x86/cpu/qemu/cpu.c
>  create mode 100644 arch/x86/cpu/qemu/fw_cfg.c
>  create mode 100644 arch/x86/include/asm/fw_cfg.h
>
> --
> 1.9.1
>

Is v6 OK for integration ? Thanks.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v6 2/8] x86: qemu: add fw_cfg support

2016-01-07 Thread Miao Yan
The QEMU fw_cfg interface allows the guest to retrieve various data
information from QEMU. For example, APCI/SMBios tables, number of online
cpus, kernel data and command line, etc.

This patch adds support for QEMU fw_cfg interface.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v6:
  - fix oneline comment
  - do not update bootargs when kernel cmdline only contains '\0'

 arch/x86/cpu/qemu/Makefile|   2 +-
 arch/x86/cpu/qemu/fw_cfg.c| 283 ++
 arch/x86/cpu/qemu/qemu.c  |   3 +
 arch/x86/include/asm/fw_cfg.h |  93 ++
 4 files changed, 380 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/cpu/qemu/fw_cfg.c
 create mode 100644 arch/x86/include/asm/fw_cfg.h

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 3f3958a..d613798 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,5 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += qemu.o
+obj-y += fw_cfg.o qemu.o
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
new file mode 100644
index 000..0599214
--- /dev/null
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -0,0 +1,283 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaoe...@gmail.com>
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static bool fwcfg_present;
+static bool fwcfg_dma_present;
+
+/* Read configuration item using fw_cfg PIO interface */
+static void qemu_fwcfg_read_entry_pio(uint16_t entry,
+   uint32_t size, void *address)
+{
+   uint32_t i = 0;
+   uint8_t *data = address;
+
+   /*
+* 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)
+   outw(entry, FW_CONTROL_PORT);
+   while (size--)
+   data[i++] = inb(FW_DATA_PORT);
+}
+
+/* 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_dma_read_entry: addr %p, length %u control 0x%x\n",
+ address, size, be32_to_cpu(dma.control));
+
+   outl(cpu_to_be32((uint32_t)), FW_DMA_PORT_HIGH);
+
+   while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_ERROR)
+   __asm__ __volatile__ ("pause");
+}
+
+static bool qemu_fwcfg_present(void)
+{
+   uint32_t qemu;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
+   return be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE;
+}
+
+static bool qemu_fwcfg_dma_present(void)
+{
+   uint8_t dma_enabled;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
+   if (dma_enabled & FW_CFG_DMA_ENABLED)
+   return true;
+
+   return false;
+}
+
+static 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, _cpus);
+
+   return le16_to_cpu(nb_cpus);
+}
+
+/*
+ * This function prepares kernel for zboot. It loads kernel data
+ * to 'load_addr', initrd to 'initrd_addr' and kernel command
+ * line using qemu fw_cfg interface.
+ */
+static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr)
+{
+   char *data_addr;
+   uint32_t setup_size, kernel_size, cmdline_size, initrd_size;
+
+   qemu_fwcfg_read_entry(FW_CFG_SETUP_SIZE, 4, _size);
+   qemu_fwcfg_read_entry(FW_CFG_KERNEL_SIZE, 4, _size);
+
+   if (setup_size == 0 || kernel_size == 0) {
+   printf("warning: no kernel available\n");
+   return -1;
+   }
+
+   data_addr = load_addr;
+   qemu_fwcfg_read_entry(FW_CFG_SETUP_DATA,
+ le32_to_cpu(setup_size), data_addr);
+   data_addr += le32_to_cpu(setup_size);
+
+   qemu_fwcfg_read_entry(FW_CFG_KERNEL_DATA,
+ le

[U-Boot] [PATCH v6 0/8] x86: qemu: add fw_cfg interface support for qemu-x86 targets

2016-01-07 Thread Miao Yan
The fw_cfg interface provided by QEMU allow guests to retrieve various 
information
about the system, e.g. cpu number, variaous firmware data, kernel setup, etc. 
The
fw_cfg interface can be accessed through 3 IO ports (on x86), using x86 in/out
instructions.

  - 0x510: select configuration items to access
  - 0x511: reading this port will return data selected in 0x510 
  - 0x514: this can be used to detect if DMA interface is available

If fw_cfg DMA interface is available, it can be used to accelerate
accesses.

This patchset adds the following supports for qemu-x86 targets: 

  + the fw_cfg driver itself

  + add a U-Boot command 'fw' to support direct accessing kernel informtion
from fw_cfg interface, this saves the time of loading them from hard disk or
network again, through emulated devices.

  + use fw_cfg to get cpu number at runtime, so smp boot no longer relies on
the cpu node hard-coded in dts files.

Changes in v6:
  - fix oneline comment
  - do not update bootargs when kernel cmdline only contains '\0'

Miao Yan (8):
  x86: adjust ramdisk load address
  x86: qemu: add fw_cfg support
  x86: qemu: add a cpu uclass driver for qemu target
  x86: fix a typo in function name
  x86: use actual CPU number for allocating memory
  x86: qemu: fix cpu device in smp boot
  x86: qemu: remove cpu node in device tree
  x86: qemu: add documentaion for the fw_cfg interface

 arch/x86/cpu/mp_init.c   |  84 +++-
 arch/x86/cpu/qemu/Makefile   |   2 +-
 arch/x86/cpu/qemu/cpu.c  |  46 +++
 arch/x86/cpu/qemu/fw_cfg.c   | 283 +++
 arch/x86/cpu/qemu/qemu.c |   3 +
 arch/x86/dts/qemu-x86_i440fx.dts |   9 +-
 arch/x86/dts/qemu-x86_q35.dts|   9 +-
 arch/x86/include/asm/fw_cfg.h|  93 +
 doc/README.x86   |  34 -
 include/configs/x86-common.h |   3 +-
 10 files changed, 539 insertions(+), 27 deletions(-)
 create mode 100644 arch/x86/cpu/qemu/cpu.c
 create mode 100644 arch/x86/cpu/qemu/fw_cfg.c
 create mode 100644 arch/x86/include/asm/fw_cfg.h

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v6 6/8] x86: qemu: fix cpu device in smp boot

2016-01-07 Thread Miao Yan
Currently, when booting with more that one CPU enabled, U-Boot scans
'cpu' node in device tree and calculates CPU number. This does not scale
well as changing CPU number also requires modifying .dts and re-compiling
U-Boot.

This patch uses fw_cfg interface provided by QEMU to detect online CPU
number at runtime, and dynamically adds 'cpu' device to U-Boot's driver
model.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v6:
  - remove cpu_qemu_bind

 arch/x86/cpu/mp_init.c  | 72 +
 arch/x86/cpu/qemu/cpu.c | 11 
 2 files changed, 72 insertions(+), 11 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 2a3ce48..7917350 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -20,8 +20,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -441,6 +444,69 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
+#ifdef CONFIG_QEMU
+static int qemu_cpu_fixup(void)
+{
+   int ret;
+   int cpu_num;
+   int cpu_online;
+   struct udevice *dev, *pdev;
+   struct cpu_platdata *plat;
+   char *cpu;
+
+   /* first we need to find '/cpus' */
+   for (device_find_first_child(dm_root(), );
+pdev;
+device_find_next_child()) {
+   if (!strcmp(pdev->name, "cpus"))
+   break;
+   }
+   if (!pdev) {
+   printf("unable to find cpus device\n");
+   return -ENODEV;
+   }
+
+   /* calculate cpus that are already bound */
+   cpu_num = 0;
+   for (uclass_find_first_device(UCLASS_CPU, );
+dev;
+uclass_find_next_device()) {
+   cpu_num++;
+   }
+
+   /* get actual cpu number */
+   cpu_online = qemu_fwcfg_online_cpus();
+   if (cpu_online < 0) {
+   printf("unable to get online cpu number: %d\n", cpu_online);
+   return cpu_online;
+   }
+
+   /* bind addtional cpus */
+   dev = NULL;
+   for (; cpu_num < cpu_online; cpu_num++) {
+   /*
+* allocate device name here as device_bind_driver() does
+* not copy device name, 8 bytes are enough for
+* sizeof("cpu@") + 3 digits cpu number + '\0'
+*/
+   cpu = malloc(8);
+   if (!cpu) {
+   printf("unable to allocate device name\n");
+   return -ENOMEM;
+   }
+   sprintf(cpu, "cpu@%d", cpu_num);
+   ret = device_bind_driver(pdev, "cpu_qemu", cpu, );
+   if (ret) {
+   printf("binding cpu@%d failed: %d\n", cpu_num, ret);
+   return ret;
+   }
+   plat = dev_get_parent_platdata(dev);
+   plat->cpu_id = cpu_num;
+   }
+   return 0;
+}
+#endif
+
 int mp_init(struct mp_params *p)
 {
int num_aps;
@@ -454,6 +520,12 @@ int mp_init(struct mp_params *p)
if (ret)
return ret;
 
+#ifdef CONFIG_QEMU
+   ret = qemu_cpu_fixup();
+   if (ret)
+   return ret;
+#endif
+
ret = init_bsp();
if (ret) {
debug("Cannot init boot CPU: err=%d\n", ret);
diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c
index a4bf53d..a1b70c6 100644
--- a/arch/x86/cpu/qemu/cpu.c
+++ b/arch/x86/cpu/qemu/cpu.c
@@ -13,16 +13,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-int cpu_qemu_bind(struct udevice *dev)
-{
-   struct cpu_platdata *plat = dev_get_parent_platdata(dev);
-
-   plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
- "intel,apic-id", -1);
-
-   return 0;
-}
-
 int cpu_qemu_get_desc(struct udevice *dev, char *buf, int size)
 {
if (size < CPU_MAX_NAME_LEN)
@@ -52,6 +42,5 @@ U_BOOT_DRIVER(cpu_qemu_drv) = {
.name   = "cpu_qemu",
.id = UCLASS_CPU,
.of_match   = cpu_qemu_ids,
-   .bind   = cpu_qemu_bind,
.ops= _qemu_ops,
 };
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v6 8/8] x86: qemu: add documentaion for the fw_cfg interface

2016-01-07 Thread Miao Yan
Document the usage of 'qfw' command

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 doc/README.x86 | 34 +++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/doc/README.x86 b/doc/README.x86
index 1271e5e..36aaef0 100644
--- a/doc/README.x86
+++ b/doc/README.x86
@@ -295,9 +295,37 @@ show QEMU's VGA console window. Note this will disable 
QEMU's serial output.
 If you want to check both consoles, use '-serial stdio'.
 
 Multicore is also supported by QEMU via '-smp n' where n is the number of cores
-to instantiate. Currently the default U-Boot built for QEMU supports 2 cores.
-In order to support more cores, you need add additional cpu nodes in the device
-tree and change CONFIG_MAX_CPUS accordingly.
+to instantiate. Note, the maximum supported CPU number in QEMU is 255.
+
+The fw_cfg interface in QEMU also provides information about kernel data, 
initrd,
+command-line arguments and more. U-Boot supports directly accessing these 
informtion
+from fw_cfg interface, this saves the time of loading them from hard disk or
+network again, through emulated devices. To use it , simply providing them in
+QEMU command line:
+
+$ qemu-system-i386 -nographic -bios path/to/u-boot.rom -m 1024 -kernel 
/path/to/bzImage
+-append 'root=/dev/ram console=ttyS0' -initrd /path/to/initrd -smp 8
+
+Note: -initrd and -smp are both optional
+
+Then start QEMU, in U-Boot command line use the following U-Boot command to 
setup kernel:
+
+ => qfw
+qfw - QEMU firmware interface
+
+Usage:
+qfw 
+- list : print firmware(s) currently loaded
+- cpus : print online cpu number
+- load   : load kernel and initrd (if any) and 
setup for zboot
+
+=> qfw load
+loading kernel to address 0100 size 5d9d30 initrd 0400 size 1b1ab50
+
+Here the kernel (bzImage) is loaded to 0100 and initrd is to 0400. 
Then, 'zboot'
+can be used to boot the kernel:
+
+=> zboot 0200 - 0400 1b1ab50
 
 CPU Microcode
 -
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v6 4/8] x86: fix a typo in function name

2016-01-07 Thread Miao Yan
Rename 'find_cpu_by_apid_id' to 'find_cpu_by_apic_id'. This should be a
typo.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/mp_init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 4334f5b..2f34317 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -104,7 +104,7 @@ static void ap_do_flight_plan(struct udevice *cpu)
}
 }
 
-static int find_cpu_by_apid_id(int apic_id, struct udevice **devp)
+static int find_cpu_by_apic_id(int apic_id, struct udevice **devp)
 {
struct udevice *dev;
 
@@ -137,7 +137,7 @@ static void ap_init(unsigned int cpu_index)
enable_lapic();
 
apic_id = lapicid();
-   ret = find_cpu_by_apid_id(apic_id, );
+   ret = find_cpu_by_apic_id(apic_id, );
if (ret) {
debug("Unknown CPU apic_id %x\n", apic_id);
goto done;
@@ -432,7 +432,7 @@ static int init_bsp(struct udevice **devp)
lapic_setup();
 
apic_id = lapicid();
-   ret = find_cpu_by_apid_id(apic_id, devp);
+   ret = find_cpu_by_apic_id(apic_id, devp);
if (ret) {
printf("Cannot find boot CPU, APIC ID %d\n", apic_id);
return ret;
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] net: e1000: Fix packet length conversion

2016-01-06 Thread Miao Yan
Hi Lian,

2016-01-06 16:41 GMT+08:00 Minghuan Lian :
> The length of the receiving packet descriptor is a 16bit integer
> not 32bit. le32_to_cpu should be replaced by le16_to_cpu to
> make the correct conversion. Otherwise, e1000 cannot work on
> some kinds of big-endian platform.


This is a duplication of

https://patchwork.ozlabs.org/patch/559472/



>
> Signed-off-by: Minghuan Lian 
> ---
>  drivers/net/e1000.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
> index 2ba03ed..e3c6916 100644
> --- a/drivers/net/e1000.c
> +++ b/drivers/net/e1000.c
> @@ -5169,7 +5169,7 @@ _e1000_poll(struct e1000_hw *hw)
> return 0;
> /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
> /* Packet received, make sure the data are re-loaded from RAM. */
> -   len = le32_to_cpu(rd->length);
> +   len = le16_to_cpu(rd->length);
> invalidate_dcache_range((unsigned long)packet,
> (unsigned long)packet +
> roundup(len, ARCH_DMA_MINALIGN));
> --
> 1.9.1
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 6/8] x86: qemu: fix cpu device in smp boot

2016-01-05 Thread Miao Yan
2016-01-06 8:25 GMT+08:00 Simon Glass <s...@chromium.org>:
> On 4 January 2016 at 01:00, Miao Yan <yanmiaob...@gmail.com> wrote:
>> Currently, when booting with more that one CPU enabled, U-Boot scans
>> 'cpu' node in device tree and calculates CPU number. This does not scale
>> well as changing CPU number also requires modifying .dts and re-compiling
>> U-Boot.
>>
>> This patch uses fw_cfg interface provided by QEMU to detect online CPU
>> number at runtime, and dynamically adds 'cpu' device to U-Boot's driver
>> model.
>>
>> Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
>> ---
>>  arch/x86/cpu/mp_init.c  | 73 
>> +
>>  arch/x86/cpu/qemu/cpu.c |  5 
>>  2 files changed, 73 insertions(+), 5 deletions(-)
>
> Reviewed-by: Simon Glass <s...@chromium.org>
>
> Maybe cpu_qemu_bind() isn't needed now?

Right, this can be removed.

Hi Bin, do you have any comments on this one ?

Thanks,
Miao
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 2/8] x86: qemu: add fw_cfg support

2016-01-04 Thread Miao Yan
The QEMU fw_cfg interface allows the guest to retrieve various data
information from QEMU. For example, APCI/SMBios tables, number of online
cpus, kernel data and command line, etc.

This patch adds support for QEMU fw_cfg interface.

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v5:
  - change 'fw' to 'qfw'
  - move fw_cfg.h to include/asm
  - cleanups

 arch/x86/cpu/qemu/Makefile|   2 +-
 arch/x86/cpu/qemu/fw_cfg.c| 286 ++
 arch/x86/cpu/qemu/qemu.c  |   3 +
 arch/x86/include/asm/fw_cfg.h |  95 ++
 4 files changed, 385 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/cpu/qemu/fw_cfg.c
 create mode 100644 arch/x86/include/asm/fw_cfg.h

diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile
index 3f3958a..d613798 100644
--- a/arch/x86/cpu/qemu/Makefile
+++ b/arch/x86/cpu/qemu/Makefile
@@ -7,5 +7,5 @@
 ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
-obj-y += qemu.o
+obj-y += fw_cfg.o qemu.o
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c
new file mode 100644
index 000..17276c3
--- /dev/null
+++ b/arch/x86/cpu/qemu/fw_cfg.c
@@ -0,0 +1,286 @@
+/*
+ * (C) Copyright 2015 Miao Yan <yanmiaoe...@gmail.com>
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static bool fwcfg_present;
+static bool fwcfg_dma_present;
+
+/*
+ * Read configuration item using fw_cfg PIO interface
+ */
+
+static void qemu_fwcfg_read_entry_pio(uint16_t entry,
+   uint32_t size, void *address)
+{
+   uint32_t i = 0;
+   uint8_t *data = address;
+
+   /*
+* 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)
+   outw(entry, FW_CONTROL_PORT);
+   while (size--)
+   data[i++] = inb(FW_DATA_PORT);
+}
+
+/*
+ * 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_dma_read_entry: addr %p, length %u control 0x%x\n",
+ address, size, be32_to_cpu(dma.control));
+
+   outl(cpu_to_be32((uint32_t)), FW_DMA_PORT_HIGH);
+
+   while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_ERROR)
+   __asm__ __volatile__ ("pause");
+}
+
+static bool qemu_fwcfg_present(void)
+{
+   uint32_t qemu;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_SIGNATURE, 4, );
+   return be32_to_cpu(qemu) == QEMU_FW_CFG_SIGNATURE;
+}
+
+static bool qemu_fwcfg_dma_present(void)
+{
+   uint8_t dma_enabled;
+
+   qemu_fwcfg_read_entry_pio(FW_CFG_ID, 1, _enabled);
+   if (dma_enabled & FW_CFG_DMA_ENABLED)
+   return true;
+
+   return false;
+}
+
+static 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, _cpus);
+
+   return le16_to_cpu(nb_cpus);
+}
+
+/*
+ * This function prepares kernel for zboot. It loads kernel data
+ * to 'load_addr', initrd to 'initrd_addr' and kernel command
+ * line using qemu fw_cfg interface.
+ */
+
+static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr)
+{
+   char *data_addr;
+   uint32_t setup_size, kernel_size, cmdline_size, initrd_size;
+
+   qemu_fwcfg_read_entry(FW_CFG_SETUP_SIZE, 4, _size);
+   qemu_fwcfg_read_entry(FW_CFG_KERNEL_SIZE, 4, _size);
+
+   if (setup_size == 0 || kernel_size == 0) {
+   printf("warning: no kernel available\n");
+   return -1;
+   }
+
+   data_addr = load_addr;
+   qemu_fwcfg_read_entry(FW_CFG_SETUP_DATA,
+ le32_to_cpu(setup_size), data_addr);
+   data_addr += le32_to_cpu(setup_size);
+
+   qemu_fwcfg_read_entry(FW_CFG_KERNEL_DATA,
+ le

[U-Boot] [PATCH v5 0/8] x86: qemu: add fw_cfg interface support for qemu-x86 targets

2016-01-04 Thread Miao Yan
The fw_cfg interface provided by QEMU allow guests to retrieve various 
information
about the system, e.g. cpu number, variaous firmware data, kernel setup, etc. 
The
fw_cfg interface can be accessed through 3 IO ports (on x86), using x86 in/out
instructions.

  - 0x510: select configuration items to access
  - 0x511: reading this port will return data selected in 0x510 
  - 0x514: this can be used to detect if DMA interface is available

If fw_cfg DMA interface is available, it can be used to accelerate
accesses.

This patchset adds the following supports for qemu-x86 targets: 

  + the fw_cfg driver itself

  + add a U-Boot command 'fw' to support direct accessing kernel informtion
from fw_cfg interface, this saves the time of loading them from hard disk or
network again, through emulated devices.

  + use fw_cfg to get cpu number at runtime, so smp boot no longer relies on
the cpu node hard-coded in dts files.

Changes in v5:
  + change 'fw' to 'qfw'
  + dynamically bind cpu device instead of fixing device tree blob
  + various cleanups

Miao Yan (8):
  x86: adjust ramdisk load address
  x86: qemu: add fw_cfg support
  x86: qemu: add a cpu uclass driver for qemu target
  x86: fix a typo in function name
  x86: use actual CPU number for allocating memory
  x86: qemu: fix cpu device in smp boot
  x86: qemu: remove cpu node in device tree
  x86: qemu: add documentaion for the fw_cfg interface

 arch/x86/cpu/mp_init.c   |  85 +++-
 arch/x86/cpu/qemu/Makefile   |   2 +-
 arch/x86/cpu/qemu/cpu.c  |  52 +++
 arch/x86/cpu/qemu/fw_cfg.c   | 286 +++
 arch/x86/cpu/qemu/qemu.c |   3 +
 arch/x86/dts/qemu-x86_i440fx.dts |   9 +-
 arch/x86/dts/qemu-x86_q35.dts|   9 +-
 arch/x86/include/asm/fw_cfg.h|  95 +
 doc/README.x86   |  34 -
 include/configs/x86-common.h |   3 +-
 10 files changed, 551 insertions(+), 27 deletions(-)
 create mode 100644 arch/x86/cpu/qemu/cpu.c
 create mode 100644 arch/x86/cpu/qemu/fw_cfg.c
 create mode 100644 arch/x86/include/asm/fw_cfg.h

-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 1/8] x86: adjust ramdisk load address

2016-01-04 Thread Miao Yan
By default, ramdisk load address is defined to 0200 in env string.
When loading bzImage to 0100 (default address), there's a chance that
the ramdisk header would be overwritten by the kernel. Thus increase the
gap and make ramdisk load at 0400 by default and also this patch
introduces a new configuration item CONFIG_RAMDISK_ADDR for this purpose

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
---
Changes in v5:
  - move this change to x86-common.h
  - reorder it to be the first patch

 include/configs/x86-common.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h
index 70ec103..4182a3b 100644
--- a/include/configs/x86-common.h
+++ b/include/configs/x86-common.h
@@ -208,6 +208,7 @@
 #define CONFIG_HOSTNAMEx86
 #define CONFIG_BOOTFILE"bzImage"
 #define CONFIG_LOADADDR0x100
+#define CONFIG_RAMDISK_ADDR0x400
 
 #define CONFIG_EXTRA_ENV_SETTINGS  \
CONFIG_STD_DEVICES_SETTINGS \
@@ -215,7 +216,7 @@
"netdev=eth0\0" \
"consoledev=ttyS0\0"\
"othbootargs=acpi=off\0"\
-   "ramdiskaddr=0x200\0"   \
+   "ramdiskaddr=0x400\0"   \
"ramdiskfile=initramfs.gz\0"
 
 #define CONFIG_RAMBOOTCOMMAND  \
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 5/8] x86: use actual CPU number for allocating memory

2016-01-04 Thread Miao Yan
Use actual CPU number, instead of maximum cpu configured, to allocate
stack memory in 'load_sipi_vector'

Signed-off-by: Miao Yan <yanmiaob...@gmail.com>
Reviewed-by: Simon Glass <s...@chromium.org>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
---
 arch/x86/cpu/mp_init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 2f34317..2a3ce48 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -210,7 +210,7 @@ static int save_bsp_msrs(char *start, int size)
return msr_count;
 }
 
-static int load_sipi_vector(atomic_t **ap_countp)
+static int load_sipi_vector(atomic_t **ap_countp, int num_cpus)
 {
struct sipi_params_16bit *params16;
struct sipi_params *params;
@@ -239,7 +239,7 @@ static int load_sipi_vector(atomic_t **ap_countp)
params->idt_ptr = (uint32_t)x86_get_idt();
 
params->stack_size = CONFIG_AP_STACK_SIZE;
-   size = params->stack_size * CONFIG_MAX_CPUS;
+   size = params->stack_size * num_cpus;
stack = memalign(size, 4096);
if (!stack)
return -ENOMEM;
@@ -483,7 +483,7 @@ int mp_init(struct mp_params *p)
mp_info.records = p->flight_plan;
 
/* Load the SIPI vector */
-   ret = load_sipi_vector(_count);
+   ret = load_sipi_vector(_count, num_cpus);
if (ap_count == NULL)
return -1;
 
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


  1   2   >