Hi Avi,

This builds on your preprocessor work for cleaning up the DSDT and makes
it trivially easy to change the CPU and PCI hotplug slot count.  I'm
thinking about splitting a few SSDTs out of the monolithic DSDT, and
generating some of the code at compile time should make that easier.
This generates the same ASL after the preprocessor as current code.
BTW, isn't \_PR.PRU & \_PR.PRD too small for hotplug'ing more than 8
CPUs?  Let me know what you think.  Thanks,

        Alex



kvm: bios: generate cpu and pci hotplug objects at compile time

Signed-off-by: Alex Williamson <[EMAIL PROTECTED]>
--

diff --git a/bios/Makefile b/bios/Makefile
index 48022ea..8ca5482 100644
--- a/bios/Makefile
+++ b/bios/Makefile
@@ -22,6 +22,9 @@
 
 # Makefile for the BIOS component of bochs
 
+max_cpus ?= 16
+max_pci_slots ?= 32
+win2k_cpu_limit ?= y
 
 .SUFFIXES: .cc
 
@@ -64,6 +67,9 @@ clean:
        rm -f  *.o *.a *.s _rombios*_.c rombios*.txt rombios*.sym
        rm -f  usage biossums rombios16.bin
        rm -f  rombios32.bin rombios32.out acpi-dsdt.hex
+       rm -f  acpi-dsdt-processor.gen acpi-dsdt-cpu-hotplug.gen
+       rm -f  acpi-dsdt-prt-slot.gen acpi-dsdt-hotplug-slot.gen
+       rm -f  acpi-dsdt-pci-hotplug.gen
 
 dist-clean: clean
        rm -f  Makefile
@@ -101,13 +107,60 @@ rombios32.out: rombios32start.o rombios32.o vapic.o 
rombios32.ld
        ld -o $@ -T rombios32.ld rombios32start.o vapic.o rombios32.o
 
 rombios32.o: rombios32.c acpi-dsdt.hex
-       $(GCC) -m32 -O2 -Wall -c -o $@ $<
+       $(GCC) -m32 -O2 -Wall -DMAX_CPUS=$(max_cpus) -c -o $@ $<
 
-acpi-dsdt.hex: acpi-dsdt.dsl
+acpi-dsdt.hex: acpi-dsdt.dsl acpi-dsdt-processor.gen acpi-dsdt-cpu-hotplug.gen 
acpi-dsdt-prt-slot.gen acpi-dsdt-hotplug-slot.gen acpi-dsdt-pci-hotplug.gen
        cpp -P $< $<.i
        iasl -tc -p $@ $<.i
        rm $<.i
 
+acpi-dsdt-processor.gen:
+       rm -f $@;
+       last=`expr $(max_cpus) - 1`;                                    \
+       if [ "$(win2k_cpu_limit)" = "y" ] && [ $$last -gt 14 ]; then    \
+               last=14;                                                \
+       fi;                                                             \
+       for i in `seq 1 $$last`; do                                     \
+               echo "gen_processor($$i, `printf "%X" $$i`)" >> $@;     \
+       done
+
+acpi-dsdt-cpu-hotplug.gen:
+       rm -f $@;
+       last=`expr $(max_cpus) - 1`;                                    \
+       if [ "$(win2k_cpu_limit)" = "y" ] && [ $$last -gt 14 ]; then    \
+               last=14;                                                \
+       fi;                                                             \
+       for i in `seq 1 $$last`; do                                     \
+               echo "gen_cpu_hotplug($$i, `printf "%X" $$i`)" >> $@;   \
+       done
+
+acpi-dsdt-prt-slot.gen:
+       rm -f $@;
+       last=`expr $(max_pci_slots) - 1`;                               \
+       for i in `seq 0 4 $$last`; do                                   \
+               echo "prt_slot0(`printf "0x%04x" $$i`)," >> $@;         \
+               next=`expr $$i + 1`;                                    \
+               echo "prt_slot1(`printf "0x%04x" $$next`)," >> $@;      \
+               next=`expr $$i + 2`;                                    \
+               echo "prt_slot2(`printf "0x%04x" $$next`)," >> $@;      \
+               next=`expr $$i + 3`;                                    \
+               echo "prt_slot3(`printf "0x%04x" $$next`)," >> $@;      \
+       done
+
+acpi-dsdt-hotplug-slot.gen:
+       rm -f $@;
+       last=`expr $(max_pci_slots) - 1`;                               \
+       for i in `seq 1 $$last`; do                                     \
+               echo "hotplug_slot($$i, `printf "0x%04x" $$i`)" >> $@;  \
+       done
+
+acpi-dsdt-pci-hotplug.gen:
+       rm -f $@;
+       last=`expr $(max_pci_slots) - 1`;                               \
+       for i in `seq 1 $$last`; do                                     \
+               echo "gen_pci_hotplug($$i)" >> $@;                      \
+       done
+
 rombios32start.o: rombios32start.S
        $(GCC) -m32 -c -o $@ $<
 
diff --git a/bios/acpi-dsdt.dsl b/bios/acpi-dsdt.dsl
index d1bfa2c..b76772a 100755
--- a/bios/acpi-dsdt.dsl
+++ b/bios/acpi-dsdt.dsl
@@ -16,6 +16,9 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "acpi-dsdt.h"
+
 DefinitionBlock (
     "acpi-dsdt.aml",    // Output Filename
     "DSDT",             // Signature
@@ -34,35 +37,10 @@ DefinitionBlock (
                PRD, 8,
        }
 
-#define gen_processor(nr, name)                                            \
-       Processor (CPU##name, nr, 0x0000b010, 0x06) {                       \
-            Name (TMP, Buffer(0x8) {0x0, 0x8, nr, nr, 0x1, 0x0, 0x0, 0x0})  \
-            Method(_MAT, 0) {                                               \
-                If (And(\_PR.PRU, ShiftLeft(1, nr))) { Return(TMP) }        \
-                Else { Return(0x0) }                                        \
-            }                                                               \
-            Method (_STA) {                                                 \
-                Return(0xF)                                                 \
-            }                                                               \
-        }                                                                   \
-
-
-
         Processor (CPU0, 0x00, 0x0000b010, 0x06) {Method (_STA) { Return(0xF)}}
-       gen_processor(1, 1)
-       gen_processor(2, 2)
-       gen_processor(3, 3)
-       gen_processor(4, 4)
-       gen_processor(5, 5)
-       gen_processor(6, 6)
-       gen_processor(7, 7)
-       gen_processor(8, 8)
-       gen_processor(9, 9)
-       gen_processor(10, A)
-       gen_processor(11, B)
-       gen_processor(12, C)
-       gen_processor(13, D)
-       gen_processor(14, E)
+
+        /* Additional processors generated via Makefile max_cpus */
+        #include "acpi-dsdt-processor.gen"
     }
 
     Scope (\)
@@ -101,50 +79,8 @@ DefinitionBlock (
                    section 6.2.8.1 */
                 /* Note: we provide the same info as the PCI routing
                    table of the Bochs BIOS */
-
-#define prt_slot(nr, lnk0, lnk1, lnk2, lnk3) \
-       Package() { nr##ffff, 0, lnk0, 0 }, \
-       Package() { nr##ffff, 1, lnk1, 0 }, \
-       Package() { nr##ffff, 2, lnk2, 0 }, \
-       Package() { nr##ffff, 3, lnk3, 0 }
-
-#define prt_slot0(nr) prt_slot(nr, LNKD, LNKA, LNKB, LNKC)
-#define prt_slot1(nr) prt_slot(nr, LNKA, LNKB, LNKC, LNKD)
-#define prt_slot2(nr) prt_slot(nr, LNKB, LNKC, LNKD, LNKA)
-#define prt_slot3(nr) prt_slot(nr, LNKC, LNKD, LNKA, LNKB)
-
-               prt_slot0(0x0000),
-               prt_slot1(0x0001),
-               prt_slot2(0x0002),
-               prt_slot3(0x0003),
-               prt_slot0(0x0004),
-               prt_slot1(0x0005),
-               prt_slot2(0x0006),
-               prt_slot3(0x0007),
-               prt_slot0(0x0008),
-               prt_slot1(0x0009),
-               prt_slot2(0x000a),
-               prt_slot3(0x000b),
-               prt_slot0(0x000c),
-               prt_slot1(0x000d),
-               prt_slot2(0x000e),
-               prt_slot3(0x000f),
-               prt_slot0(0x0010),
-               prt_slot1(0x0011),
-               prt_slot2(0x0012),
-               prt_slot3(0x0013),
-               prt_slot0(0x0014),
-               prt_slot1(0x0015),
-               prt_slot2(0x0016),
-               prt_slot3(0x0017),
-               prt_slot0(0x0018),
-               prt_slot1(0x0019),
-               prt_slot2(0x001a),
-               prt_slot3(0x001b),
-               prt_slot0(0x001c),
-               prt_slot1(0x001d),
-               prt_slot2(0x001e),
-               prt_slot3(0x001f),
+                /* Generated via Makefile max_pci_slots */
+                #include "acpi-dsdt-prt-slot.gen"
             })
 
             OperationRegion(PCST, SystemIO, 0xae00, 0x08)
@@ -160,47 +96,8 @@ DefinitionBlock (
                 B0EJ, 32,
             }
 
-#define hotplug_slot(name, nr) \
-            Device (S##name) {                    \
-               Name (_ADR, nr##0000)              \
-               Method (_EJ0,1) {                  \
-                    Store(ShiftLeft(1, nr), B0EJ) \
-                    Return (0x0)                  \
-               }                                  \
-               Name (_SUN, name)                  \
-            }
-
-           hotplug_slot(1, 0x0001)
-           hotplug_slot(2, 0x0002)
-           hotplug_slot(3, 0x0003)
-           hotplug_slot(4, 0x0004)
-           hotplug_slot(5, 0x0005)
-           hotplug_slot(6, 0x0006)
-           hotplug_slot(7, 0x0007)
-           hotplug_slot(8, 0x0008)
-           hotplug_slot(9, 0x0009)
-           hotplug_slot(10, 0x000a)
-           hotplug_slot(11, 0x000b)
-           hotplug_slot(12, 0x000c)
-           hotplug_slot(13, 0x000d)
-           hotplug_slot(14, 0x000e)
-           hotplug_slot(15, 0x000f)
-           hotplug_slot(16, 0x0010)
-           hotplug_slot(17, 0x0011)
-           hotplug_slot(18, 0x0012)
-           hotplug_slot(19, 0x0013)
-           hotplug_slot(20, 0x0014)
-           hotplug_slot(21, 0x0015)
-           hotplug_slot(22, 0x0016)
-           hotplug_slot(23, 0x0017)
-           hotplug_slot(24, 0x0018)
-           hotplug_slot(25, 0x0019)
-           hotplug_slot(26, 0x001a)
-           hotplug_slot(27, 0x001b)
-           hotplug_slot(28, 0x001c)
-           hotplug_slot(29, 0x001d)
-           hotplug_slot(30, 0x001e)
-           hotplug_slot(31, 0x001f)
+            /* Hotplug slots generated by Makefile */
+            #include "acpi-dsdt-hotplug-slot.gen"
 
             Method (_CRS, 0, NotSerialized)
             {
@@ -664,75 +561,12 @@ DefinitionBlock (
     })
     Scope (\_GPE)
     {
-
-#define gen_cpu_hotplug(name, nr)                      \
-       If (And(\_PR.PRU, ShiftLeft(1, nr))) {     \
-           Notify(\_PR.CPU##name, 1)              \
-        }                                          \
-       If (And(\_PR.PRD, ShiftLeft(1, nr))) {     \
-           Notify(\_PR.CPU##name, 3)              \
-        }
-
         Method(_L00) {
-           gen_cpu_hotplug(1, 1)
-           gen_cpu_hotplug(2, 2)
-           gen_cpu_hotplug(3, 3)
-           gen_cpu_hotplug(4, 4)
-           gen_cpu_hotplug(5, 5)
-           gen_cpu_hotplug(6, 6)
-           gen_cpu_hotplug(7, 7)
-           gen_cpu_hotplug(8, 8)
-           gen_cpu_hotplug(9, 9)
-           gen_cpu_hotplug(A, 10)
-           gen_cpu_hotplug(B, 11)
-           gen_cpu_hotplug(C, 12)
-           gen_cpu_hotplug(D, 13)
-           gen_cpu_hotplug(E, 14)
-
+            #include "acpi-dsdt-cpu-hotplug.gen"
             Return(0x01)
         }
-
-#define gen_pci_hotplug(nr)                                       \
-            If (And(\_SB.PCI0.PCIU, ShiftLeft(1, nr))) {          \
-                Notify(\_SB.PCI0.S##nr, 1)                        \
-            }                                                     \
-            If (And(\_SB.PCI0.PCID, ShiftLeft(1, nr))) {          \
-                Notify(\_SB.PCI0.S##nr, 3)                        \
-            }
-
         Method(_L01) {
-           gen_pci_hotplug(1)
-           gen_pci_hotplug(2)
-           gen_pci_hotplug(3)
-           gen_pci_hotplug(4)
-           gen_pci_hotplug(5)
-           gen_pci_hotplug(6)
-           gen_pci_hotplug(7)
-           gen_pci_hotplug(8)
-           gen_pci_hotplug(9)
-           gen_pci_hotplug(10)
-           gen_pci_hotplug(11)
-           gen_pci_hotplug(12)
-           gen_pci_hotplug(13)
-           gen_pci_hotplug(14)
-           gen_pci_hotplug(15)
-           gen_pci_hotplug(16)
-           gen_pci_hotplug(17)
-           gen_pci_hotplug(18)
-           gen_pci_hotplug(19)
-           gen_pci_hotplug(20)
-           gen_pci_hotplug(21)
-           gen_pci_hotplug(22)
-           gen_pci_hotplug(23)
-           gen_pci_hotplug(24)
-           gen_pci_hotplug(25)
-           gen_pci_hotplug(26)
-           gen_pci_hotplug(27)
-           gen_pci_hotplug(28)
-           gen_pci_hotplug(29)
-           gen_pci_hotplug(30)
-           gen_pci_hotplug(31)
-
+            #include "acpi-dsdt-pci-hotplug.gen"
             Return(0x01)
         }
         Method(_L02) {
diff --git a/bios/acpi-dsdt.h b/bios/acpi-dsdt.h
new file mode 100755
index 0000000..68b50e8
--- /dev/null
+++ b/bios/acpi-dsdt.h
@@ -0,0 +1,67 @@
+/*
+ * DSDT generation preprocessor macros
+ *
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2008
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define gen_processor(nr, name)                                         \
+    Processor (CPU##name, nr, 0x0000b010, 0x06) {                       \
+        Name (TMP, Buffer(0x8) {0x0, 0x8, nr, nr, 0x1, 0x0, 0x0, 0x0})  \
+        Method(_MAT, 0) {                                               \
+            If (And(\_PR.PRU, ShiftLeft(1, nr))) { Return(TMP) }        \
+            Else { Return(0x0) }                                        \
+        }                                                               \
+        Method (_STA) {                                                 \
+            Return(0xF)                                                 \
+        }                                                               \
+    }                                                                   \
+
+#define gen_cpu_hotplug(nr, name)                                       \
+    If (And(\_PR.PRU, ShiftLeft(1, nr))) {                              \
+        Notify(\_PR.CPU##name, 1)                                       \
+    }                                                                   \
+    If (And(\_PR.PRD, ShiftLeft(1, nr))) {                              \
+        Notify(\_PR.CPU##name, 3)                                       \
+    }
+
+#define prt_slot(nr, lnk0, lnk1, lnk2, lnk3)                            \
+    Package() { nr##ffff, 0, lnk0, 0 },                                 \
+    Package() { nr##ffff, 1, lnk1, 0 },                                 \
+    Package() { nr##ffff, 2, lnk2, 0 },                                 \
+    Package() { nr##ffff, 3, lnk3, 0 }
+
+#define prt_slot0(nr) prt_slot(nr, LNKD, LNKA, LNKB, LNKC)
+#define prt_slot1(nr) prt_slot(nr, LNKA, LNKB, LNKC, LNKD)
+#define prt_slot2(nr) prt_slot(nr, LNKB, LNKC, LNKD, LNKA)
+#define prt_slot3(nr) prt_slot(nr, LNKC, LNKD, LNKA, LNKB)
+
+#define hotplug_slot(name, nr)                                          \
+    Device (S##name) {                                                  \
+        Name (_ADR, nr##0000)                                           \
+        Method (_EJ0,1) {                                               \
+            Store(ShiftLeft(1, nr), B0EJ)                               \
+            Return (0x0)                                                \
+        }                                                               \
+        Name (_SUN, name)                                               \
+    }
+
+#define gen_pci_hotplug(nr)                                             \
+    If (And(\_SB.PCI0.PCIU, ShiftLeft(1, nr))) {                        \
+        Notify(\_SB.PCI0.S##nr, 1)                                      \
+    }                                                                   \
+    If (And(\_SB.PCI0.PCID, ShiftLeft(1, nr))) {                        \
+        Notify(\_SB.PCI0.S##nr, 3)                                      \
+    }
diff --git a/bios/rombios.h b/bios/rombios.h
index feed101..6188fa1 100644
--- a/bios/rombios.h
+++ b/bios/rombios.h
@@ -59,8 +59,6 @@
 #define CPU_COUNT_ADDR    0xf000
 #define SMP_MSR_ADDR      0xf010
 
-#define MAX_CPUS 16
-
   // Define the application NAME
 #if defined(BX_QEMU)
 #  define BX_APPNAME "QEMU"


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to