Re: [Qemu-devel] qemu-coroutine.c: error: thread-local storage not supported for this target

2015-01-24 Thread Paolo Bonzini


On 23/01/2015 23:54, Programmingkid wrote:
 Sorry, I was wrong.  I missed that you are using 10.6.x.
 
 Thread-local storage was introduced on Mac OS X in 10.7.  For
 10.6.x you'll have to compile GCC 4.3 or newer yourself (or take it
 from fink/homebrew/whatever the Mac folks use these days).
 
 The code that causes this problem needs to be #ifdef'ed. I'm just not
 sure what the problem code is.

Thread-local storage will become more and more fundamental as QEMU makes
more use of threads.  Another use of __thread will be committed in a
matter of weeks; __thread is simpler and potentially faster than pthread
TLS.

A possible alternative would be to enable QEMU to compile with a C++
compiler and use Boost's thread-local storage module.  Using #ifdef
makes code ugly for no reason, and is not an acceptable alternative.

Note that GCC 4.3 was released almost seven years ago; we've been
requiring it on Windows for three years (commit 00dccaf, coroutine:
introduce coroutines, 2011-01-17), and no one has ever complained.

Apple is not providing it for Mac OS X 10.6.x only because of political
reasons.  Complain to them, not to the QEMU project.

Paolo



Re: [Qemu-devel] qemu-coroutine.c: error: thread-local storage not supported for this target

2015-01-24 Thread Peter Maydell
On 24 January 2015 at 18:54, Paolo Bonzini pbonz...@redhat.com wrote:
 Note that GCC 4.3 was released almost seven years ago; we've been
 requiring it on Windows for three years (commit 00dccaf, coroutine:
 introduce coroutines, 2011-01-17), and no one has ever complained.

 Apple is not providing it for Mac OS X 10.6.x only because of political
 reasons.  Complain to them, not to the QEMU project.

Apple's not providing it on 10.6.x because 10.6.x is obsolete
as far as Apple is concerned. Supported versions of OSX use
clang, which has support for __thread. Missing __thread
support is an old platform thing, not a political GPL thing.

-- PMM



Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append()

2015-01-24 Thread Michael S. Tsirkin
On Fri, Jan 23, 2015 at 06:56:20PM +0100, Igor Mammedov wrote:
 On Fri, 23 Jan 2015 15:55:11 +0200
 Michael S. Tsirkin m...@redhat.com wrote:
 
  On Fri, Jan 23, 2015 at 02:40:30PM +0100, Igor Mammedov wrote:
   On Fri, 23 Jan 2015 15:24:24 +0200
   Michael S. Tsirkin m...@redhat.com wrote:
   
On Fri, Jan 23, 2015 at 11:35:29AM +0100, Igor Mammedov wrote:
 On Fri, 23 Jan 2015 10:11:19 +0200
 Michael S. Tsirkin m...@redhat.com wrote:
 
  On Thu, Jan 22, 2015 at 02:49:45PM +, Igor Mammedov wrote:
   Adds for dynamic AML creation, which will be used
   for piecing ASL/AML primitives together and hiding
   from user/caller details about how nested context
   should be closed/packed leaving less space for
   mistakes and necessity to know how AML should be
   encoded, allowing user to concentrate on ASL
   representation instead.
   
   For example it will allow to create AML like this:
   
   AcpiAml scope = acpi_scope(PCI0)
   AcpiAml dev = acpi_device(PM)
   aml_append(dev, acpi_name_decl(_ADR, acpi_int(addr)))
   aml_append(scope, dev);
   
   Signed-off-by: Igor Mammedov imamm...@redhat.com
   ---
hw/acpi/acpi-build-utils.c | 39 
   ++
include/hw/acpi/acpi-build-utils.h | 16 
2 files changed, 55 insertions(+)
   
   diff --git a/hw/acpi/acpi-build-utils.c 
   b/hw/acpi/acpi-build-utils.c
   index 602e68c..547ecaa 100644
   --- a/hw/acpi/acpi-build-utils.c
   +++ b/hw/acpi/acpi-build-utils.c
   @@ -267,3 +267,42 @@ void build_append_int(GArray *table, 
   uint32_t value)
build_append_value(table, value, 4);
}
}
   +
   +static void build_prepend_int(GArray *array, uint32_t value)
   +{
   +GArray *data = build_alloc_array();
   +
   +build_append_int(data, value);
   +g_array_prepend_vals(array, data-data, data-len);
   +build_free_array(data);
   +}
  
  I don't think prepend is generally justified:
  it makes code hard to follow and debug.
  
  Adding length is different: of course you need
  to first have the package before you can add length.
  
  We currently have build_prepend_package_length - just move it
  to utils, and use everywhere.
 [...]
   +case BUFFER:
   +build_prepend_int(child.buf, child.buf-len);
   +build_package(child.buf, child.op);
 Buffer uses the same concept as package, but adds its own additional 
 length.
 Therefore I've added build_prepend_int(),
 I can create build_buffer() and mimic build_package()

Sounds good, pls do.
The point is to avoid generic prepend calls as an external API.

 but it won't change picture.

It's a better API - what is meant by picture?
   build_prepend_int() is a static/non public function,
   build_buffer() will also be static/non public function for use only by
   API internals.
   
   I pretty much hate long build_append_foo() names so I'm hiding all
   lowlevel constructs and try to expose only high-level ASL ones.
   Which makes me to think that we need to use asl_ prefix for API calls
   instead of acpi_ or aml_.
  
  This sounds wrong unless we either accept ASL input or
  produce ASL output.
  
  Igor, I think you are aiming a bit too high. Don't try to
  write your own language, just use C. It does have
  overhead like need to declare functions and variables,
  and allocate/free memory, but they are well understood.
 I refuse to give up on cleaner and simpler API yet :)
 
  
  
  Your patches are almost there, they are pretty clean, the only issue I
  think is this passing of AcpiAml by value, sometimes freeing buffer in
  the process, sometimes not.
 Currently buffer is allocated by API and is always freed whenever
 it's passed to another API function.
 That's why it makes user not to care about memory mgmt.
 
 The only limitation of it is if you store AcpiAml return value into some
 variable you are responsible to use it only once for passing to another API
 function. Reusing this variable's value (pass it to API function second time)
 would cause cause use-after-free and freeing-freed bugs.
 Like this:
 AcpiAml table = acpi_definition_block(SSDT,...);
 AcpiAml scope = acpi_scope(PCI0);
 aml_append(table, scope); // - here scope becomes invalid
 // a bug
 aml_append(table, scope); // use-after-free + freeing-freed bugs
 
 There are several approaches to look for resolving above issues:
 1. Adopt and use memory mgmt model used by GTK+
in nutshell: 
 http://www.cs.hunter.cuny.edu/~sweiss/course_materials/csci493.70/lecture_notes/GTK_memory_mngmt.pdf
In particular adopt behavior of GInitiallyUnowned usage model
 
that will allow to keep convenient chained call style and if necessary
reuse objects returned by API by 

Re: [Qemu-devel] [RFC PATCH 02/11] hw/arm/virt-acpi-build: Basic framework for building ACPI tables

2015-01-24 Thread Michael S. Tsirkin
On Sat, Jan 24, 2015 at 05:21:11PM +0800, Shannon Zhao wrote:
 Introduce a preliminary framework in virt-acpi-build.c with the main
 ACPI build functions. It exposes the generated ACPI contents to
 guest over fw_cfg. Some codes borrowed from hw/i386/acpi-build.c.
 
 The minimum required ACPI v5.1 tables for ARM are:
 - RSDP: Initial table that points to XSDT
 - XSDT: Points to all other tables (except FACS  DSDT)
 - FADT: Generic information about the machine
 - DSDT: Holds all information about system devices/peripherals
 - FACS: Needs to be pointed from FADT
 
 Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
 ---
  hw/arm/Makefile.objs |1 +
  hw/arm/virt-acpi-build.c |  263 
 ++
  include/hw/arm/virt-acpi-build.h |   71 ++
  3 files changed, 335 insertions(+), 0 deletions(-)
  create mode 100644 hw/arm/virt-acpi-build.c
  create mode 100644 include/hw/arm/virt-acpi-build.h
 
 diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
 index 6088e53..8daf825 100644
 --- a/hw/arm/Makefile.objs
 +++ b/hw/arm/Makefile.objs
 @@ -3,6 +3,7 @@ obj-$(CONFIG_DIGIC) += digic_boards.o
  obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o
  obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o
  obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o
 +obj-$(CONFIG_ACPI) += virt-acpi-build.o
  
  obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
  obj-$(CONFIG_DIGIC) += digic.o
 diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
 new file mode 100644
 index 000..4eed0a3
 --- /dev/null
 +++ b/hw/arm/virt-acpi-build.c
 @@ -0,0 +1,263 @@
 +/* Support for generating ACPI tables and passing them to Guests
 + *
 + * ARM virt ACPI generation
 + *
 + * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD.
 + *
 + * Author: Shannon Zhao zhaoshengl...@huawei.com

Since you copied code over, you should append copyright and author
information from the original file to the new one.

 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms and conditions of the GNU General Public License,
 + * version 2 or later, as published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope it will be useful, but WITHOUT
 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 + * more details.
 + *
 + * You should have received a copy of the GNU General Public License along 
 with
 + * this program.  If not, see http://www.gnu.org/licenses/.
 + */
 +
 +#include hw/arm/virt-acpi-build.h
 +#include stddef.h
 +#include glib.h
 +#include qemu-common.h
 +#include qemu/bitmap.h
 +#include qemu/osdep.h
 +#include qemu/range.h
 +#include qemu/error-report.h
 +#include qom/cpu.h
 +#include target-arm/cpu.h
 +#include hw/acpi/acpi-defs.h
 +#include hw/acpi/acpi.h
 +#include hw/nvram/fw_cfg.h
 +#include hw/acpi/bios-linker-loader.h
 +#include hw/loader.h
 +
 +#include hw/acpi/acpi-build-utils.h
 +
 +#include qapi/qmp/qint.h
 +#include qom/qom-qobject.h
 +#include exec/ram_addr.h
 +
 +
 +#define ACPI_BUILD_TABLE_SIZE 0x2
 +
 +/* Reserve RAM space for tables: add another order of magnitude. */
 +#define ACPI_BUILD_TABLE_MAX_SIZE 0x20
 +
 +/* #define DEBUG_ACPI_BUILD */
 +#ifdef DEBUG_ACPI_BUILD
 +#define ACPI_BUILD_DPRINTF(fmt, ...)\
 +do {printf(ACPI_BUILD:  fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define ACPI_BUILD_DPRINTF(fmt, ...)
 +#endif
 +
 +#define ACPI_BUILD_APPNAME  Bochs
 +#define ACPI_BUILD_APPNAME6 BOCHS 
 +
 +#define ACPI_BUILD_RSDP_FILE etc/acpi/rsdp
 +#define ACPI_BUILD_TPMLOG_FILE etc/tpm/log
 +
 +static inline void *acpi_data_push(GArray *table_data, uint64_t size)
 +{
 +unsigned off = table_data-len;
 +g_array_set_size(table_data, off + size);
 +return table_data-data + off;
 +}
 +
 +static unsigned acpi_data_len(GArray *table)
 +{
 +#if GLIB_CHECK_VERSION(2, 22, 0)
 +assert(g_array_get_element_size(table) == 1);
 +#endif
 +return table-len;
 +}
 +
 +static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
 +{
 +uint32_t offset = cpu_to_le32(table_data-len);
 +g_array_append_val(table_offsets, offset);
 +}
 +
 +/* RSDP */
 +static GArray *
 +build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t xsdt)
 +{
 +return rsdp_table;
 +}
 +
 +/* XSDT */
 +static void
 +build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 +{
 +}
 +
 +/* MADT */
 +static void
 +build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 +{
 +}
 +
 +/* GTDT */
 +static void
 +build_gtdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 +{
 +}
 +
 +/* FADT */
 +static void
 +build_fadt(GArray *table_data, GArray *linker, uint64_t facs, uint64_t dsdt)
 +{
 +}
 +
 +/* FACS */
 +static void
 +build_facs(GArray *table_data, GArray 

Re: [Qemu-devel] [RFC PATCH 04/11] hw/arm/virt-acpi-build: Generate XSDT table and add a build_header function

2015-01-24 Thread Laszlo Ersek
comments below, fix attached

On 01/24/15 10:21, Shannon Zhao wrote:
 XDST points to other tables except FACS  DSDT.
 Implement a common header helper functions for generating ACPI tables.
 
 Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
 ---
  hw/arm/virt-acpi-build.c|   34 ++
  include/hw/acpi/acpi-defs.h |9 +
  2 files changed, 43 insertions(+), 0 deletions(-)
 
 diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
 index 9c3971a..446947a 100644
 --- a/hw/arm/virt-acpi-build.c
 +++ b/hw/arm/virt-acpi-build.c
 @@ -61,6 +61,22 @@
  #define ACPI_BUILD_RSDP_FILE etc/acpi/rsdp
  #define ACPI_BUILD_TPMLOG_FILE etc/tpm/log
  
 +static void
 +build_header(GArray *linker, GArray *table_data,
 + AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
 +{
 +memcpy(h-signature, sig, sizeof(h-signature));
 +h-length = cpu_to_le32(len);
 +h-revision = rev;
 +memcpy(h-oem_id, ACPI_VIRT_QEMU_STR_6, sizeof(h-oem_id));
 +memcpy(h-oem_table_id, ACPI_VIRT_MACH_STR_8, sizeof(h-oem_table_id));
 +h-oem_revision = cpu_to_le32(1);
 +h-checksum = 0;
 +/* Checksum to be filled in by Guest linker */
 +bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
 +table_data-data, h, len, h-checksum);
 +}
 +
  static inline void *acpi_data_push(GArray *table_data, uint64_t size)
  {
  unsigned off = table_data-len;
 @@ -115,6 +131,24 @@ build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t 
 xsdt)
  static void
  build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
  {
 +AcpiXsdtDescriptor *xsdt;
 +size_t xsdt_len;
 +int i;
 +
 +xsdt_len = sizeof(*xsdt) + sizeof(uint64_t) * table_offsets-len;
 +xsdt = acpi_data_push(table_data, xsdt_len);
 +memcpy(xsdt-table_offset_entry, table_offsets-data,
 +   sizeof(uint64_t) * table_offsets-len);

This is a bug, but it's not introduced here. The bug is introduced in:

  [RFC PATCH 02/11] hw/arm/virt-acpi-build: Basic framework for
building ACPI tables

I'm attaching the fix.

Please do not squash the fix into this patch; you have to split it up.
The code fixes go into 02/11, and the typo fix goes:

 +for (i = 0; i  table_offsets-len; ++i) {
 +/* rsdt-table_offset_entry to be filled by Guest linker */

here.

Thanks,
Laszlo
From 899ed2c6329c33520f5bad143dd50508012f1f27 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek ler...@redhat.com
Date: Sat, 24 Jan 2015 20:43:48 +0100
Subject: [PATCH] virt-acpi-build: internal representation for XSDT entries
 must be uint64_t

The build_xsdt() function copies the data contents of the gradually built
table_offsets GArray directly into the XSDT, with memcpy(), using an
element type of uint64_t.

For this to work, the element type of the source array, table_offsets,
must also be uint64_t.

Otherwise, the XSDT entries will be filled with garbage, pointing outside
of the target blob. edk2's linker/loader catches  rejects the first
pointer:

   Loading driver at 0x000BEE36000 EntryPoint=0x000BEE362B0 AcpiPlatformDxe.efi
   InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF BB7BCE98
   ProcessCmdAllocate: File=etc/acpi/rsdp Alignment=0x10 Zone=2 Size=0x24 Address=0xB7048000
   ProcessCmdAllocate: File=etc/acpi/tables Alignment=0x40 Zone=1 Size=0xB4E Address=0xB7047000
   ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0x49 Start=0x40 Length=0x8CE
   ProcessCmdAddPointer: PointerFile=etc/acpi/tables PointeeFile=etc/acpi/tables PointerOffset=0x992 PointerSize=8
   ProcessCmdAddPointer: PointerFile=etc/acpi/tables PointeeFile=etc/acpi/tables PointerOffset=0x99A PointerSize=8
   ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0x917 Start=0x90E Length=0x10C
   ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0xA23 Start=0xA1A Length=0x90
   ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0xAB3 Start=0xAAA Length=0x60
- ProcessCmdAddPointer: invalid pointer value in etc/acpi/tables
   InstallAllQemuLinkedTables: freeing etc/acpi/rsdp
   InstallAllQemuLinkedTables: freeing etc/acpi/tables
   Error: Image at 000BEE36000 start failed: Protocol Error

Signed-off-by: Laszlo Ersek ler...@redhat.com
---
 hw/arm/virt-acpi-build.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 5c76ca2..904fc33 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -94,7 +94,7 @@ static unsigned acpi_data_len(GArray *table)
 
 static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
 {
-uint32_t offset = cpu_to_le32(table_data-len);
+uint64_t offset = cpu_to_le64(table_data-len);
 g_array_append_val(table_offsets, offset);
 }
 
@@ -245,7 +245,7 @@ build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 memcpy(xsdt-table_offset_entry, table_offsets-data,

Re: [Qemu-devel] qemu-coroutine.c: error: thread-local storage not supported for this target

2015-01-24 Thread Paolo Bonzini
The lack of emulated TLS on 10.6 is the consequence of a political choice, 
though. GCC 4.3 was released long before Snow Leopard, but users are stuck with 
4.2.1 because of the license.

Paolo


-Original Message-
From: Peter Maydell [peter.mayd...@linaro.org]
Received: sabato, 24 gen 2015, 20:33
To: Paolo Bonzini [pbonz...@redhat.com]
CC: Programmingkid [programmingk...@gmail.com]; Kevin Wolf [kw...@redhat.com]; 
qemu-devel qemu-devel [qemu-devel@nongnu.org]
Subject: Re: [Qemu-devel] qemu-coroutine.c: error: thread-local storage not 
supported for this target

On 24 January 2015 at 18:54, Paolo Bonzini pbonz...@redhat.com wrote:
 Note that GCC 4.3 was released almost seven years ago; we've been
 requiring it on Windows for three years (commit 00dccaf, coroutine:
 introduce coroutines, 2011-01-17), and no one has ever complained.

 Apple is not providing it for Mac OS X 10.6.x only because of political
 reasons.  Complain to them, not to the QEMU project.

Apple's not providing it on 10.6.x because 10.6.x is obsolete
as far as Apple is concerned. Supported versions of OSX use
clang, which has support for __thread. Missing __thread
support is an old platform thing, not a political GPL thing.

-- PMM


Re: [Qemu-devel] [RFC PATCH 07/11] hw/arm/virt-acpi-build: Generate FADT table and update ACPI headers

2015-01-24 Thread Laszlo Ersek
comments below

On 01/24/15 10:21, Shannon Zhao wrote:
 FADT points to FACS and DSDT, in the case of mach virt, it is also used
 to set the Hardware Reduced bit and enable PSCI SMP booting through HVC.
 
 Update the header definitions for FADT taking into account the new
 additions of ACPI v5.1 in `include/hw/acpi/acpi-defs.h`
 
 Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
 ---
  hw/arm/virt-acpi-build.c|   26 ++
  include/hw/acpi/acpi-defs.h |  114 
 +--
  2 files changed, 103 insertions(+), 37 deletions(-)
 
 diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
 index 2872dff..e3c708d 100644
 --- a/hw/arm/virt-acpi-build.c
 +++ b/hw/arm/virt-acpi-build.c
 @@ -218,6 +218,32 @@ build_gtdt(GArray *table_data, GArray *linker, 
 VirtGuestInfo *guest_info)
  static void
  build_fadt(GArray *table_data, GArray *linker, uint64_t facs, uint64_t dsdt)
  {
 +AcpiFadtDescriptorRev5_1 *fadt = acpi_data_push(table_data, 
 sizeof(*fadt));
 +
 +/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */

You set Hardware Reduced here.

 +fadt-flags = cpu_to_le32(1  ACPI_FADT_F_HW_REDUCED_ACPI);
 +fadt-arm_boot_flags = cpu_to_le16((1  ACPI_FADT_ARM_USE_PSCI_G_0_2) |
 +   (1  ACPI_FADT_ARM_PSCI_USE_HVC));
 +
 +/* ACPI v5.1 (fadt-revision.fadt-minor_revision) */
 +fadt-minor_revision = 0x1;
 +
 +fadt-Xfacs = cpu_to_le64(facs);

But you also set up a FACS table.

Hardware Reduced mode makes Linux ignore the FACS table. Please see
upstream kernel commit

commit 22e5b40ab21fcac21db0ff25fbb844ffecc73a4a
Author: Bob Moore robert.mo...@intel.com
Date:   Wed Nov 16 10:57:28 2011 +0800

ACPI 5.0: Implement hardware-reduced option

You can probably drop the generation of the FACS, unless you intend to
disable HW reduced mode.

Thanks
Laszlo




Re: [Qemu-devel] [RFC PATCH 11/11] hw/arm/virt: Enable dynamic generation of ACPI v5.1 tables

2015-01-24 Thread Laszlo Ersek
On 01/24/15 10:21, Shannon Zhao wrote:
 Expose the needed device information to the table generation
 insfrastructure and register a machine_init_done notify to
 call virt_acpi_build().
 
 Add CONFIG_ACPI to arm-softmmu.mak, but there is compile error.
 Don't include unnecessary file for ARM. Maybe this way is not
 right, fix me please.
 
 Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
 ---
  default-configs/arm-softmmu.mak  |1 +
  default-configs/i386-softmmu.mak |3 ++
  default-configs/mips-softmmu.mak |3 ++
  default-configs/mips64-softmmu.mak   |3 ++
  default-configs/mips64el-softmmu.mak |3 ++
  default-configs/mipsel-softmmu.mak   |3 ++
  default-configs/x86_64-softmmu.mak   |3 ++
  hw/acpi/Makefile.objs|5 ++-
  hw/arm/virt.c|   59 +++--
  hw/i2c/Makefile.objs |2 +-
  10 files changed, 78 insertions(+), 7 deletions(-)

 diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
 index cad0355..4e3f15f 100644
 --- a/hw/acpi/Makefile.objs
 +++ b/hw/acpi/Makefile.objs
 @@ -1,5 +1,6 @@
 -common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
 -common-obj-$(CONFIG_ACPI) += memory_hotplug.o
 +common-obj-$(CONFIG_ACPI_CORE) += core.o piix4.o ich9.o pcihp.o
 +common-obj-$(CONFIG_ACPI_HOTPLUG) += cpu_hotplug.o

This line has a typo and it breaks the linking of qemu-system-x86_64.
You need to say

  CONFIG_ACPI_CPU_HOTPLUG

here, not

  CONFIG_ACPI_HOTPLUG

Thanks
Laszlo




Re: [Qemu-devel] [PATCH 04/11] target-arm: Define correct mmu_idx values and pass them in TB flags

2015-01-24 Thread Peter Maydell
On 24 January 2015 at 16:36, Greg Bellows greg.bell...@linaro.org wrote:
 I understand what the code is doing, my point is that you rely on
 arm_is_secure_below_el3 to deal with EL2 when you could have just as easily
 checked for el2.  Not a big deal though.

Well, I rely on the architecture to tell me that it isn't
possible for arm_is_secure_below_el3 to be true if we're
in EL2. Otherwise there'd be a bug in that function...

-- PMM



Re: [Qemu-devel] [RFC PATCH 00/11] Generate ACPI v5.1 tables and expose it to guest over fw_cfg on ARM

2015-01-24 Thread Laszlo Ersek
On 01/24/15 10:21, Shannon Zhao wrote:
 This patch series generate seven ACPI v5.1 tables for machine virt on
 ARM.
 The set of generated tables are:
 - RSDP
 - XSDT
 - MADT
 - GTDT
 - FADT
 - FACS
 - DSDT

 These tables are created dynamically using the function of
 acpi-build-utils.c, taking into account the needed information passed
 from the virt machine model. When the generation is finalized, it use
 fw_cfg to expose the tables to guest.

 This patchset is based on Igor Mammedov's branch which can be found at
 below git tree:
  https://github.com/imammedo/qemu/commits/ASL_API_v2

Awesome! I didn't know you had been coordinating with Igor. This is the
best (or, put differently, only :)) possible way forward. Great!

 And this patchset refers to Alexander Spyridakis's patches which are
 sent to qemu-devel mailing list before.
  http://lists.gnu.org/archive/html/qemu-devel/2014-10/msg03987.html

 As UEFI (ArmVirtualizationQemu) doesn't support downloading ACPI
 tables over fw_cfg, I just do compile test and start a guest with
 UEFI. But I contacted Laszlo Ersek before, he says that if qemu can
 expose the generated ACPI tables over fw_cfg, he can quickly add
 support in UEFI. So just send this out and make it go forward.

I hope I was quick enough:
- patches: http://thread.gmane.org/gmane.comp.bios.tianocore.devel/12158
- branch: https://github.com/lersek/edk2/commits/armvirt_acpi
- binary: http://people.redhat.com/~lersek/armvirt_acpi/QEMU_EFI.fd


 Todo:
 1) add GPIO controller in virt and expose it through ACPI
 2) add cpu hotplug support

 Any comments are welcome.

I answered with a couple of notes and fixes in the thread. I found those
via testing. I won't offer a code review; I hope you don't mind.

For testing on your end (and for further development) before the edk2
series is applied, you can fetch my patches from github, or even use the
binary I built for you.

Note: the binary includes a very small patch that is not upstream. (Well
it includes some other patches too, but they are not relevant.) This is
it:

 --- a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
 +++ b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
 @@ -87,7 +87,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE

  [PcdsFixedAtBuild.common]
 -  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x804F
 +  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8040004F

gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|QEMU

It enables the EFI_D_VERBOSE loglevel. The ACPI code logs quite a bit of
info on this loglevel, so if you build an image yourself, be sure to
enable EFI_D_VERBOSE manually. Otherwise you'll only see a part of this
log fragment:

 Loading driver at 0x000BEE66000 EntryPoint=0x000BEE662B0 AcpiPlatformDxe.efi
 InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF BB7BBE98
 ProcessCmdAllocate: File=etc/acpi/rsdp Alignment=0x10 Zone=2 Size=0x24 
 Address=0xB7048000
 ProcessCmdAllocate: File=etc/acpi/tables Alignment=0x40 Zone=1 Size=0xBC0 
 Address=0xB7047000
 ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0x49 Start=0x40 
 Length=0x8F4
 ProcessCmdAddPointer: PointerFile=etc/acpi/tables 
 PointeeFile=etc/acpi/tables PointerOffset=0x9B8 PointerSize=8
 ProcessCmdAddPointer: PointerFile=etc/acpi/tables 
 PointeeFile=etc/acpi/tables PointerOffset=0x9C0 PointerSize=8
 ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0x93D Start=0x934 
 Length=0x10C
 ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0xA49 Start=0xA40 
 Length=0xDC
 ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0xB25 Start=0xB1C 
 Length=0x60
 ProcessCmdAddPointer: PointerFile=etc/acpi/tables 
 PointeeFile=etc/acpi/tables PointerOffset=0xBA0 PointerSize=8
 ProcessCmdAddPointer: PointerFile=etc/acpi/tables 
 PointeeFile=etc/acpi/tables PointerOffset=0xBA8 PointerSize=8
 ProcessCmdAddPointer: PointerFile=etc/acpi/tables 
 PointeeFile=etc/acpi/tables PointerOffset=0xBB0 PointerSize=8
 ProcessCmdAddChecksum: File=etc/acpi/tables ResultOffset=0xB85 Start=0xB7C 
 Length=0x44
 ProcessCmdAddPointer: PointerFile=etc/acpi/rsdp 
 PointeeFile=etc/acpi/tables PointerOffset=0x18 PointerSize=8
 ProcessCmdAddChecksum: File=etc/acpi/rsdp ResultOffset=0x8 Start=0x0 
 Length=0x24
 Process2ndPassCmdAddPointer: checking for ACPI header in etc/acpi/tables at 
 0xB7047000 (remaining: 0xBC0): found FACS size 0x40
 Process2ndPassCmdAddPointer: checking for ACPI header in etc/acpi/tables at 
 0xB7047040 (remaining: 0xB80): found DSDT size 0x8F4
 Process2ndPassCmdAddPointer: checking for ACPI header in etc/acpi/tables at 
 0xB7047934 (remaining: 0x28C): found FACP size 0x10C
 Process2ndPassCmdAddPointer: checking for ACPI header in etc/acpi/tables at 
 0xB7047A40 (remaining: 0x180): found APIC size 0xDC
 Process2ndPassCmdAddPointer: checking for ACPI header in etc/acpi/tables at 
 0xB7047B1C (remaining: 0xA4): found GTDT size 0x60
 Process2ndPassCmdAddPointer: checking for ACPI header in 

[Qemu-devel] [PATCH v2] linux-user/syscall.c: Need call unlock_user() before go to failure return in default case

2015-01-24 Thread Chen Gang S
In abi_long do_ioctl_dm(), after calls lock_user(), it does not call
unlock_user() before go to failure return in default case.

Signed-off-by: Chen Gang gang.chen.5...@gmail.com
---
 linux-user/syscall.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a427f7a..ec9e4fc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3566,6 +3566,7 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t 
*buf_temp, int fd,
 }
 default:
 ret = -TARGET_EINVAL;
+unlock_user(argptr, guest_data, 0);
 goto out;
 }
 unlock_user(argptr, guest_data, 0);
@@ -3685,6 +3686,7 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t 
*buf_temp, int fd,
 break;
 }
 default:
+unlock_user(argptr, guest_data, 0);
 ret = -TARGET_EINVAL;
 goto out;
 }
-- 
1.9.3



Re: [Qemu-devel] [PATCH 04/11] target-arm: Define correct mmu_idx values and pass them in TB flags

2015-01-24 Thread Greg Bellows
On Jan 23, 2015 7:12 PM, Peter Maydell peter.mayd...@linaro.org wrote:

 On 23 January 2015 at 21:44, Greg Bellows greg.bell...@linaro.org wrote:
  On Fri, Jan 23, 2015 at 12:20 PM, Peter Maydell
  peter.mayd...@linaro.org wrote:
  +typedef enum ARMMMUIdx {
  +ARMMMUIdx_S12NSE0 = 0,
  +ARMMMUIdx_S12NSE1 = 1,
  +ARMMMUIdx_S1E2 = 2,
  +ARMMMUIdx_S1E3 = 3,
  +ARMMMUIdx_S1SE0 = 4,
  +ARMMMUIdx_S1SE1 = 5,
  +ARMMMUIdx_S2NS = 6,
  +/* Indexes below here don't have TLBs and are used only for AT
system
  + * instructions or for the first stage of an S12 page table walk.
  + */
  +ARMMMUIdx_S1NSE0 = 7,
  +ARMMMUIdx_S1NSE1 = 8,
  +} ARMMMUIdx;
  +
   #define MMU_MODE0_SUFFIX _user
   #define MMU_MODE1_SUFFIX _kernel
   #define MMU_USER_IDX 0
  +
  +/* Return the exception level we're running at if this is our mmu_idx
*/
  +static inline int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx)
  +{
  +assert(mmu_idx  ARMMMUIdx_S2NS);
  +return mmu_idx  3;
  +}
  +
  +/* Determine the current mmu_idx to use for normal loads/stores */
   static inline int cpu_mmu_index (CPUARMState *env)
   {
  -return arm_current_el(env);
  +int el = arm_current_el(env);
  +
  +if (el  3  arm_is_secure_below_el3(env)) {
 
  We bypass the secure check for EL3 but not EL2.  We should either
  circumvent both EL2  3 or neither.

 Not sure what you mean here. The point of this code is to return
 a suitable MMU idx for the current CPU state. If we are in
 EL2 or EL3 then just el is correct (being ARMMMUIdx_S1E2 and
 ARMMMUIdx_S1E3). We can't be in this condition with el == 2

I understand what the code is doing, my point is that you rely on
arm_is_secure_below_el3 to deal with EL2 when you could have just as easily
checked for el2.  Not a big deal though.

 because if we're in EL2 then the NS bit must be set (there's
 no such thing as Secure EL2) and so arm_is_secure_below_el3()
 will have returned false. So we know here that el is 0 or 1,
 and this addition below:

  +return ARMMMUIdx_S1SE0 + el;

 means we end up with either _S1SE0 or _S1SE1, as required.

 (the condition could equally well be written
if (el  2  arm_is_secure_below_el3(env))
  as the two are true in exactly the same set of cases.  3 seemed
  marginally better to me, since it's expressing if we're secure
 and not in EL3 which is the set of cases where we need to
 change the mmu_idx from the 0/1/2/3 values.)

  +}
  +return el;

 Anything else (_S12NSE0, _S12NSE1, _S1E2, _S1E3) is this return.

   }

 thanks
 -- PMM


Re: [Qemu-devel] [PATCH 2/2] hw/ppc/spapr Add qemu_register_boot_set for SPAPR

2015-01-24 Thread Dinar Valeev

On 01/24/2015 12:04 AM, Alexander Graf wrote:



On 23.01.15 23:51, dval...@suse.de wrote:

From: Dinar Valeev dval...@suse.com

In order to have -boot once=d functioning, it is required to have
qemu_register_boot_set

qemu-system-ppc64 -enable-kvm -boot once=d

Ready!
0  dev /chosen   ok
0  .properties
...
qemu,boot-device d
...
0  reset-all

Ready!
0  dev /chosen   ok
0  .properties
...
qemu,boot-device cdn
...

Signed-off-by: Dinar Valeev dval...@suse.com
---
  hw/ppc/spapr.c | 12 
  1 file changed, 12 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 3d2cfa3..38b03fc 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -314,6 +314,16 @@ static void add_str(GString *s, const gchar *s1)
  g_string_append_len(s, s1, strlen(s1) + 1);
  }

+static void spapr_boot_set(void *opaque, const char *boot_device,
+   Error **errp)
+{
+int offset;
+offset = fdt_path_offset(opaque, /chosen);
+fdt_setprop_string(opaque, offset, qemu,boot-device, boot_device);
+
+}
+
+
  static void *spapr_create_fdt_skel(hwaddr initrd_base,
 hwaddr initrd_size,
 hwaddr kernel_size,
@@ -414,6 +424,8 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
  if (boot_device) {
  _FDT((fdt_property_string(fdt, qemu,boot-device, boot_device)));
  }
+qemu_register_boot_set(spapr_boot_set, fdt);


If you simply move the code above (the _FDT() one) from create_fdt_skel
to spapr_finalize_fdt() you should have the same net effect and much
cleaner code :).
Haven't tried it, but I suspect -boot once=d on reset will be still 
equal to -boot d behaviour.


And does it make sense to split boot_device from the rest?


Alex


+
  if (boot_menu) {
  _FDT((fdt_property_cell(fdt, qemu,boot-menu, boot_menu)));
  }






[Qemu-devel] [RFC PATCH 02/11] hw/arm/virt-acpi-build: Basic framework for building ACPI tables

2015-01-24 Thread Shannon Zhao
Introduce a preliminary framework in virt-acpi-build.c with the main
ACPI build functions. It exposes the generated ACPI contents to
guest over fw_cfg. Some codes borrowed from hw/i386/acpi-build.c.

The minimum required ACPI v5.1 tables for ARM are:
- RSDP: Initial table that points to XSDT
- XSDT: Points to all other tables (except FACS  DSDT)
- FADT: Generic information about the machine
- DSDT: Holds all information about system devices/peripherals
- FACS: Needs to be pointed from FADT

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/Makefile.objs |1 +
 hw/arm/virt-acpi-build.c |  263 ++
 include/hw/arm/virt-acpi-build.h |   71 ++
 3 files changed, 335 insertions(+), 0 deletions(-)
 create mode 100644 hw/arm/virt-acpi-build.c
 create mode 100644 include/hw/arm/virt-acpi-build.h

diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 6088e53..8daf825 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -3,6 +3,7 @@ obj-$(CONFIG_DIGIC) += digic_boards.o
 obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o
 obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o
 obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o
+obj-$(CONFIG_ACPI) += virt-acpi-build.o
 
 obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
 obj-$(CONFIG_DIGIC) += digic.o
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
new file mode 100644
index 000..4eed0a3
--- /dev/null
+++ b/hw/arm/virt-acpi-build.c
@@ -0,0 +1,263 @@
+/* Support for generating ACPI tables and passing them to Guests
+ *
+ * ARM virt ACPI generation
+ *
+ * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD.
+ *
+ * Author: Shannon Zhao zhaoshengl...@huawei.com
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/.
+ */
+
+#include hw/arm/virt-acpi-build.h
+#include stddef.h
+#include glib.h
+#include qemu-common.h
+#include qemu/bitmap.h
+#include qemu/osdep.h
+#include qemu/range.h
+#include qemu/error-report.h
+#include qom/cpu.h
+#include target-arm/cpu.h
+#include hw/acpi/acpi-defs.h
+#include hw/acpi/acpi.h
+#include hw/nvram/fw_cfg.h
+#include hw/acpi/bios-linker-loader.h
+#include hw/loader.h
+
+#include hw/acpi/acpi-build-utils.h
+
+#include qapi/qmp/qint.h
+#include qom/qom-qobject.h
+#include exec/ram_addr.h
+
+
+#define ACPI_BUILD_TABLE_SIZE 0x2
+
+/* Reserve RAM space for tables: add another order of magnitude. */
+#define ACPI_BUILD_TABLE_MAX_SIZE 0x20
+
+/* #define DEBUG_ACPI_BUILD */
+#ifdef DEBUG_ACPI_BUILD
+#define ACPI_BUILD_DPRINTF(fmt, ...)\
+do {printf(ACPI_BUILD:  fmt, ## __VA_ARGS__); } while (0)
+#else
+#define ACPI_BUILD_DPRINTF(fmt, ...)
+#endif
+
+#define ACPI_BUILD_APPNAME  Bochs
+#define ACPI_BUILD_APPNAME6 BOCHS 
+
+#define ACPI_BUILD_RSDP_FILE etc/acpi/rsdp
+#define ACPI_BUILD_TPMLOG_FILE etc/tpm/log
+
+static inline void *acpi_data_push(GArray *table_data, uint64_t size)
+{
+unsigned off = table_data-len;
+g_array_set_size(table_data, off + size);
+return table_data-data + off;
+}
+
+static unsigned acpi_data_len(GArray *table)
+{
+#if GLIB_CHECK_VERSION(2, 22, 0)
+assert(g_array_get_element_size(table) == 1);
+#endif
+return table-len;
+}
+
+static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
+{
+uint32_t offset = cpu_to_le32(table_data-len);
+g_array_append_val(table_offsets, offset);
+}
+
+/* RSDP */
+static GArray *
+build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t xsdt)
+{
+return rsdp_table;
+}
+
+/* XSDT */
+static void
+build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+{
+}
+
+/* MADT */
+static void
+build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
+{
+}
+
+/* GTDT */
+static void
+build_gtdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
+{
+}
+
+/* FADT */
+static void
+build_fadt(GArray *table_data, GArray *linker, uint64_t facs, uint64_t dsdt)
+{
+}
+
+/* FACS */
+static void
+build_facs(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
+{
+}
+
+/* DSDT */
+static void
+build_dsdt(AcpiAml *table_aml, GArray *linker, VirtGuestInfo *guest_info)
+{
+}
+
+typedef
+struct AcpiBuildTables {
+AcpiAml table_data;
+GArray *rsdp;
+GArray *tcpalog;
+GArray *linker;
+} AcpiBuildTables;
+
+static inline void 

[Qemu-devel] [PATCH v1 1/2] target_arm: Remove memory region init from armv7m_init

2015-01-24 Thread Alistair Francis
This patch moves the memory region init code from the
armv7m_init function to the stellaris_init function

Signed-off-by: Alistair Francis alistai...@gmail.com
Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---
This has been split from the Netduino 2 machine patch
series.

 hw/arm/armv7m.c  | 33 +++--
 hw/arm/stellaris.c   | 24 
 include/hw/arm/arm.h |  3 +--
 3 files changed, 24 insertions(+), 36 deletions(-)

diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index ef24ca4..50281f7 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -163,11 +163,10 @@ static void armv7m_reset(void *opaque)
 }
 
 /* Init CPU and memory for a v7-M based board.
-   flash_size and sram_size are in kb.
+   mem_size is in bytes.
Returns the NVIC array.  */
 
-qemu_irq *armv7m_init(MemoryRegion *system_memory,
-  int flash_size, int sram_size,
+qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size,
   const char *kernel_filename, const char *cpu_model)
 {
 ARMCPU *cpu;
@@ -180,13 +179,8 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory,
 uint64_t lowaddr;
 int i;
 int big_endian;
-MemoryRegion *sram = g_new(MemoryRegion, 1);
-MemoryRegion *flash = g_new(MemoryRegion, 1);
 MemoryRegion *hack = g_new(MemoryRegion, 1);
 
-flash_size *= 1024;
-sram_size *= 1024;
-
 if (cpu_model == NULL) {
cpu_model = cortex-m3;
 }
@@ -197,27 +191,6 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory,
 }
 env = cpu-env;
 
-#if 0
-/*  32Mb SRAM gets complicated because it overlaps the bitband area.
-   We don't have proper commandline options, so allocate half of memory
-   as SRAM, up to a maximum of 32Mb, and the rest as code.  */
-if (ram_size  (512 + 32) * 1024 * 1024)
-ram_size = (512 + 32) * 1024 * 1024;
-sram_size = (ram_size / 2)  TARGET_PAGE_MASK;
-if (sram_size  32 * 1024 * 1024)
-sram_size = 32 * 1024 * 1024;
-code_size = ram_size - sram_size;
-#endif
-
-/* Flash programming is done via the SCU, so pretend it is ROM.  */
-memory_region_init_ram(flash, NULL, armv7m.flash, flash_size,
-   error_abort);
-vmstate_register_ram_global(flash);
-memory_region_set_readonly(flash, true);
-memory_region_add_subregion(system_memory, 0, flash);
-memory_region_init_ram(sram, NULL, armv7m.sram, sram_size, error_abort);
-vmstate_register_ram_global(sram);
-memory_region_add_subregion(system_memory, 0x2000, sram);
 armv7m_bitband_init();
 
 nvic = qdev_create(NULL, armv7m_nvic);
@@ -244,7 +217,7 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory,
 image_size = load_elf(kernel_filename, NULL, NULL, entry, lowaddr,
   NULL, big_endian, ELF_MACHINE, 1);
 if (image_size  0) {
-image_size = load_image_targphys(kernel_filename, 0, flash_size);
+image_size = load_image_targphys(kernel_filename, 0, mem_size);
 lowaddr = 0;
 }
 if (image_size  0) {
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 64bd4b4..d0c61c5 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -1220,10 +1220,26 @@ static void stellaris_init(const char *kernel_filename, 
const char *cpu_model,
 int i;
 int j;
 
-flash_size = ((board-dc0  0x) + 1)  1;
-sram_size = (board-dc0  18) + 1;
-pic = armv7m_init(get_system_memory(),
-  flash_size, sram_size, kernel_filename, cpu_model);
+MemoryRegion *sram = g_new(MemoryRegion, 1);
+MemoryRegion *flash = g_new(MemoryRegion, 1);
+MemoryRegion *system_memory = get_system_memory();
+
+flash_size = (((board-dc0  0x) + 1)  1) * 1024;
+sram_size = ((board-dc0  18) + 1) * 1024;
+
+/* Flash programming is done via the SCU, so pretend it is ROM.  */
+memory_region_init_ram(flash, NULL, stellaris.flash, flash_size,
+   error_abort);
+vmstate_register_ram_global(flash);
+memory_region_set_readonly(flash, true);
+memory_region_add_subregion(system_memory, 0, flash);
+
+memory_region_init_ram(sram, NULL, stellaris.sram, sram_size,
+   error_abort);
+vmstate_register_ram_global(sram);
+memory_region_add_subregion(system_memory, 0x2000, sram);
+
+pic = armv7m_init(system_memory, flash_size, kernel_filename, cpu_model);
 
 if (board-dc1  (1  16)) {
 dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h
index c4bf56d..f8b329b 100644
--- a/include/hw/arm/arm.h
+++ b/include/hw/arm/arm.h
@@ -15,8 +15,7 @@
 #include hw/irq.h
 
 /* armv7m.c */
-qemu_irq *armv7m_init(MemoryRegion *system_memory,
-  int flash_size, int sram_size,
+qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size,
   const 

[Qemu-devel] [RFC PATCH 08/11] hw/arm/virt-acpi-build: Generate FACS table and update ACPI headers

2015-01-24 Thread Shannon Zhao
FACS table is created as a mockup, as with the Hardware Reduced bit
set it will not be used.

Update the header definitions for FACS taking into account the new
additions of ACPI v5.1 in `include/hw/acpi/acpi-defs.h`

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c|4 
 include/hw/acpi/acpi-defs.h |   28 +---
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index e3c708d..de1f307 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -250,6 +250,10 @@ build_fadt(GArray *table_data, GArray *linker, uint64_t 
facs, uint64_t dsdt)
 static void
 build_facs(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
+AcpiFacsDescriptorRev5_1 *facs = acpi_data_push(table_data, sizeof *facs);
+memcpy(facs-signature, FACS, sizeof(facs-signature));
+facs-length = cpu_to_le32(sizeof(*facs));
+facs-version = 0x02;
 }
 
 /* DSDT */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index c1255fa..91b3520 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -196,20 +196,34 @@ struct AcpiRsdtDescriptorRev1
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
 
 /*
- * ACPI 1.0 Firmware ACPI Control Structure (FACS)
+ * ACPI Firmware ACPI Control Structure (FACS)
  */
+#define ACPI_FACS_COMMON_DEF /* FACS common definition */ \
+uint32_t signature;   /* ACPI Signature */ \
+uint32_t length; /* Length of structure, in bytes */ \
+uint32_t hardware_signature; /* Hardware configuration signature */ \
+uint32_t firmware_waking_vector; /* ACPI OS waking vector */ \
+uint32_t global_lock;/* Global Lock */ \
+uint32_t flags;
+
 struct AcpiFacsDescriptorRev1
 {
-uint32_t signature;   /* ACPI Signature */
-uint32_t length; /* Length of structure, in bytes */
-uint32_t hardware_signature; /* Hardware configuration signature */
-uint32_t firmware_waking_vector; /* ACPI OS waking vector */
-uint32_t global_lock;/* Global Lock */
-uint32_t flags;
+ACPI_FACS_COMMON_DEF
 uint8_t  resverved3 [40];/* Reserved - must be zero */
 } QEMU_PACKED;
 typedef struct AcpiFacsDescriptorRev1 AcpiFacsDescriptorRev1;
 
+struct AcpiFacsDescriptorRev5_1 {
+ACPI_FACS_COMMON_DEF
+/* 64-bit version of the Firmware Waking Vector (ACPI 2.0+) */
+uint64_t xfirmware_waking_vector;
+uint8_t version; /* Version of this table (ACPI 2.0+) */
+uint8_t reserved[3]; /* Reserved, must be zero */
+uint32_t ospm_flags; /* Flags to be set by OSPM (ACPI 4.0) */
+uint8_t reserved1[24];   /* Reserved, must be zero */
+} QEMU_PACKED;
+typedef struct AcpiFacsDescriptorRev5_1 AcpiFacsDescriptorRev5_1;
+
 /*
  * Differentiated System Description Table (DSDT)
  */
-- 
1.7.1





[Qemu-devel] [RFC PATCH 09/11] hw/acpi/acpi-build-utils: Add acpi_fixed_memory32() and acpi_extended_irq()

2015-01-24 Thread Shannon Zhao
Add acpi_fixed_memory32() for describing device mmio region in resource 
template.
Add acpi_extended_irq() for describing device interrupt in resource template.
These can be used to generating DSDT table for ACPI on ARM.

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/acpi/acpi-build-utils.c |   42 
 include/hw/acpi/acpi-build-utils.h |2 +
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c
index 59873e3..211c4d3 100644
--- a/hw/acpi/acpi-build-utils.c
+++ b/hw/acpi/acpi-build-utils.c
@@ -493,6 +493,48 @@ AcpiAml acpi_call4(const char *method, AcpiAml arg1, 
AcpiAml arg2,
 }
 
 /*
+ * ACPI 5.1: 19.5.80 Memory32Fixed (Memory Resource Descriptor Macro)
+ *   6.4.2 Small Resource Data Type
+ */
+AcpiAml acpi_fixed_memory32(uint64_t addr, uint64_t size, uint8_t rw_flag)
+{
+AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+build_append_byte(var.buf, 0x86); /* Extended irq descriptor */
+build_append_byte(var.buf, 9);
+build_append_byte(var.buf, 0);
+build_append_byte(var.buf, rw_flag);
+build_append_byte(var.buf, addr  0xff);
+build_append_byte(var.buf, (addr  8)  0xff);
+build_append_byte(var.buf, (addr  16)  0xff);
+build_append_byte(var.buf, (addr  24)  0xff);
+
+build_append_byte(var.buf, size  0xff);
+build_append_byte(var.buf, (size  8)  0xff);
+build_append_byte(var.buf, (size  16)  0xff);
+build_append_byte(var.buf, (size  24)  0xff);
+return var;
+}
+
+/*
+ * ACPI 5.1: 19.5.61 Interrupt (Interrupt Resource Descriptor Macro)
+ *   6.4.2 Small Resource Data Type
+ */
+AcpiAml acpi_extended_irq(uint8_t irq_flags, int irq)
+{
+AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+build_append_byte(var.buf, 0x89); /* Extended irq descriptor */
+build_append_byte(var.buf, 6);
+build_append_byte(var.buf, 0);
+build_append_byte(var.buf, irq_flags);
+build_append_byte(var.buf, 0x01);
+build_append_byte(var.buf, irq  0xff);
+build_append_byte(var.buf, (irq  8)  0xff);
+build_append_byte(var.buf, (irq  16)  0xff);
+build_append_byte(var.buf, (irq  24)  0xff);
+return var;
+}
+
+/*
  * ACPI 5.0: 19.5.62 IO (IO Resource Descriptor Macro)
  *   6.4.2 Small Resource Data Type
 */
diff --git a/include/hw/acpi/acpi-build-utils.h 
b/include/hw/acpi/acpi-build-utils.h
index d39b5b1..bfed546 100644
--- a/include/hw/acpi/acpi-build-utils.h
+++ b/include/hw/acpi/acpi-build-utils.h
@@ -115,6 +115,8 @@ AcpiAml acpi_call3(const char *method, AcpiAml arg1, 
AcpiAml arg2,
AcpiAml arg3);
 AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
AcpiAml arg3, AcpiAml arg4);
+AcpiAml acpi_fixed_memory32(uint64_t addr, uint64_t size, uint8_t rw_flag);
+AcpiAml acpi_extended_irq(uint8_t irq_flags, int irq);
 AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
 uint8_t aln, uint8_t len);
 AcpiAml acpi_iqr_no_flags(uint8_t irq);
-- 
1.7.1





[Qemu-devel] [RFC PATCH 06/11] hw/arm/virt-acpi-build: Generate GTDT table

2015-01-24 Thread Shannon Zhao
ACPI v5.1 defines GTDT for ARM devices as a place to describe timer
related information in the system. The Arch Timer interrupts must
be provided for GTDT

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c|   21 +
 include/hw/acpi/acpi-defs.h |   37 +
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 4f55408..2872dff 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -191,6 +191,27 @@ build_madt(GArray *table_data, GArray *linker, 
VirtGuestInfo *guest_info)
 static void
 build_gtdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
+int gtdt_start = table_data-len;
+const struct acpi_gtdt_info *info = guest_info-gtdt_info;
+AcpiGenericTimerTable *gtdt;
+
+gtdt = acpi_data_push(table_data, sizeof *gtdt);
+/* The interrupt values are the same with the device tree when adding 16 */
+gtdt-secure_el1_interrupt = info-timer_s_el1;
+gtdt-secure_el1_flags = ACPI_EDGE_SENSITIVE;
+
+gtdt-non_secure_el1_interrupt = info-timer_ns_el1;
+gtdt-non_secure_el1_flags = ACPI_EDGE_SENSITIVE;
+
+gtdt-virtual_timer_interrupt = info-timer_virt;
+gtdt-virtual_timer_flags = ACPI_EDGE_SENSITIVE;
+
+gtdt-non_secure_el2_interrupt = info-timer_ns_el2;
+gtdt-non_secure_el2_flags = ACPI_EDGE_SENSITIVE;
+
+build_header(linker, table_data,
+ (void *)(table_data-data + gtdt_start), GTDT,
+ table_data-len - gtdt_start, 1);
 }
 
 /* FADT */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index b81926d..5633e04 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -288,6 +288,43 @@ struct AcpiMadtGenericDistributor {
 typedef struct AcpiMadtGenericDistributor AcpiMadtGenericDistributor;
 
 /*
+ * Generic Timer Description Table (GTDT)
+ */
+
+#define ACPI_GTDT_INTERRUPT_MODE(1)
+#define ACPI_GTDT_INTERRUPT_POLARITY(11)
+#define ACPI_GTDT_ALWAYS_ON (12)
+
+/* Triggering */
+
+#define ACPI_LEVEL_SENSITIVE(uint8_t) 0x00
+#define ACPI_EDGE_SENSITIVE (uint8_t) 0x01
+
+/* Polarity */
+
+#define ACPI_ACTIVE_HIGH(uint8_t) 0x00
+#define ACPI_ACTIVE_LOW (uint8_t) 0x01
+#define ACPI_ACTIVE_BOTH(uint8_t) 0x02
+
+struct AcpiGenericTimerTable {
+ACPI_TABLE_HEADER_DEF
+uint64_t counter_block_addresss;
+uint32_t reserved;
+uint32_t secure_el1_interrupt;
+uint32_t secure_el1_flags;
+uint32_t non_secure_el1_interrupt;
+uint32_t non_secure_el1_flags;
+uint32_t virtual_timer_interrupt;
+uint32_t virtual_timer_flags;
+uint32_t non_secure_el2_interrupt;
+uint32_t non_secure_el2_flags;
+uint64_t counter_read_block_address;
+uint32_t platform_timer_count;
+uint32_t platform_timer_offset;
+} QEMU_PACKED;
+typedef struct AcpiGenericTimerTable AcpiGenericTimerTable;
+
+/*
  * HPET Description Table
  */
 struct Acpi20Hpet {
-- 
1.7.1





[Qemu-devel] [RFC PATCH 01/11] hw/i386: Move ACPI header definitions in an arch-independent location

2015-01-24 Thread Shannon Zhao
The ACPI related header file acpi-defs.h, includes definitions that
apply on other architectures as well. Move it in `include/hw/acpi/`
to sanely include it from other architectures.

Signed-off-by: Alvise Rigo a.r...@virtualopensystems.com
Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/i386/acpi-build.c|2 +-
 hw/i386/acpi-defs.h |  368 ---
 include/hw/acpi/acpi-defs.h |  368 +++
 tests/bios-tables-test.c|2 +-
 4 files changed, 370 insertions(+), 370 deletions(-)
 delete mode 100644 hw/i386/acpi-defs.h
 create mode 100644 include/hw/acpi/acpi-defs.h

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f66da5d..f22f6d6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -33,7 +33,7 @@
 #include hw/i386/pc.h
 #include target-i386/cpu.h
 #include hw/timer/hpet.h
-#include hw/i386/acpi-defs.h
+#include hw/acpi/acpi-defs.h
 #include hw/acpi/acpi.h
 #include hw/nvram/fw_cfg.h
 #include hw/acpi/bios-linker-loader.h
diff --git a/hw/i386/acpi-defs.h b/hw/i386/acpi-defs.h
deleted file mode 100644
index c4468f8..000
--- a/hw/i386/acpi-defs.h
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see http://www.gnu.org/licenses/.
- */
-#ifndef QEMU_ACPI_DEFS_H
-#define QEMU_ACPI_DEFS_H
-
-enum {
-ACPI_FADT_F_WBINVD,
-ACPI_FADT_F_WBINVD_FLUSH,
-ACPI_FADT_F_PROC_C1,
-ACPI_FADT_F_P_LVL2_UP,
-ACPI_FADT_F_PWR_BUTTON,
-ACPI_FADT_F_SLP_BUTTON,
-ACPI_FADT_F_FIX_RTC,
-ACPI_FADT_F_RTC_S4,
-ACPI_FADT_F_TMR_VAL_EXT,
-ACPI_FADT_F_DCK_CAP,
-ACPI_FADT_F_RESET_REG_SUP,
-ACPI_FADT_F_SEALED_CASE,
-ACPI_FADT_F_HEADLESS,
-ACPI_FADT_F_CPU_SW_SLP,
-ACPI_FADT_F_PCI_EXP_WAK,
-ACPI_FADT_F_USE_PLATFORM_CLOCK,
-ACPI_FADT_F_S4_RTC_STS_VALID,
-ACPI_FADT_F_REMOTE_POWER_ON_CAPABLE,
-ACPI_FADT_F_FORCE_APIC_CLUSTER_MODEL,
-ACPI_FADT_F_FORCE_APIC_PHYSICAL_DESTINATION_MODE,
-ACPI_FADT_F_HW_REDUCED_ACPI,
-ACPI_FADT_F_LOW_POWER_S0_IDLE_CAPABLE,
-};
-
-/*
- * ACPI 2.0 Generic Address Space definition.
- */
-struct Acpi20GenericAddress {
-uint8_t  address_space_id;
-uint8_t  register_bit_width;
-uint8_t  register_bit_offset;
-uint8_t  reserved;
-uint64_t address;
-} QEMU_PACKED;
-typedef struct Acpi20GenericAddress Acpi20GenericAddress;
-
-struct AcpiRsdpDescriptor {/* Root System Descriptor Pointer */
-uint64_t signature;  /* ACPI signature, contains RSD PTR  */
-uint8_t  checksum;   /* To make sum of struct == 0 */
-uint8_t  oem_id [6]; /* OEM identification */
-uint8_t  revision;   /* Must be 0 for 1.0, 2 for 2.0 */
-uint32_t rsdt_physical_address;  /* 32-bit physical address of RSDT */
-uint32_t length; /* XSDT Length in bytes including hdr */
-uint64_t xsdt_physical_address;  /* 64-bit physical address of XSDT */
-uint8_t  extended_checksum;  /* Checksum of entire table */
-uint8_t  reserved [3];   /* Reserved field must be 0 */
-} QEMU_PACKED;
-typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor;
-
-/* Table structure from Linux kernel (the ACPI tables are under the
-   BSD license) */
-
-
-#define ACPI_TABLE_HEADER_DEF   /* ACPI common table header */ \
-uint32_t signature;  /* ACPI signature (4 ASCII characters) */ \
-uint32_t length; /* Length of table, in bytes, including 
header */ \
-uint8_t  revision;   /* ACPI Specification minor version # */ \
-uint8_t  checksum;   /* To make sum of entire table == 0 */ \
-uint8_t  oem_id [6]; /* OEM identification */ \
-uint8_t  oem_table_id [8];   /* OEM table identification */ \
-uint32_t oem_revision;   /* OEM revision number */ \
-uint8_t  asl_compiler_id [4];/* ASL compiler vendor ID */ \
-uint32_t asl_compiler_revision;  /* ASL compiler revision number */
-
-
-struct AcpiTableHeader /* ACPI common table header */
-{
-ACPI_TABLE_HEADER_DEF
-} QEMU_PACKED;
-typedef struct AcpiTableHeader AcpiTableHeader;
-
-/*
- * ACPI 1.0 Fixed ACPI Description Table (FADT)
- */
-struct AcpiFadtDescriptorRev1
-{
-ACPI_TABLE_HEADER_DEF /* ACPI common table header */
-uint32_t firmware_ctrl;  /* Physical address of FACS 

[Qemu-devel] [RFC PATCH 07/11] hw/arm/virt-acpi-build: Generate FADT table and update ACPI headers

2015-01-24 Thread Shannon Zhao
FADT points to FACS and DSDT, in the case of mach virt, it is also used
to set the Hardware Reduced bit and enable PSCI SMP booting through HVC.

Update the header definitions for FADT taking into account the new
additions of ACPI v5.1 in `include/hw/acpi/acpi-defs.h`

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c|   26 ++
 include/hw/acpi/acpi-defs.h |  114 +--
 2 files changed, 103 insertions(+), 37 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 2872dff..e3c708d 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -218,6 +218,32 @@ build_gtdt(GArray *table_data, GArray *linker, 
VirtGuestInfo *guest_info)
 static void
 build_fadt(GArray *table_data, GArray *linker, uint64_t facs, uint64_t dsdt)
 {
+AcpiFadtDescriptorRev5_1 *fadt = acpi_data_push(table_data, sizeof(*fadt));
+
+/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */
+fadt-flags = cpu_to_le32(1  ACPI_FADT_F_HW_REDUCED_ACPI);
+fadt-arm_boot_flags = cpu_to_le16((1  ACPI_FADT_ARM_USE_PSCI_G_0_2) |
+   (1  ACPI_FADT_ARM_PSCI_USE_HVC));
+
+/* ACPI v5.1 (fadt-revision.fadt-minor_revision) */
+fadt-minor_revision = 0x1;
+
+fadt-Xfacs = cpu_to_le64(facs);
+/* FACS address to be filled by Guest linker */
+bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+   ACPI_BUILD_TABLE_FILE,
+   table_data, fadt-Xfacs,
+   sizeof fadt-Xfacs);
+
+fadt-Xdsdt = cpu_to_le64(dsdt);
+/* DSDT address to be filled by Guest linker */
+bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+   ACPI_BUILD_TABLE_FILE,
+   table_data, fadt-Xdsdt,
+   sizeof fadt-Xdsdt);
+
+build_header(linker, table_data,
+ (void *)fadt, FACP, sizeof(*fadt), 5);
 }
 
 /* FACS */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 5633e04..c1255fa 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -97,46 +97,49 @@ struct AcpiXsdtDescriptor {
 typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
 
 /*
- * ACPI 1.0 Fixed ACPI Description Table (FADT)
+ * ACPI Fixed ACPI Description Table (FADT)
  */
+#define ACPI_FADT_COMMON_DEF /* FADT common definition */ \
+ACPI_TABLE_HEADER_DEF/* ACPI common table header */ \
+uint32_t firmware_ctrl;  /* Physical address of FACS */ \
+uint32_t dsdt;   /* Physical address of DSDT */ \
+uint8_t  model;  /* System Interrupt Model */ \
+uint8_t  reserved1;  /* Reserved */ \
+uint16_t sci_int;/* System vector of SCI interrupt */ \
+uint32_t smi_cmd;/* Port address of SMI command port */ \
+uint8_t  acpi_enable;/* Value to write to smi_cmd to enable 
ACPI */ \
+uint8_t  acpi_disable;   /* Value to write to smi_cmd to disable 
ACPI */ \
+uint8_t  S4bios_req; /* Value to write to SMI CMD to enter 
S4BIOS state */ \
+uint8_t  reserved2;  /* Reserved - must be zero */ \
+uint32_t pm1a_evt_blk;   /* Port address of Power Mgt 1a 
acpi_event Reg Blk */ \
+uint32_t pm1b_evt_blk;   /* Port address of Power Mgt 1b 
acpi_event Reg Blk */ \
+uint32_t pm1a_cnt_blk;   /* Port address of Power Mgt 1a Control 
Reg Blk */ \
+uint32_t pm1b_cnt_blk;   /* Port address of Power Mgt 1b Control 
Reg Blk */ \
+uint32_t pm2_cnt_blk;/* Port address of Power Mgt 2 Control 
Reg Blk */ \
+uint32_t pm_tmr_blk; /* Port address of Power Mgt Timer Ctrl 
Reg Blk */ \
+uint32_t gpe0_blk;   /* Port addr of General Purpose 
acpi_event 0 Reg Blk */ \
+uint32_t gpe1_blk;   /* Port addr of General Purpose 
acpi_event 1 Reg Blk */ \
+uint8_t  pm1_evt_len;/* Byte length of ports at pm1_x_evt_blk 
*/ \
+uint8_t  pm1_cnt_len;/* Byte length of ports at pm1_x_cnt_blk 
*/ \
+uint8_t  pm2_cnt_len;/* Byte Length of ports at pm2_cnt_blk */ 
\
+uint8_t  pm_tmr_len; /* Byte Length of ports at pm_tm_blk */ \
+uint8_t  gpe0_blk_len;   /* Byte Length of ports at gpe0_blk */ \
+uint8_t  gpe1_blk_len;   /* Byte Length of ports at gpe1_blk */ \
+uint8_t  gpe1_base;  /* Offset in gpe model where gpe1 events 
start */ \
+uint8_t  reserved3;  /* Reserved */ \
+uint16_t plvl2_lat;  /* Worst case HW latency to enter/exit C2 
state */ \
+uint16_t plvl3_lat;  /* Worst case HW latency to enter/exit C3 
state */ \
+uint16_t flush_size; /* Size of area read 

[Qemu-devel] [RFC PATCH 05/11] hw/arm/virt-acpi-build: Generate MADT table

2015-01-24 Thread Shannon Zhao
MADT describes GIC enabled ARM platforms. The GICC and GICD
subtables are used to define the GIC regions.

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c|   30 ++
 include/hw/acpi/acpi-defs.h |   37 -
 2 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 446947a..4f55408 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -155,6 +155,36 @@ build_xsdt(GArray *table_data, GArray *linker, GArray 
*table_offsets)
 static void
 build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
 {
+int madt_start = table_data-len;
+const struct acpi_madt_info *info = guest_info-madt_info;
+AcpiMultipleApicTable *madt;
+AcpiMadtGenericDistributor *gicd;
+int i;
+
+madt = acpi_data_push(table_data, sizeof *madt);
+madt-local_apic_address = *info-gic_cpu_base_addr;
+madt-flags = cpu_to_le32(1);
+
+for (i = 0; i  guest_info-max_cpus; i++) {
+AcpiMadtGenericInterrupt *gicc = acpi_data_push(table_data,
+ sizeof *gicc);
+gicc-type = ACPI_APIC_GENERIC_INTERRUPT;
+gicc-length = sizeof(*gicc);
+gicc-base_address = *info-gic_cpu_base_addr;
+gicc-cpu_interface_number = i;
+gicc-arm_mpidr = i;
+gicc-uid = i;
+gicc-flags = i  guest_info-nb_cpus ? cpu_to_le32(1) : 
cpu_to_le32(0);
+}
+
+gicd = acpi_data_push(table_data, sizeof *gicd);
+gicd-type = ACPI_APIC_GENERIC_DISTRIBUTOR;
+gicd-length = sizeof(*gicd);
+gicd-base_address = *info-gic_dist_base_addr;
+
+build_header(linker, table_data,
+ (void *)(table_data-data + madt_start), APIC,
+ table_data-len - madt_start, 1);
 }
 
 /* GTDT */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 779f872..b81926d 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -204,7 +204,14 @@ typedef struct AcpiMultipleApicTable AcpiMultipleApicTable;
 #define ACPI_APIC_IO_SAPIC   6
 #define ACPI_APIC_LOCAL_SAPIC7
 #define ACPI_APIC_XRUPT_SOURCE   8
-#define ACPI_APIC_RESERVED   9   /* 9 and greater are reserved 
*/
+#define ACPI_APIC_LOCAL_X2APIC   9
+#define ACPI_APIC_LOCAL_X2APIC_NMI  10
+#define ACPI_APIC_GENERIC_INTERRUPT 11
+#define ACPI_APIC_GENERIC_DISTRIBUTOR   12
+#define ACPI_APIC_GENERIC_MSI_FRAME 13
+#define ACPI_APIC_GENERIC_REDISTRIBUTOR 14
+#define ACPI_APIC_RESERVED  15   /* 15 and greater are reserved */
+
 
 /*
  * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE)
@@ -252,6 +259,34 @@ struct AcpiMadtLocalNmi {
 } QEMU_PACKED;
 typedef struct AcpiMadtLocalNmi AcpiMadtLocalNmi;
 
+struct AcpiMadtGenericInterrupt {
+ACPI_SUB_HEADER_DEF
+uint16_t reserved;
+uint32_t cpu_interface_number;
+uint32_t uid;
+uint32_t flags;
+uint32_t parking_version;
+uint32_t performance_interrupt;
+uint64_t parked_address;
+uint64_t base_address;
+uint64_t gicv_base_address;
+uint64_t gich_base_address;
+uint32_t vgic_interrupt;
+uint64_t gicr_base_address;
+uint64_t arm_mpidr;
+} QEMU_PACKED;
+typedef struct AcpiMadtGenericInterrupt AcpiMadtGenericInterrupt;
+
+struct AcpiMadtGenericDistributor {
+ACPI_SUB_HEADER_DEF
+uint16_t reserved;
+uint32_t gic_id;
+uint64_t base_address;
+uint32_t global_irq_base;
+uint32_t reserved2;
+} QEMU_PACKED;
+typedef struct AcpiMadtGenericDistributor AcpiMadtGenericDistributor;
+
 /*
  * HPET Description Table
  */
-- 
1.7.1





[Qemu-devel] [RFC PATCH 03/11] hw/arm/virt-acpi-build: Generate RSDP table

2015-01-24 Thread Shannon Zhao
RSDP points to XSDT which in turn points to other tables.

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c |   22 ++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 4eed0a3..9c3971a 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -86,6 +86,28 @@ static inline void acpi_add_table(GArray *table_offsets, 
GArray *table_data)
 static GArray *
 build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t xsdt)
 {
+AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
+
+bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 16,
+ true /* fseg memory */);
+
+memcpy(rsdp-signature, RSD PTR , sizeof(rsdp-signature));
+memcpy(rsdp-oem_id, ACPI_VIRT_QEMU_STR_6, sizeof(rsdp-oem_id));
+rsdp-length = cpu_to_le32(sizeof(*rsdp));
+rsdp-revision = 0x02;
+
+/* Point to XSDT */
+rsdp-xsdt_physical_address = cpu_to_le64(xsdt);
+/* Address to be filled by Guest linker */
+bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+   ACPI_BUILD_TABLE_FILE,
+   rsdp_table, rsdp-xsdt_physical_address,
+   sizeof rsdp-xsdt_physical_address);
+rsdp-checksum = 0;
+/* Checksum to be filled by Guest linker */
+bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+rsdp, rsdp, sizeof *rsdp, rsdp-checksum);
+
 return rsdp_table;
 }
 
-- 
1.7.1





[Qemu-devel] [PATCH v1 2/2] target_arm: Parameterise the irq lines for armv7m_init

2015-01-24 Thread Alistair Francis
This patch allows the board to specifiy the number of NVIC interrupt
lines when using armv7m_init.

Signed-off-by: Alistair Francis alistai...@gmail.com
Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---
This has been split from the Netduino 2 machine patch
series.

 hw/arm/armv7m.c  | 7 ---
 hw/arm/stellaris.c   | 5 -
 include/hw/arm/arm.h | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index 50281f7..7169027 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -166,14 +166,14 @@ static void armv7m_reset(void *opaque)
mem_size is in bytes.
Returns the NVIC array.  */
 
-qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size,
+qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq,
   const char *kernel_filename, const char *cpu_model)
 {
 ARMCPU *cpu;
 CPUARMState *env;
 DeviceState *nvic;
 /* FIXME: make this local state.  */
-static qemu_irq pic[64];
+qemu_irq *pic = g_new(qemu_irq, num_irq);
 int image_size;
 uint64_t entry;
 uint64_t lowaddr;
@@ -194,11 +194,12 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, int 
mem_size,
 armv7m_bitband_init();
 
 nvic = qdev_create(NULL, armv7m_nvic);
+qdev_prop_set_uint32(nvic, num-irq, num_irq);
 env-nvic = nvic;
 qdev_init_nofail(nvic);
 sysbus_connect_irq(SYS_BUS_DEVICE(nvic), 0,
qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ));
-for (i = 0; i  64; i++) {
+for (i = 0; i  num_irq; i++) {
 pic[i] = qdev_get_gpio_in(nvic, i);
 }
 
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index d0c61c5..6fad10f 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -29,6 +29,8 @@
 #define BP_OLED_SSI  0x02
 #define BP_GAMEPAD   0x04
 
+#define NUM_IRQ_LINES 64
+
 typedef const struct {
 const char *name;
 uint32_t did0;
@@ -1239,7 +1241,8 @@ static void stellaris_init(const char *kernel_filename, 
const char *cpu_model,
 vmstate_register_ram_global(sram);
 memory_region_add_subregion(system_memory, 0x2000, sram);
 
-pic = armv7m_init(system_memory, flash_size, kernel_filename, cpu_model);
+pic = armv7m_init(system_memory, flash_size, NUM_IRQ_LINES,
+  kernel_filename, cpu_model);
 
 if (board-dc1  (1  16)) {
 dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h
index f8b329b..5c940eb 100644
--- a/include/hw/arm/arm.h
+++ b/include/hw/arm/arm.h
@@ -15,7 +15,7 @@
 #include hw/irq.h
 
 /* armv7m.c */
-qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size,
+qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq,
   const char *kernel_filename, const char *cpu_model);
 
 /* arm_boot.c */
-- 
2.1.0




[Qemu-devel] [RFC PATCH 11/11] hw/arm/virt: Enable dynamic generation of ACPI v5.1 tables

2015-01-24 Thread Shannon Zhao
Expose the needed device information to the table generation
insfrastructure and register a machine_init_done notify to
call virt_acpi_build().

Add CONFIG_ACPI to arm-softmmu.mak, but there is compile error.
Don't include unnecessary file for ARM. Maybe this way is not
right, fix me please.

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 default-configs/arm-softmmu.mak  |1 +
 default-configs/i386-softmmu.mak |3 ++
 default-configs/mips-softmmu.mak |3 ++
 default-configs/mips64-softmmu.mak   |3 ++
 default-configs/mips64el-softmmu.mak |3 ++
 default-configs/mipsel-softmmu.mak   |3 ++
 default-configs/x86_64-softmmu.mak   |3 ++
 hw/acpi/Makefile.objs|5 ++-
 hw/arm/virt.c|   59 +++--
 hw/i2c/Makefile.objs |2 +-
 10 files changed, 78 insertions(+), 7 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index f3513fa..3c89f53 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -88,3 +88,4 @@ CONFIG_INTEGRATOR_DEBUG=y
 CONFIG_ALLWINNER_A10_PIT=y
 CONFIG_ALLWINNER_A10_PIC=y
 CONFIG_ALLWINNER_A10=y
+CONFIG_ACPI=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 8e08841..3a5fe74 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_IDE_ISA=y
diff --git a/default-configs/mips-softmmu.mak b/default-configs/mips-softmmu.mak
index 2a80b04..d37ada7 100644
--- a/default-configs/mips-softmmu.mak
+++ b/default-configs/mips-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_PIIX4=y
diff --git a/default-configs/mips64-softmmu.mak 
b/default-configs/mips64-softmmu.mak
index f1f933b..b15d6c0 100644
--- a/default-configs/mips64-softmmu.mak
+++ b/default-configs/mips64-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_PIIX4=y
diff --git a/default-configs/mips64el-softmmu.mak 
b/default-configs/mips64el-softmmu.mak
index 317b151..494a7e7 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_PIIX4=y
diff --git a/default-configs/mipsel-softmmu.mak 
b/default-configs/mipsel-softmmu.mak
index 7708185..0d2173b 100644
--- a/default-configs/mipsel-softmmu.mak
+++ b/default-configs/mipsel-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_PIIX4=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index 66557ac..79eb980 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -17,6 +17,9 @@ CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
+CONFIG_ACPI_CORE=y
+CONFIG_ACPI_MEMORY_HOTPLUG=y
+CONFIG_ACPI_CPU_HOTPLUG=y
 CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_IDE_ISA=y
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index cad0355..4e3f15f 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -1,5 +1,6 @@
-common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
-common-obj-$(CONFIG_ACPI) += memory_hotplug.o
+common-obj-$(CONFIG_ACPI_CORE) += core.o piix4.o ich9.o pcihp.o
+common-obj-$(CONFIG_ACPI_HOTPLUG) += cpu_hotplug.o
+common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
 common-obj-$(CONFIG_ACPI) += acpi-build-utils.o
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2353440..63ee9b3 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -42,6 +42,7 @@
 #include exec/address-spaces.h
 #include qemu/bitops.h
 #include qemu/error-report.h
+#include hw/arm/virt-acpi-build.h
 
 #define NUM_VIRTIO_TRANSPORTS 32
 
@@ -59,6 +60,11 @@
 #define GIC_FDT_IRQ_PPI_CPU_START 8
 #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8
 
+#define ARCH_TIMER_VIRT_IRQ   11
+#define ARCH_TIMER_S_EL1_IRQ  13
+#define ARCH_TIMER_NS_EL1_IRQ 14
+#define ARCH_TIMER_NS_EL2_IRQ 10
+
 enum {
 VIRT_FLASH,
 VIRT_MEM,
@@ -139,6 +145,29 @@ static const int a15irqmap[] = {
 [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
 };
 
+static const struct acpi_madt_info madt_info = {
+

[Qemu-devel] [RFC PATCH 04/11] hw/arm/virt-acpi-build: Generate XSDT table and add a build_header function

2015-01-24 Thread Shannon Zhao
XDST points to other tables except FACS  DSDT.
Implement a common header helper functions for generating ACPI tables.

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c|   34 ++
 include/hw/acpi/acpi-defs.h |9 +
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 9c3971a..446947a 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -61,6 +61,22 @@
 #define ACPI_BUILD_RSDP_FILE etc/acpi/rsdp
 #define ACPI_BUILD_TPMLOG_FILE etc/tpm/log
 
+static void
+build_header(GArray *linker, GArray *table_data,
+ AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
+{
+memcpy(h-signature, sig, sizeof(h-signature));
+h-length = cpu_to_le32(len);
+h-revision = rev;
+memcpy(h-oem_id, ACPI_VIRT_QEMU_STR_6, sizeof(h-oem_id));
+memcpy(h-oem_table_id, ACPI_VIRT_MACH_STR_8, sizeof(h-oem_table_id));
+h-oem_revision = cpu_to_le32(1);
+h-checksum = 0;
+/* Checksum to be filled in by Guest linker */
+bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
+table_data-data, h, len, h-checksum);
+}
+
 static inline void *acpi_data_push(GArray *table_data, uint64_t size)
 {
 unsigned off = table_data-len;
@@ -115,6 +131,24 @@ build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t 
xsdt)
 static void
 build_xsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
 {
+AcpiXsdtDescriptor *xsdt;
+size_t xsdt_len;
+int i;
+
+xsdt_len = sizeof(*xsdt) + sizeof(uint64_t) * table_offsets-len;
+xsdt = acpi_data_push(table_data, xsdt_len);
+memcpy(xsdt-table_offset_entry, table_offsets-data,
+   sizeof(uint64_t) * table_offsets-len);
+for (i = 0; i  table_offsets-len; ++i) {
+/* rsdt-table_offset_entry to be filled by Guest linker */
+bios_linker_loader_add_pointer(linker,
+   ACPI_BUILD_TABLE_FILE,
+   ACPI_BUILD_TABLE_FILE,
+   table_data, 
xsdt-table_offset_entry[i],
+   sizeof(uint64_t));
+}
+build_header(linker, table_data,
+ (void *)xsdt, XSDT, xsdt_len, 1);
 }
 
 /* MADT */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index c4468f8..779f872 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -88,6 +88,15 @@ struct AcpiTableHeader /* ACPI common table header */
 typedef struct AcpiTableHeader AcpiTableHeader;
 
 /*
+ * Extended System Description Table (XSDT)
+ */
+struct AcpiXsdtDescriptor {
+ACPI_TABLE_HEADER_DEF
+uint64_t table_offset_entry[1]; /* Array of pointers to ACPI tables */
+} QEMU_PACKED;
+typedef struct AcpiXsdtDescriptor AcpiXsdtDescriptor;
+
+/*
  * ACPI 1.0 Fixed ACPI Description Table (FADT)
  */
 struct AcpiFadtDescriptorRev1
-- 
1.7.1





[Qemu-devel] [RFC PATCH 10/11] hw/arm/virt-acpi-build: Generation of DSDT table for virt devices

2015-01-24 Thread Shannon Zhao
DSDT consists of the usual common table header plus a definition
block in AML encoding which describes all devices in the platform.

After initializing DSDT with header information the namespace is
created which is followed by the device encodings. The devices are
described using the Resource Template for the 32-Bit Fixed Memory
Range and the Extended Interrupt Descriptors.

The following devices are included in the DSDT:
- CPUs
- UART
- RTC
- NAND Flash
- virtio-mmio

Signed-off-by: Shannon Zhao zhaoshengl...@huawei.com
---
 hw/arm/virt-acpi-build.c |  120 ++
 1 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index de1f307..5c76ca2 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -98,6 +98,111 @@ static inline void acpi_add_table(GArray *table_offsets, 
GArray *table_data)
 g_array_append_val(table_offsets, offset);
 }
 
+static void acpi_dsdt_add_cpus(AcpiAml *scope, int smp_cpus)
+{
+AcpiAml dev, crs;
+int i;
+char name[5];
+for (i = 0; i  smp_cpus; i++) {
+snprintf(name, 5, CPU%u, i);
+dev = acpi_device(%s, name);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(ACPI007)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(i)));
+crs = acpi_resource_template();
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+}
+}
+
+static void acpi_dsdt_add_uart(AcpiAml *scope, const hwaddr *uart_addr,
+   const int *uart_irq)
+{
+AcpiAml dev, crs;
+
+dev = acpi_device(COM0);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(ARMH0011)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(0)));
+
+crs = acpi_resource_template();
+aml_append(crs,
+   acpi_fixed_memory32(uart_addr[0], uart_addr[1], 0x01));
+aml_append(crs,
+   acpi_extended_irq(0x01, *uart_irq + 32));
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+}
+
+static void acpi_dsdt_add_rtc(AcpiAml *scope, const hwaddr *rtc_addr,
+  const int *rtc_irq)
+{
+AcpiAml dev, crs;
+
+dev = acpi_device(RTC0);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(LNRO0013)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(0)));
+
+crs = acpi_resource_template();
+aml_append(crs,
+   acpi_fixed_memory32(rtc_addr[0], rtc_addr[1], 0x01));
+aml_append(crs,
+   acpi_extended_irq(0x01, *rtc_irq + 32));
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+}
+
+static void acpi_dsdt_add_flash(AcpiAml *scope, const hwaddr *flash_addr)
+{
+AcpiAml dev, crs;
+hwaddr base = flash_addr[0];
+hwaddr size = flash_addr[1];
+
+dev = acpi_device(FLS0);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(LNRO0015)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(0)));
+
+crs = acpi_resource_template();
+aml_append(crs,
+   acpi_fixed_memory32(base, size, 0x01));
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+
+dev = acpi_device(FLS1);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(LNRO0015)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(1)));
+crs = acpi_resource_template();
+aml_append(crs,
+   acpi_fixed_memory32(base + size, size, 0x01));
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+}
+
+static void acpi_dsdt_add_virtio(AcpiAml *scope, const hwaddr *mmio_addrs,
+ const int *mmio_irq, int num)
+{
+AcpiAml dev, crs;
+hwaddr base = mmio_addrs[0];
+hwaddr size = mmio_addrs[1];
+int irq = *mmio_irq + 32;
+int i;
+char name[5];
+
+for (i = 0; i  num; i++) {
+snprintf(name, 5, VR%02u, i);
+dev = acpi_device(%s, name);
+aml_append(dev, acpi_name_decl(_HID, acpi_string(LNRO0005)));
+aml_append(dev, acpi_name_decl(_UID, acpi_int(i)));
+
+crs = acpi_resource_template();
+aml_append(crs,
+   acpi_fixed_memory32(base, size, 0x01));
+aml_append(crs,
+   acpi_extended_irq(0x01, irq + i));
+aml_append(dev, acpi_name_decl(_CRS, crs));
+aml_append(scope, dev);
+base += size;
+}
+}
+
 /* RSDP */
 static GArray *
 build_rsdp(GArray *rsdp_table, GArray *linker, uint64_t xsdt)
@@ -260,6 +365,21 @@ build_facs(GArray *table_data, GArray *linker, 
VirtGuestInfo *guest_info)
 static void
 build_dsdt(AcpiAml *table_aml, GArray *linker, VirtGuestInfo *guest_info)
 {
+AcpiAml scope, dsdt;
+const struct acpi_dsdt_info *info = guest_info-dsdt_info;
+
+dsdt = acpi_def_block(DSDT, 1, ACPI_VIRT_QEMU_STR_4,
+ ACPI_VIRT_MACH_STR_8, 1);
+scope = acpi_scope(\\_SB);
+

[Qemu-devel] [RFC PATCH 00/11] Generate ACPI v5.1 tables and expose it to guest over fw_cfg on ARM

2015-01-24 Thread Shannon Zhao
This patch series generate seven ACPI v5.1 tables for machine virt on ARM.
The set of generated tables are:
- RSDP
- XSDT
- MADT
- GTDT
- FADT
- FACS
- DSDT

These tables are created dynamically using the function of acpi-build-utils.c,
taking into account the needed information passed from the virt machine model.
When the generation is finalized, it use fw_cfg to expose the tables to guest.

This patchset is based on Igor Mammedov's branch which can be found at below
git tree:
 https://github.com/imammedo/qemu/commits/ASL_API_v2

And this patchset refers to Alexander Spyridakis's patches which are sent to
qemu-devel mailing list before.
 http://lists.gnu.org/archive/html/qemu-devel/2014-10/msg03987.html

As UEFI (ArmVirtualizationQemu) doesn't support downloading ACPI tables over
fw_cfg, I just do compile test and start a guest with UEFI. But I contacted
Laszlo Ersek before, he says that if qemu can expose the generated ACPI
tables over fw_cfg, he can quickly add support in UEFI. So just send this
out and make it go forward.

Todo:
1) add GPIO controller in virt and expose it through ACPI
2) add cpu hotplug support

Any comments are welcome.

Thanks,
Shannon

Shannon Zhao (11):
  hw/i386: Move ACPI header definitions in an arch-independent location
  hw/arm/virt-acpi-build: Basic framwork for building ACPI tables
  hw/arm/virt-acpi-build: Generate RSDP table
  hw/arm/virt-acpi-build: Generate XSDT table and add a build_header
function
  hw/arm/virt-acpi-build: Generate MADT table
  hw/arm/virt-acpi-build: Generate GTDT table
  hw/arm/virt-acpi-build: Generate FADT table and update ACPI headers
  hw/arm/virt-acpi-build: Generate FACS table and update ACPI headers
  hw/acpi/acpi-build-utils: Add acpi_fixed_memory32() and
acpi_extended_irq()
  hw/arm/virt-acpi-build: Generation of DSDT table for virt devices
  hw/arm/virt: Enable dynamic generation of ACPI v5.1 tables

 default-configs/arm-softmmu.mak  |1 +
 default-configs/i386-softmmu.mak |3 +
 default-configs/mips-softmmu.mak |3 +
 default-configs/mips64-softmmu.mak   |3 +
 default-configs/mips64el-softmmu.mak |3 +
 default-configs/mipsel-softmmu.mak   |3 +
 default-configs/x86_64-softmmu.mak   |3 +
 hw/acpi/Makefile.objs|5 +-
 hw/acpi/acpi-build-utils.c   |   42 +++
 hw/arm/Makefile.objs |1 +
 hw/arm/virt-acpi-build.c |  520 ++
 hw/arm/virt.c|   59 -
 hw/i2c/Makefile.objs |2 +-
 hw/i386/acpi-build.c |2 +-
 hw/i386/acpi-defs.h  |  368 
 include/hw/acpi/acpi-build-utils.h   |2 +
 include/hw/acpi/acpi-defs.h  |  503 
 include/hw/arm/virt-acpi-build.h |   71 +
 tests/bios-tables-test.c |2 +-
 19 files changed, 1219 insertions(+), 377 deletions(-)
 create mode 100644 hw/arm/virt-acpi-build.c
 delete mode 100644 hw/i386/acpi-defs.h
 create mode 100644 include/hw/acpi/acpi-defs.h
 create mode 100644 include/hw/arm/virt-acpi-build.h





[Qemu-devel] [PATCH v2] vhost-user: add multi queue support

2015-01-24 Thread Nikolay Nikolaev
Vhost-user will implement the multiqueueu support in a similar way to what
vhost already has - a separate thread for each queue.

To enable the multiqueue funcionality - a new command line parameter
queues is introduced for the vhost-user netdev.

Changes since v1:
 - use s-nc.info_str when bringing up/down the backend

Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 docs/specs/vhost-user.txt |5 +
 hw/virtio/vhost-user.c|6 +-
 net/vhost-user.c  |   39 +--
 qapi-schema.json  |6 +-
 qemu-options.hx   |5 +++--
 5 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 650bb18..d7b208c 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -127,6 +127,11 @@ in the ancillary data:
 If Master is unable to send the full message or receives a wrong reply it will
 close the connection. An optional reconnection mechanism can be implemented.
 
+Multi queue suport
+-
+The protocol supports multiple queues by setting all index fields in the sent
+messages to a properly calculated value.
+
 Message types
 -
 
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index aefe0bb..83ebcaa 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -253,17 +253,20 @@ static int vhost_user_call(struct vhost_dev *dev, 
unsigned long int request,
 case VHOST_SET_VRING_NUM:
 case VHOST_SET_VRING_BASE:
 memcpy(msg.state, arg, sizeof(struct vhost_vring_state));
+msg.state.index += dev-vq_index;
 msg.size = sizeof(m.state);
 break;
 
 case VHOST_GET_VRING_BASE:
 memcpy(msg.state, arg, sizeof(struct vhost_vring_state));
+msg.state.index += dev-vq_index;
 msg.size = sizeof(m.state);
 need_reply = 1;
 break;
 
 case VHOST_SET_VRING_ADDR:
 memcpy(msg.addr, arg, sizeof(struct vhost_vring_addr));
+msg.addr.index += dev-vq_index;
 msg.size = sizeof(m.addr);
 break;
 
@@ -271,7 +274,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned 
long int request,
 case VHOST_SET_VRING_CALL:
 case VHOST_SET_VRING_ERR:
 file = arg;
-msg.u64 = file-index  VHOST_USER_VRING_IDX_MASK;
+msg.u64 = (file-index + dev-vq_index)  VHOST_USER_VRING_IDX_MASK;
 msg.size = sizeof(m.u64);
 if (ioeventfd_enabled()  file-fd  0) {
 fds[fd_num++] = file-fd;
@@ -313,6 +316,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned 
long int request,
 error_report(Received bad msg size.\n);
 return -1;
 }
+msg.state.index -= dev-vq_index;
 memcpy(arg, msg.state, sizeof(struct vhost_vring_state));
 break;
 default:
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 24e050c..a0b4af2 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -122,37 +122,39 @@ static void net_vhost_user_event(void *opaque, int event)
 case CHR_EVENT_OPENED:
 vhost_user_start(s);
 net_vhost_link_down(s, false);
-error_report(chardev \%s\ went up\n, s-chr-label);
+error_report(chardev \%s\ went up\n, s-nc.info_str);
 break;
 case CHR_EVENT_CLOSED:
 net_vhost_link_down(s, true);
 vhost_user_stop(s);
-error_report(chardev \%s\ went down\n, s-chr-label);
+error_report(chardev \%s\ went down\n, s-nc.info_str);
 break;
 }
 }
 
 static int net_vhost_user_init(NetClientState *peer, const char *device,
const char *name, CharDriverState *chr,
-   bool vhostforce)
+   bool vhostforce, uint32_t queues)
 {
 NetClientState *nc;
 VhostUserState *s;
+int i;
 
-nc = qemu_new_net_client(net_vhost_user_info, peer, device, name);
+for (i = 0; i  queues; i++) {
+nc = qemu_new_net_client(net_vhost_user_info, peer, device, name);
 
-snprintf(nc-info_str, sizeof(nc-info_str), vhost-user to %s,
- chr-label);
+snprintf(nc-info_str, sizeof(nc-info_str), vhost-user%d to %s,
+ i, chr-label);
 
-s = DO_UPCAST(VhostUserState, nc, nc);
+s = DO_UPCAST(VhostUserState, nc, nc);
 
-/* We don't provide a receive callback */
-s-nc.receive_disabled = 1;
-s-chr = chr;
-s-vhostforce = vhostforce;
-
-qemu_chr_add_handlers(s-chr, NULL, NULL, net_vhost_user_event, s);
+/* We don't provide a receive callback */
+s-nc.receive_disabled = 1;
+s-chr = chr;
+s-vhostforce = vhostforce;
 
+qemu_chr_add_handlers(s-chr, NULL, NULL, net_vhost_user_event, s);
+}
 return 0;
 }
 
@@ -228,6 +230,7 @@ static int net_vhost_check_net(QemuOpts *opts, void *opaque)
 int net_init_vhost_user(const 

Re: [Qemu-devel] [PATCH v3 0/13] migration: Add a new feature to do live migration

2015-01-24 Thread Li, Liang Z

Thanks Dave  Eric for spending time to review my patches and giving the
valuable comments, I will refine my patches in the later version according 
to your suggestions.

 * Liang Li (liang.z...@intel.com) wrote:
  This feature can help to reduce the data transferred about 60%, and
  the migration time can also be reduced about 70%.
 
  Summary of changed from v2-v3
 
  -Splited the patch to 13 parts instead of 2
  -Rewrote the core code to do compression and decompression
  -Updated the document
  -Added a common command interface to set and query parameters
  -Added some comments
 
 Hi,
   Apologies for taking so long; generally this is a lot nicer.

 I'll reply to each patch individually, but two more general questions:
a) Shouldn't compressBound be used somewhere to get the worst case
 compressed size?

Yes, compressBound is better to deal with the worst case, I will make a change.

b) I think adding some trace points would be useful; it would make it 
 easier
 to
   spot when you were waiting for threads etc.


I will do that.

Liang



Re: [Qemu-devel] [v3 12/13] migration: Add command to set migration parameter

2015-01-24 Thread Li, Liang Z
 
 * Liang Li (liang.z...@intel.com) wrote:
  Add the qmp and hmp commands to tune the parameters used in live
  migration.
 
 If I understand correctly on the destination side we need to set the number
 of decompression threads very early on an incoming migration - I'm not clear
 how early that needs to be - especially if you're using fd: so it's not 
 waiting
 for a connect ?

The decompression threads can be set after QEMU started (with -incomming
options) and before the TCP accept.





[Qemu-devel] Qemu with GDB - Query

2015-01-24 Thread manish tiwari
Hello everyone,

I am new to QEMU and trying to attach gdb with qemu on powepc host.

I have tried below options

qemu-system-ppc -enable-kvm -nographic -m 512 -M ppce500 -cpu e500mc -gdb
tcp::1234 -s -S -kernel uImage -initrd rootfs.ext2.gz -append
root=/dev/ram rw console=ttyS0,115200 -serial tcp::,server,


With the above command I have attached gdb with qemu.
Now I am not sure what needs to be done on host side(I have cross compiled
GDB in the Host file system).

Please help me what i need to do in host side ?




Thanks  Regards
Manish Tiwari


[Qemu-devel] [Bug 1414293] [NEW] target-lm32/translate.c:336: bad ? : operator

2015-01-24 Thread dcb
Public bug reported:

[qemu/target-lm32/translate.c:336]: (style) Same expression in both
branches of ternary operator.

   int rY = (dc-format == OP_FMT_RR) ? dc-r0 : dc-r0;

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1414293

Title:
  target-lm32/translate.c:336: bad ? : operator

Status in QEMU:
  New

Bug description:
  [qemu/target-lm32/translate.c:336]: (style) Same expression in both
  branches of ternary operator.

 int rY = (dc-format == OP_FMT_RR) ? dc-r0 : dc-r0;

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1414293/+subscriptions



Re: [Qemu-devel] [v3 04/13] qemu-file: Add tow function will be used in migration

2015-01-24 Thread Li, Liang Z
  +size_t migrate_qemu_add_compression_data(QEMUFile *f,
  +const uint8_t *p, size_t size, int level)
 
 It's an odd name, QEMUFile is only used by migration anyway; maybe
 qemufile_add_compression_data ?
 
  +{
  +size_t blen = IO_BUF_SIZE - f-buf_index - sizeof(int);
  +
  +if (compress2(f-buf + f-buf_index + sizeof(int), blen, (Bytef *)p,
  +size, level) != Z_OK) {
  +error_report(Compress Failed!);
  +return 0;
  +}
 
 What are the 'sizeof(int)'s for?  It's unusual because we normally keep the
 format of the stream the same even if one side was a 32bit qemu and the
 other 64bit.
 How do you know that there is enough space for the compress - i.e. what
 happens if f-buf_index is too high?

The compress2 will return failed if that happened. The spare space should be
checked before calling compress2, I will make a change.

  +qemu_put_be32(f, blen);
  +f-buf_index += blen;
  +return blen + sizeof(int);
  +}
  +
  +int migrate_qemu_flush(QEMUFile *f_des, QEMUFile *f_src) {
  +int len = 0;
  +
  +if (f_src-buf_index  0) {
  +len = f_src-buf_index;
  +qemu_put_buffer(f_des, f_src-buf, f_src-buf_index);
  +f_src-buf_index = 0;
  +}
  +return len;
  +}
 
 Can you explain a bit more here how you're using the src file; I think you're
 using it as kind of a dummy buffer; but it needs to be documented
 somewhere.  Again I'm also not sure of the name of this function.
 
Yes, it is for dummy buffer use, and I am not satisfied with the function name
too.



Re: [Qemu-devel] [v3 05/13] arch_init: alloc and free data struct in multi-thread compression

2015-01-24 Thread Li, Liang Z
   typedef struct compress_param compress_param;
 
  +enum {
  +DONE,
  +START,
  +};
  +
 
 Do you really need any more than a 'bool busy' ?

Good ideal.

   struct decompress_param {
   /* To be done */
   };
   typedef struct decompress_param decompress_param;
 
   static compress_param *comp_param;
  +static QemuMutex *mutex;
  +static QemuCond *cond;
 
 Those need better names and a comment; If I'm reading it correctly, this
 cond is used to wake up the parent thread when one of the workers has
 finished it's task?

Yes, it is.
 



Re: [Qemu-devel] [v3 08/13] migration: Add the core code of multi-thread compresion

2015-01-24 Thread Li, Liang Z
  -
  +/* When starting the process of a new block, the first page of
  + * the block should be sent out before other pages in the same
  + * block, and all the pages in last block should have been sent
  + * out, keeping this order is important.
 
 Why?  Is this just because of the 'cont' flag used to avoid sending the block
 names again?
 

Yes, it is.