i386: pc: align gpa<->hpa on 1GB boundary (v6)

Align guest physical address and host physical address
beyond guest 4GB on a 1GB boundary.

Otherwise 1GB TLBs cannot be cached for the range.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
[Reorganize code, keep same logic. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
acpi: factor out common pm_update_sci() into acpi core

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
perhaps this patch sholud go before "piix4: add acpi pci hotplug support"
so that there were no need in this rename in piix4_acpi_pci_hotplug()
here.

s/pm_update_sci/acpi_update_sci/
pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS

'etc/reserved-memory-end' will allow QEMU to tell BIOS where PCI
BARs mapping could safely start in high memory.

Allowing BIOS to start mapping 64-bit PCI BARs at address where it
wouldn't conflict with other mappings QEMU might place before it.

That permits QEMU to reserve extra address space before
64-bit PCI hole for memory hotplug.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
   * disable 'etc/reserved-memory-end' for 1.7 and older machine types
vl: convert -m to QemuOpts

Adds option to -m
 "mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed,
it assumes amount in Mb.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
vl.c: extend -m option to support options for memory hotplug

Add following parameters:
  "slots" - total number of hotplug memory slots
  "maxmem" - maximum possible memory

"slots" and "maxmem" should go in pair and "maxmem" should be greater
than "mem" for memory hotplug to be enabled.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
rename pci_hotplug_fn to hotplug_fn and make it available for other devices

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
resolving conflict with pcihp: s/PCIHotplugState/HotplugState/
perhaps this patch should go before  pcihp patches to avoid
unnecessary code churn??
qapi: add SIZE type parser to string_input_visitor

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
get reference to /backend container via qemu_get_backend()

... API, so it could be reused later using qemu_get_backend()
without duplicating "/backend" everywhere.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
add memdev backend infrastructure

Provides framework for splitting host RAM allocation/
policies into a separate backend that could be used
by devices. It would allow to separate host specific
options from device model like it's done for netdev & co.

It adds new:
   -memdev CLI option and corresponding memdev-add
    QMP/HMP commands.

Upon successful command execution an new memdev object
is added to QOM tree into "/backend/memdev" container.

Initially only legacy RAM backend is provided, which
uses memory_region_init_ram() allocator and compatible
with every CLI option that affects memory_region_init_ram().

memdev object is intendend for usage with Dimm device,
example:
 -memdev id=m1,size=1G -device dimm,id=dimm1,memdev=m1

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
dimm: implement dimm device abstraction

Each hotplug-able memory slot is a DimmDevice. All DimmDevices are
attached to a new bus called DimmBus.

A hot-add operation for a DIMM:
- creates a new DimmDevice and attaches it to the DimmBus

Hotplug operations are done through normal device_add commands.
For migration case, all hotplugged DIMMs on source should be specified
on target's command line using '-device' option with properties set to
the same values as on target.

To simplify review, patch introduces only DimmDevice and DimmBus basic
QOM skeleton that will be extended by following patches to implement
actual memory hotplug and related functions.

Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v3:
  pc: compile memhotplug on i386 target too
v2:
  fix typo s/DimmBus/DimmDevice/ in doc comment
  s/klass/oc/;s/*/parent_obj/;a/gtk-doc markup/

dimm impl
dimm: map DimmDevice into DimBus provided address space

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
dimm: add busy slot check and slot auto-allocation

- if slot property is not specified on -device/device_add command,
treat default value as request for assigning DimmDevice to
the first free slot.

- if slot is provided with -device/device_add command, attempt to
use it or fail command if it's already occupied.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  s/dc/dbc/
dimm: add busy address check and address auto-allocation

- if 'start' property is not specified on -device/device_add command,
treat default value as request for assigning DimmDevice to
the first free memory region.

- if 'start' is provided with -device/device_add command, attempt to
use it or fail command if it's already occupied or falls inside
of an existing DimmDevice memory region.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  * s/dc/dbc/
  * if DimmBus is not initialized, report error "memory add is disabled"
dimm: add hotplug callback to DimmBus

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
acpi: memory hotplug ACPI hardware implementation

- implements QEMU hardware part of memory hotplug protocol
  described at "docs/specs/acpi_mem_hotplug.txt"
- handles only memory add notification event for now

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
acpi: initialize memory hotplug ACPI PIIX4 hardware

to be used by i440fx machine for handling hardware ACPI part of
memory hotplug interface with guest.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
  * fix spec:
      - document OST register
      - reg 0x14: fix bit numbering
  * drop version register and put status/ctrl reg there
  * document what could be written to not documented fields
  * apply suggested rewording
acpi: piix4: add memory-hotplug-io-base property to piix4_pm

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
acpi: ich9: allow guest to clear SCI rised by GPE

it fixes IRQ storm since guest isn't able to lower SCI IRQ
after it has been handled when it clears GPE event.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
acpi: initialize memory hotplug ACPI ICH9 hardware

to be used by Q35 machine for handling hardware ACPI part of
memory hotplug interface with guest.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
acpi: ich9: add memory-hotplug-io-base property to ich9_pm

Signed-off-by: Igor Mammedov <imammedo@redhat.com>