acpi processor hotplug
cover acpi processor hotplug
Hi,
I'm resending the series with avi's few comments merged, and a couple of others on my own:
* _STA returns 0xF instead of 0x1. According to the specification, it means that the device, besides present, is also functional, enabled, and a couple of other cool things.
* gpe_base and proc_base as #defines, not unsigned long
* _EJ method out. It's causing a lot of troubles, and I'm not even sure it makes sense for processors. We can live without it by now, and if it is needed, it can be added later.
Have a safe trip back home,
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 1/15 Make a GPE register block be acessible.
gpe is acessible when its address listed by BIOS is !0. This patch makes gpe blk 0 available, and 4 bytes in length
--- bios/rombios32.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
bios/rombios32.c +2 -0
@@ -1441,6 +1441,8 @@ #endif fadt->pm_tmr_len =4 ; fadt->plvl2_lat =cpu_to_le16 (0x0fff );// C2 state not supported fadt->plvl3_lat =cpu_to_le16 (0x0fff );// C3 state not supported + fadt->gpe0_blk =cpu_to_le32 (0xafe0 ); + fadt->gpe0_blk_len =4 ;/* WBINVD + PROC_C1 + SLP_BUTTON + FIX_RTC */ fadt->flags =cpu_to_le32 ((1 <<0 ) | (1 <<2 ) | (1 <<5 ) | (1 <<6 )); acpi_build_table_header((struct acpi_table_header *)fadt, "FACP",
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 2/15 mark extra cpus as present
Mark cpus over smp_cpus as present, but disable. The OS can then recognize it and make room for future hotplug
--- bios/rombios.h | 2 ++ bios/rombios32.c | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-)
bios/rombios.h +2 -0
@@ -58,6 +58,8 @@ #define PM_IO_BASE 0xb000#define SMB_IO_BASE 0xb100#define CPU_COUNT_ADDR 0xf000 +#define MAX_CPUS 16 +// Define the application NAME #if defined(BX_QEMU )# define BX_APPNAME "QEMU"
bios/rombios32.c +13 -8
@@ -948,20 +948,22 @@ #endifputstr (&q,"0.1 " );/* vendor id */ putle32 (&q,0 );/* OEM table ptr */ putle16 (&q,0 );/* OEM table size */ -putle16 (&q, smp_cpus +18 );/* entry count */ +putle16 (&q,MAX_CPUS +18 );/* entry count */ putle32 (&q,0xfee00000 );/* local APIC addr */ putle16 (&q,0 );/* ext table length */ putb (&q,0 );/* ext table checksum */ putb (&q,0 );/* reserved */ -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i <MAX_CPUS ; i++) {putb (&q,0 );/* entry type = processor */ putb (&q, i);/* APIC id */ putb (&q,0x11 );/* local APIC version number */ if (i ==0 )putb (&q,3 );/* cpu flags: enabled, bootstrap cpu */ -else +else if ( i < smp_cpus)putb (&q,1 );/* cpu flags: enabled */ +else +putb (&q,0 );/* cpu flags: disabled */ putb (&q,0 );/* cpu signature */ putb (&q,6 );putb (&q,0 );
@@ -981,7 +983,7 @@ #endifputstr (&q,"ISA " );/* ioapic */ - ioapic_id = smp_cpus; + ioapic_id =MAX_CPUS ;putb (&q,2 );/* entry type = I/O APIC */ putb (&q, ioapic_id);/* apic ID */ putb (&q,0x11 );/* I/O APIC version number */
@@ -1393,7 +1395,7 @@ #endif addr = (addr +7 ) & ~7 ; madt_addr = addr; madt_size =sizeof (*madt) + -sizeof (struct madt_processor_apic ) * smp_cpus + +sizeof (struct madt_processor_apic ) *MAX_CPUS +sizeof (struct madt_io_apic ); madt = (void *)(addr); addr += madt_size;
@@ -1466,18 +1468,21 @@ #endif madt->local_apic_address =cpu_to_le32 (0xfee00000 ); madt->flags =cpu_to_le32 (1 ); apic = (void *)(madt +1 ); -for (i=0 ;i<smp_cpus;i++) { +for (i=0 ;i<MAX_CPUS ;i++) { apic->type =APIC_PROCESSOR ; apic->length =sizeof (*apic); apic->processor_id = i; apic->local_apic_id = i; - apic->flags =cpu_to_le32 (1 ); +if (i < smp_cpus) + apic->flags =cpu_to_le32 (1 ); +else + apic->flags =0 ; apic++; } io_apic = (void *)apic; io_apic->type =APIC_IO ; io_apic->length =sizeof (*io_apic); - io_apic->io_apic_id = smp_cpus; + io_apic->io_apic_id =MAX_CPUS ; io_apic->address =cpu_to_le32 (0xfec00000 ); io_apic->interrupt =cpu_to_le32 (0 );
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 3/15 introduce cpu_set to qemu monitor
in this patch, cpu_set is introduced to qemu monitor
semantics is : cpu_set x online|offline.
it will then tell the acpi backend to signal cpu x.
--- qemu/hw/acpi.c | 4 ++++ qemu/monitor.c | 16 ++++++++++++++++ qemu/sysemu.h | 3 +++ 3 files changed, 23 insertions(+), 0 deletions(-)
qemu/hw/acpi.c +4 -0
@@ -533,3 +533,7 @@ void qemu_system_powerdown(void) } }#endif + +void qemu_system_cpu_hot_add (int cpu,int state) +{ +}
qemu/monitor.c +16 -0
@@ -345,6 +345,21 @@ static void do_cpu_set(int index)term_printf ("Invalid CPU index\n" ); } +static void do_cpu_set_nr (int value,const char *status) +{ +int state; + +if (!strcmp (status,"online" )) + state =1 ; +else if (!strcmp (status,"offline" )) + state =0 ; +else { +term_printf ("invalid status: %s\n" , status); +return ; + } +qemu_system_cpu_hot_add (value, state); +} +static void do_info_jit (void ) {dump_exec_info (NULL , monitor_fprintf);
@@ -1338,6 +1353,7 @@ #endif "", "cancel the current VM migration" }, {"migrate_set_speed" ,"s" , do_migrate_set_speed, "value", "set maximum speed (in bytes) for migrations" }, + { "cpu_set", "is", do_cpu_set_nr, "cpu [online|offline]", "change cpu state" }, { NULL, NULL, }, };
qemu/sysemu.h +3 -0
@@ -153,6 +153,9 @@ int extboot_drive;extern int drive_get_index (BlockInterfaceType type,int bus,int unit);extern int drive_get_max_bus (BlockInterfaceType type); +/* acpi */ +void qemu_system_cpu_hot_add (int cpu,int state); +/* vmchannel devices */ #define MAX_VMCHANNEL_DEVICES 4
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 4/15 mark processors as presents
mark processors as present through the _STA method
--- bios/acpi-dsdt.dsl | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
bios/acpi-dsdt.dsl +18 -0
@@ -25,6 +25,24 @@ DefinitionBlock ( 0x1 // OEM Revision ) { + Scope (\_PR) + { + Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU1, 0x01, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU2, 0x02, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU3, 0x03, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU4, 0x04, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU5, 0x05, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU6, 0x06, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU7, 0x07, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU8, 0x08, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU9, 0x09, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPUA, 0x0a, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPUB, 0x0b, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPUC, 0x0c, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPUD, 0x0d, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPUE, 0x0e, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + } Scope (\) {
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 5/15 provide gpe _L0x methods
provide methods for gpe blk 0, even though they do nothing atm
--- bios/acpi-dsdt.dsl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-)
bios/acpi-dsdt.dsl +51 -0
@@ -578,4 +578,55 @@ DefinitionBlock ( 0x00, // reserved 0x00, // reserved }) + Scope (\_GPE) + { + Method(_L00) { + Return(0x01) + } + Method(_L01) { + Return(0x01) + } + Method(_L02) { + Return(0x01) + } + Method(_L03) { + Return(0x01) + } + Method(_L04) { + Return(0x01) + } + Method(_L05) { + Return(0x01) + } + Method(_L06) { + Return(0x01) + } + Method(_L07) { + Return(0x01) + } + Method(_L08) { + Return(0x01) + } + Method(_L09) { + Return(0x01) + } + Method(_L0A) { + Return(0x01) + } + Method(_L0B) { + Return(0x01) + } + Method(_L0C) { + Return(0x01) + } + Method(_L0D) { + Return(0x01) + } + Method(_L0E) { + Return(0x01) + } + Method(_L0F) { + Return(0x01) + } + } }
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 6/15 provide operation region for pio to the gpes
--- bios/acpi-dsdt.dsl | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
bios/acpi-dsdt.dsl +7 -0
@@ -27,6 +27,13 @@ DefinitionBlock ( { Scope (\_PR) { + OperationRegion( PRST, SystemIO, 0xaf00, 0x02) + Field (PRST, ByteAcc, NoLock, WriteAsZeros) + { + PRU, 8, + PRD, 8, + } + Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} Processor (CPU1, 0x01, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} Processor (CPU2, 0x02, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}}
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 7/15 implement method _L00 for GPE0
This corresponds to the cpu hotplug functionality
--- bios/acpi-dsdt.dsl | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-)
bios/acpi-dsdt.dsl +114 -0
@@ -588,6 +588,120 @@ DefinitionBlock ( Scope (\_GPE) { Method(_L00) { + /* Up status */ + If (And(\_PR.PRU, 0x2)) { + Notify(\_PR.CPU1,1) + } + + If (And(\_PR.PRU, 0x4)) { + Notify(\_PR.CPU2,1) + } + + If (And(\_PR.PRU, 0x8)) { + Notify(\_PR.CPU3,1) + } + + If (And(\_PR.PRU, 0x10)) { + Notify(\_PR.CPU4,1) + } + + If (And(\_PR.PRU, 0x20)) { + Notify(\_PR.CPU5,1) + } + + If (And(\_PR.PRU, 0x40)) { + Notify(\_PR.CPU6,1) + } + + If (And(\_PR.PRU, 0x80)) { + Notify(\_PR.CPU7,1) + } + + If (And(\_PR.PRU, 0x100)) { + Notify(\_PR.CPU8,1) + } + + If (And(\_PR.PRU, 0x200)) { + Notify(\_PR.CPU9,1) + } + + If (And(\_PR.PRU, 0x400)) { + Notify(\_PR.CPUA,1) + } + + If (And(\_PR.PRU, 0x800)) { + Notify(\_PR.CPUB,1) + } + + If (And(\_PR.PRU, 0x1000)) { + Notify(\_PR.CPUC,1) + } + + If (And(\_PR.PRU, 0x2000)) { + Notify(\_PR.CPUD,1) + } + + If (And(\_PR.PRU, 0x4000)) { + Notify(\_PR.CPUE,1) + } + + /* Down status */ + If (And(\_PR.PRD, 0x2)) { + Notify(\_PR.CPU1,3) + } + + If (And(\_PR.PRD, 0x4)) { + Notify(\_PR.CPU2,3) + } + + If (And(\_PR.PRD, 0x8)) { + Notify(\_PR.CPU3,3) + } + + If (And(\_PR.PRD, 0x10)) { + Notify(\_PR.CPU4,3) + } + + If (And(\_PR.PRD, 0x20)) { + Notify(\_PR.CPU5,3) + } + + If (And(\_PR.PRD, 0x40)) { + Notify(\_PR.CPU6,3) + } + + If (And(\_PR.PRD, 0x80)) { + Notify(\_PR.CPU7,3) + } + + If (And(\_PR.PRD, 0x100)) { + Notify(\_PR.CPU8,3) + } + + If (And(\_PR.PRD, 0x200)) { + Notify(\_PR.CPU9,3) + } + + If (And(\_PR.PRD, 0x400)) { + Notify(\_PR.CPUA,3) + } + + If (And(\_PR.PRD, 0x800)) { + Notify(\_PR.CPUB,3) + } + + If (And(\_PR.PRD, 0x1000)) { + Notify(\_PR.CPUC,3) + } + + If (And(\_PR.PRD, 0x2000)) { + Notify(\_PR.CPUD,3) + } + + If (And(\_PR.PRD, 0x4000)) { + Notify(\_PR.CPUE,3) + } + Return(0x01) } Method(_L01) {
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 8/15 isolate cpu initialization function in hw/pc.c
This patch wraps up the piece of code in hw/pc.c that actually allocates and initializates a cpu. After that, plan is to be able to start it later on.
--- qemu/hw/pc.c | 40 +++++++++++++++++++++++----------------- qemu/hw/pc.h | 1 + 2 files changed, 24 insertions(+), 17 deletions(-)
qemu/hw/pc.c +23 -17
@@ -740,6 +740,28 @@ static int load_option_rom(const char *freturn size; } +CPUState *pc_new_cpu (int cpu,const char *cpu_model,int pci_enabled) +{ +CPUState *env =cpu_init (cpu_model); +if (!env) { +fprintf (stderr,"Unable to find x86 CPU definition\n" ); +exit (1 ); + } +if (cpu !=0 ) + env->hflags |=HF_HALTED_MASK ; +if (smp_cpus >1 ) { +/* XXX: enable it in all cases */ + env->cpuid_features |=CPUID_APIC ; + } +register_savevm ("cpu" , cpu,4 , cpu_save, cpu_load, env); +qemu_register_reset (main_cpu_reset, env); +if (pci_enabled) { +apic_init (env); + } +vmport_init (env); +return env; +} +/* PC hardware initialisation */ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds,
@@ -779,23 +801,7 @@ #endif }for (i =0 ; i < smp_cpus; i++) { - env =cpu_init (cpu_model); -if (!env) { -fprintf (stderr,"Unable to find x86 CPU definition\n" ); -exit (1 ); - } -if (i !=0 ) - env->hflags |=HF_HALTED_MASK ; -if (smp_cpus >1 ) { -/* XXX: enable it in all cases */ - env->cpuid_features |=CPUID_APIC ; - } -register_savevm ("cpu" , i,4 , cpu_save, cpu_load, env); -qemu_register_reset (main_cpu_reset, env); -if (pci_enabled) { -apic_init (env); - } -vmport_init (env); + env =pc_new_cpu (i, cpu_model, pci_enabled); }/* allocate RAM */
qemu/hw/pc.h +1 -0
@@ -85,6 +85,7 @@ extern int fd_bootchk;void ioport_set_a20 (int enable);int ioport_get_a20 (void ); +CPUState *pc_new_cpu (int cpu,const char *cpu_model,int pci_enabled);/* acpi.c */ extern int acpi_enabled;
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 9/15 initialize hot add system.
Register the pios, and grab cpu_model for future usage.
--- qemu/hw/acpi.c | 34 ++++++++++++++++++++++++++++++++++ qemu/hw/pc.c | 1 + qemu/sysemu.h | 1 + 3 files changed, 36 insertions(+), 0 deletions(-)
qemu/hw/acpi.c +34 -0
@@ -533,6 +533,40 @@ void qemu_system_powerdown(void) } }#endif +#define GPE_BASE 0xafe0 + +struct gpe_regs { +uint16_t sts;/* status */ +uint16_t en;/* enabled */ +}; + +static struct gpe_regs gpe; + +static uint32_t gpe_readb (void *opaque,uint32_t addr) +{ +uint32_t val =0 ; +#if defined(DEBUG ) +printf ("gpe read %lx == %lx\n" , addr, val); +#endif +return val; +} + +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) +{ +#if defined(DEBUG ) +printf ("gpe write %lx <== %d\n" , addr, val); +#endif +} + +static char *model; + +void qemu_system_hot_add_init (char *cpu_model) +{ +register_ioport_write (GPE_BASE ,4 ,1 , gpe_writeb, &gpe); +register_ioport_read (GPE_BASE ,4 ,1 , gpe_readb, &gpe); + + model = cpu_model; +}void qemu_system_cpu_hot_add (int cpu,int state) {
qemu/hw/pc.c +1 -0
@@ -1020,6 +1020,7 @@ #endif } } +qemu_system_hot_add_init (cpu_model);#define USE_HYPERCALL #ifdef USE_HYPERCALL pci_hypercall_init (pci_bus);
qemu/sysemu.h +1 -0
@@ -155,6 +155,7 @@ extern int drive_get_max_bus(BlockInterf/* acpi */ void qemu_system_cpu_hot_add (int cpu,int state); +void qemu_system_hot_add_init (char *cpu_model);/* vmchannel devices */
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 10/15 handle gpe data for pio
actually grab and return data, instead of just being two bogus functions.
--- qemu/hw/acpi.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
qemu/hw/acpi.c +36 -0
@@ -545,6 +545,24 @@ static struct gpe_regs gpe;static uint32_t gpe_readb (void *opaque,uint32_t addr) {uint32_t val =0 ; +struct gpe_regs *g = opaque; +switch (addr) { +case GPE_BASE : + val = g->sts &0xFF ; +break ; +case GPE_BASE +1 : + val = (g->sts >>8 ) &0xFF ; +break ; +case GPE_BASE +2 : + val = g->en &0xFF ; +break ; +case GPE_BASE +3 : + val = (g->en >>8 ) &0xFF ; +break ; +default : +break ; + } +#if defined(DEBUG )printf ("gpe read %lx == %lx\n" , addr, val);#endif
@@ -553,6 +571,24 @@ #endifstatic void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) { +struct gpe_regs *g = opaque; +switch (addr) { +case GPE_BASE : + g->sts = (g->sts & ~0xFFFF ) | (val &0xFFFF ); +break ; +case GPE_BASE +1 : + g->sts = (g->sts &0xFFFF ) | (val <<8 ); +break ; +case GPE_BASE +2 : + g->en = (g->en & ~0xFFFF ) | (val &0xFFFF ); +break ; +case GPE_BASE +3 : + g->en = (g->en &0xFFFF ) | (val <<8 ); +break ; +default : +break ; + } +#if defined(DEBUG )printf ("gpe write %lx <== %d\n" , addr, val);#endif
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 11/15 manipulate the gpe bits and send sci up the os.
--- qemu/hw/acpi.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)
qemu/hw/acpi.c +42 -0
@@ -534,10 +534,13 @@ void qemu_system_powerdown(void) }#endif #define GPE_BASE 0xafe0 +#define PROC_BASE 0xaf00struct gpe_regs {uint16_t sts;/* status */ uint16_t en;/* enabled */ +uint8_t up; +uint8_t down; };static struct gpe_regs gpe;
@@ -547,6 +550,13 @@ static uint32_t gpe_readb(void *opaque,uint32_t val =0 ;struct gpe_regs *g = opaque;switch (addr) { +case PROC_BASE : + val = g->up; +break ; +case PROC_BASE +1 : + val = g->down; +break ; +case GPE_BASE : val = g->sts &0xFF ;break ;
@@ -573,6 +583,13 @@ static void gpe_writeb(void *opaque, uin {struct gpe_regs *g = opaque;switch (addr) { +case PROC_BASE : + g->up = val; +break ; +case PROC_BASE +1 : + g->down = val; +break ; +case GPE_BASE : g->sts = (g->sts & ~0xFFFF ) | (val &0xFFFF );break ;
@@ -601,9 +618,34 @@ void qemu_system_hot_add_init(char *cpu_register_ioport_write (GPE_BASE ,4 ,1 , gpe_writeb, &gpe);register_ioport_read (GPE_BASE ,4 ,1 , gpe_readb, &gpe); +register_ioport_write (PROC_BASE ,4 ,1 , gpe_writeb, &gpe); +register_ioport_read (PROC_BASE ,4 ,1 , gpe_readb, &gpe); + model = cpu_model; } +static void enable_processor (struct gpe_regs *g,int cpu) +{ + g->sts |=1 ; + g->en |=1 ; + g->up |= (1 << cpu); +} + +static void disable_processor (struct gpe_regs *g,int cpu) +{ + g->sts |=1 ; + g->en |=1 ; + g->down |= (1 << cpu); +} +void qemu_system_cpu_hot_add (int cpu,int state) { +qemu_set_irq (pm_state->irq,1 ); + gpe.up =0 ; + gpe.down =0 ; +if (state) +enable_processor (&gpe, cpu); +else +disable_processor (&gpe, cpu); +qemu_set_irq (pm_state->irq,0 ); }
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 12/15 isolate cpu thread creation in qemu-kvm.c
--- qemu/qemu-kvm.c | 9 +++++++-- qemu/qemu-kvm.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
qemu/qemu-kvm.c +7 -2
@@ -351,6 +351,11 @@ static void kvm_add_signal(struct qemu_ksigdelset (&sigtab->negsigset, signum); } +void kvm_init_new_ap (int cpu,CPUState *env) +{ +pthread_create (&vcpu_info[cpu].thread,NULL , ap_main_loop, env); +} +int kvm_init_ap (void ) {CPUState *env = first_cpu->next_cpu;
@@ -371,8 +376,8 @@ #endif vcpu->env = first_cpu;signal (SIG_IPI , sig_ipi_handler);for (i =1 ; i < smp_cpus; ++i) { -pthread_create (&vcpu_info[i].thread,NULL , ap_main_loop, env); - env = env->next_cpu; +kvm_init_new_ap (i, env); + env = env->next_cpu; }return 0 ; }
qemu/qemu-kvm.h +1 -0
@@ -13,6 +13,7 @@ #include "cpu.h"int kvm_main_loop (void );int kvm_qemu_init (void );int kvm_qemu_create_context (void ); +void kvm_init_new_ap (int cpu,CPUState *env);int kvm_init_ap (void );void kvm_qemu_destroy (void );void kvm_load_registers (CPUState *env);
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 13/15 provide _MAT to acpi processor
--- bios/acpi-dsdt.dsl | 154 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 140 insertions(+), 14 deletions(-)
bios/acpi-dsdt.dsl +140 -14
@@ -35,20 +35,146 @@ DefinitionBlock ( } Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU1, 0x01, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU2, 0x02, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU3, 0x03, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU4, 0x04, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU5, 0x05, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU6, 0x06, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU7, 0x07, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU8, 0x08, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPU9, 0x09, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPUA, 0x0a, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPUB, 0x0b, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPUC, 0x0c, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPUD, 0x0d, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} - Processor (CPUE, 0x0e, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU1, 0x01, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x01, 0x01, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x2)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU2, 0x02, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x02, 0x02, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x4)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU3, 0x03, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x03, 0x03, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x8)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU4, 0x04, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x04, 0x04, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x10)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU5, 0x05, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x05, 0x05, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x20)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU6, 0x06, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x06, 0x06, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x40)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU7, 0x07, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x07, 0x07, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x80)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU8, 0x08, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x08, 0x08, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x100)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPU9, 0x09, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x09, 0x09, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x200)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPUA, 0x0a, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x0A, 0x0A, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x400)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPUB, 0x0b, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x0B, 0x0B, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x800)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPUC, 0x0c, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x0C, 0x0C, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x1000)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPUD, 0x0d, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x0D, 0x0D, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x2000)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } + Processor (CPUE, 0x0e, 0x0000b010, 0x06) { + Name (TMP, Buffer(0x8) {0x0, 0x8, 0x0E, 0x0E, 0x1, 0x0, 0x0, 0x0}) + Method(_MAT, 0) { + If (And(\_PR.PRU, 0x4000)) { Return(TMP) } + Else { Return(0x0) } + } + Method (_STA) { + Return(0xF) + } + } } Scope (\)
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 14/15 start a new cpu thread
spin up a new cpu thread if not yet running.
--- qemu/hw/acpi.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
qemu/hw/acpi.c +16 -0
@@ -23,6 +23,9 @@ #include "qemu-timer.h"#include "sysemu.h" #include "i2c.h" #include "smbus.h" +#ifdef USE_KVM +#include "qemu-kvm.h" +#endif //#define DEBUG
@@ -640,6 +643,19 @@ static void disable_processor(struct gpevoid qemu_system_cpu_hot_add (int cpu,int state) { +CPUState *env; + +if ((state) && (!qemu_kvm_cpu_env (cpu))) { + env =pc_new_cpu (cpu, model,1 ); +if (!env) { +fprintf (stderr,"cpu %d creation failed\n" , cpu); +return ; + } +#ifdef USE_KVM +kvm_init_new_ap (cpu, env); +#endif + } +qemu_set_irq (pm_state->irq,1 ); gpe.up =0 ; gpe.down =0 ;
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 15/15 remove acpi_build_processor_ssdt
--- bios/rombios32.c | 55 ------------------------------------------------------ 1 files changed, 0 insertions(+), 55 deletions(-)
bios/rombios32.c +0 -55
@@ -1294,57 +1294,6 @@ #endif h->checksum =acpi_checksum ((void *)h, len); } -int acpi_build_processor_ssdt (uint8_t *ssdt) -{ -uint8_t *ssdt_ptr = ssdt; -int i, length; -int acpi_cpus = smp_cpus >0xff ?0xff : smp_cpus; - - ssdt_ptr[9 ] =0 ;// checksum; - ssdt_ptr +=sizeof (struct acpi_table_header ); - -// caluculate the length of processor block and scope block excluding PkgLength - length =0x0d * acpi_cpus +4 ; - -// build processor scope header - *(ssdt_ptr++) =0x10 ;// ScopeOp -if (length <=0x3e ) { - *(ssdt_ptr++) = length +1 ; - }else { - *(ssdt_ptr++) =0x7F ; - *(ssdt_ptr++) = (length +2 ) >>6 ; - } - *(ssdt_ptr++) ='_' ;// Name - *(ssdt_ptr++) ='P' ; - *(ssdt_ptr++) ='R' ; - *(ssdt_ptr++) ='_' ; - -// build object for each processor -for (i=0 ;i<acpi_cpus;i++) { - *(ssdt_ptr++) =0x5B ;// ProcessorOp - *(ssdt_ptr++) =0x83 ; - *(ssdt_ptr++) =0x0B ;// Length - *(ssdt_ptr++) ='C' ;// Name (CPUxx) - *(ssdt_ptr++) ='P' ; -if ((i &0xf0 ) !=0 ) - *(ssdt_ptr++) = (i >>4 ) <0xa ? (i >>4 ) +'0' : (i >>4 ) +'A' -0xa ; -else - *(ssdt_ptr++) ='U' ; - *(ssdt_ptr++) = (i &0xf ) <0xa ? (i &0xf ) +'0' : (i &0xf ) +'A' -0xa ; - *(ssdt_ptr++) = i; - *(ssdt_ptr++) =0x10 ;// Processor block address - *(ssdt_ptr++) =0xb0 ; - *(ssdt_ptr++) =0 ; - *(ssdt_ptr++) =0 ; - *(ssdt_ptr++) =6 ;// Processor block length - } - -acpi_build_table_header ((struct acpi_table_header *)ssdt, -"SSDT" , ssdt_ptr - ssdt,1 ); - -return ssdt_ptr - ssdt; -} -/* base_addr must be a multiple of 4KB */ void acpi_bios_init (void ) {
@@ -1388,10 +1337,6 @@ #endif dsdt = (void *)(addr); addr +=sizeof (AmlCode); - ssdt_addr = addr; - ssdt = (void *)(addr); - addr +=acpi_build_processor_ssdt (ssdt); - addr = (addr +7 ) & ~7 ; madt_addr = addr; madt_size = sizeof(*madt) +
Signature · 7 lines
1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [PATCH 4/15] mark processors as presents
In reply to Glauber CostaQuoted 39 lines · Glauber Costa
mark processors as present through the
_STAmethodSigned-off-by Glauber Costa <[email protected]>---
bios/acpi-dsdt.dsl | 18 ++++++++++++++++++1 files changed, 18 insertions(+), 0 deletions(-)bios/acpi-dsdt.dsl +6
-0@@ -25,6 +25,24 @@ DefinitionBlock ( 0x1 // OEM Revision ) { + Scope (\_PR) + { + Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU1, 0x01, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU2, 0x02, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU3, 0x03, 0x0000b010, 0x06) {Method (_STA){ Return(0xF)}}
+ Processor (CPU4,0x04,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU5,0x05,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU6,0x06,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU7,0x07,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU8,0x08,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU9,0x09,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUA,0x0a,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
Quoted 8 lines
+ Processor (CPUB,
0x0b,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUC,0x0c,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUD,0x0d,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUE,0x0e,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
So if I understand this correctly, you set all possible CPUs on active and available. What exactly happens if one of these is not usable? I know that Darwin broke on the _PR description quite badly, as it just allocates possible execution engines using the ACPI Processor specification and I do not know what happens if the engine is not available.
I have to admit that I have not tested it as I do not have the time to do so though, so maybe it works.
Quoted 8 lines
+ }
Scope (\) {Signature · 1 line
1.4.2
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [PATCH 4/15] mark processors as presents
Quoted 58 lines · Alexander Graf
Quoted 39 lines · Glauber Costa
mark processors as present through the
_STAmethodSigned-off-by Glauber Costa <[email protected]>---
bios/acpi-dsdt.dsl | 18 ++++++++++++++++++1 files changed, 18 insertions(+), 0 deletions(-)bios/acpi-dsdt.dsl +6
-0@@ -25,6 +25,24 @@ DefinitionBlock ( 0x1 // OEM Revision ) { + Scope (\_PR) + { + Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU1, 0x01, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU2, 0x02, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}} + Processor (CPU3, 0x03, 0x0000b010, 0x06) {Method (_STA){ Return(0xF)}}
+ Processor (CPU4,0x04,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU5,0x05,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU6,0x06,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU7,0x07,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU8,0x08,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPU9,0x09,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUA,0x0a,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}Quoted 8 lines
+ Processor (CPUB,
0x0b,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUC,0x0c,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUD,0x0d,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}
+ Processor (CPUE,0x0e,0x0000b010,0x06) {Method (_STA)
{ Return(0xF)}}So if I understand this correctly, you set all possible CPUs on active and available. What exactly happens if one of these is not usable? I know that Darwin broke on the
_PRdescription quite badly, as it just allocates possible execution engines using the ACPI Processor specification and I do not know what happens if the engine is not available.
Quoted 2 lines
I have to admit that I have not tested it as I do not have the time to do so though, so maybe it works.
I just read patch 13 ... nevermind
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Avi Kivity
AppliedQuoted 5 lines · Glauber Costa
Hi,
I'm resending the series with avi's few comments merged, and a couple of others on my own:
Quoted 9 lines
*
_STAreturns0xFinstead of0x1. According to the specification, it means that the device, besides present, is also functional, enabled, and a couple of other cool things.
*gpe_baseandproc_baseas #defines, not unsigned long
*_EJmethod out. It's causing a lot of troubles, and I'm not even sure it makes sense for processors. We can live without it by now, and if it is needed, it can be added later.
Applied all, thanks.
Signature · 7 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/