move I/O-related definitions from qemu-common.h to a new header (qemu-stdio.h)

This will help reduce the qemu-common.h dependency hell.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
cpus.h: include cpu-stdio.h

Needed for the definition of fprint_function.

This is not necessary right now, but it will be necessary if code that
doesn't include cpu-common.h includes cpus.h.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
hw/apic.c: rename bit functions to not conflict with bitops.h (v2)

Changes v1 -> v2:
 - Coding style change: break too-long line

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
kvm: set vcpu_id to APIC ID instead of CPU index

The CPU ID in KVM is supposed to be the APIC ID, so change the
KVM_CREATE_VCPU call to match it. It didn't break anything yet because
today the APIC ID is assumed to be == the CPU index, but this won't be
true in the future.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
i386: cpu: move cpuid_apic_id initialization to cpu_x86_register()

The problem here is:

 - The CPU object can't define its APIC ID itself, it has to be
   defined by the creator of the CPU object
 - The object instance_init() function can't get extra arguments
 - I don't want to add a APIC ID argument to x86_cpu_realize(), as it
   should eventually become a ObjectClass::realize() method

So, the only place where the CPU object can get an additional
x86-specific initialization argument (the APIC ID) is
cpu_x86_register(). This patch just moves the initialization code there,
the apic_id argument to cpu_x86_register() will be added later.

The cpuid_apic_id field is used only at:

 - pc_new_cpu(), after the cpu_x86_register() call
 - kvm_init_vcpu(), that is called from the VCPU thread
   created by qemu_init_vcpu(), called by x86_cpu_realize()
   (called after cpu_x86_register())
 - helper_cpuid(), called only when the VCPU is already running
 - kvm_arch_init_vcpu(), that's called by kvm_init_vcpu()

So it's safe to initialize it later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
i386: cpu: add apic_id argument to cpu_x86_register()

It's not up to the CPU object to decide its APIC ID, but to the CPU
object creator (that knows about the CPU sockets, cores, and threads
topology).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
cpu_x86_init: allow APIC ID to be set by caller

This allows callers of cpu_x86_init() to override the APIC ID, in case
it needs to build a specific cores/threads topology.

By now, all the callers use the default behavior, that's using the CPU
index as APIC ID.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
remove FW_CFG_MAX_CPUS from fw_cfg_init()

PC will not use max_cpus for that field, so move it outside the common code so
it can use a different value on PC.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
pc: set explicit APIC ID for CPUs

The current behavior (setting APIC ID = CPU index) is kept, but this
will allow the PC code to set the proper CPU topology, later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
i386: create apic_id_for_cpu() function (v3)

Currently we need a way to calculate the Initial APIC ID using only the
CPU index (without needing a CPU object), as the NUMA fw_cfg data is
APIC-ID-based, and may include data for hotplug CPUs (that don't exist
yet), up to max_cpus.

Changes v2 -> v3:
  - Move the whole code to hw/pc.c, now only the PC code will need
    to handle topology-based APIC IDs

Changes v1 -> v2:
  - make function return value 'unsigned int' (it's not specific for the 8-bit
    xAPIC ID)
  - move implementation to cpu.c

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
pc: set FW_CFG data based on APIC ID calculation (v2)

This changes FW_CFG_MAX_CPUS and FW_CFG_NUMA to use apic_id_for_cpu(),
so the NUMA table can be based on the APIC IDs, instead of CPU index
(SeaBIOS knows nothing about CPU indexes, just APIC IDs).

Changes v1 -> v2:
 - Add more detailed comments explaining the reason for FW_CFG_MAX_CPUS
   not being simply 'max_cpus'

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
move global properties code to global-props.c

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Conflicts:
	hw/qdev-properties.c

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
rename qdev_prop_register_global_list to qemu_globals_register_list

The function is not qdev-specific, it just keeps a global
driver/property/value list.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
move global-property declarations to global-props.h

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
create qemu_global_get() function

Useful for cases where code is not converted to QOM and/or QDEV yet, but
needs to check the value of a global property.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Conflicts:
	hw/qdev.h

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
global-props: implement qemu_global_get_bool()

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
tests: support target-specific unit tests

To make unit tests that depend on target-specific files, use
check-unit-<arch>-y and test-obj-<arch>-y.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
i386: topology & APIC ID utility functions (v2)

Changes v1 -> v2:
 - Support 32-bit APIC IDs (in case x2APIC is going to be used)
 - Coding style changes
 - Use TARGET_I386_TOPOLOGY_H instead of __QEMU_X86_TOPOLOGY_H__
 - Rename topo_make_apic_id() to topo_apicid_for_cpu()
 - Rename __make_apicid() to topo_make_apicid()
 - Spaces around operators on test-x86-cpuid.c, as requested by
   Blue Swirl
 - Make test-x86-cpuid a target-specific test

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
generate APIC IDs according to CPU topology (v3)

This keeps compatibility on machine-types pc-1.1 and lower, and prints a
warning in case the requested configuration won't get the correct
topology.

Changes v2 -> v3:
 - Now all code is inside hw/pc.c
 - Rename SMP.contiguous_apic_ids to PC.contiguous_apic_ids
 - Use qemu_global_get_bool()

Changes v1 -> v2:
 - Move code to cpu.c
 - keep using cpu_index on *-user
 - Use SMP.contiguous_apic_ids global property
 - Prints warning in case the compatibility mode will expose incorrect
   topology

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>