kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] acpi: extract aml from .lst
@ 2011-10-26 21:28 Michael S. Tsirkin
  2011-10-28  0:08 ` Kevin O'Connor
  2011-10-30 17:51 ` Kevin O'Connor
  0 siblings, 2 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2011-10-26 21:28 UTC (permalink / raw)
  To: Amos Kong
  Cc: Kevin O'Connor, seabios, Gleb Natapov, kvm, jasowang,
	alex williamson, Marcelo Tosatti

Add ACPI_EXTRACT_ALL_CODE directive, to support extracting
AML code from listing into a named array. Use that instead including C
file generated by iasl, this makes it possible to include multiple AML
tables without resorting to preprocessor tricks.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

---

Kevin, you suggested something like the below, I think?  Seems to work
but RFC since I didn't have time to test this properly.

diff --git a/Makefile b/Makefile
index 91d9b77..200a07a 100644
--- a/Makefile
+++ b/Makefile
@@ -198,7 +198,7 @@ src/%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py
 	$(Q)./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
 	$(Q)iasl -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
 	$(Q)./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
-	$(Q)cat $(OUT)$*.hex $(OUT)$*.off > $@
+	$(Q)cat $(OUT)$*.off > $@
 
 $(OUT)ccode32flat.o: src/acpi-dsdt.hex src/ssdt-proc.hex
 
diff --git a/src/acpi-dsdt.dsl b/src/acpi-dsdt.dsl
index a5f0a4d..b9b06f2 100644
--- a/src/acpi-dsdt.dsl
+++ b/src/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
  */
+
+ACPI_EXTRACT_ALL_CODE AmlCode
+
 DefinitionBlock (
     "acpi-dsdt.aml",    // Output Filename
     "DSDT",             // Signature
diff --git a/src/acpi.c b/src/acpi.c
index 27a939e..f743bdd 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -366,9 +366,7 @@ encodeLen(u8 *ssdt_ptr, int length, int bytes)
     return ssdt_ptr + bytes;
 }
 
-#define AmlCode static ssdp_proc_aml
 #include "ssdt-proc.hex"
-#undef AmlCode
 
 /* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
 #define SD_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
diff --git a/src/ssdt-proc.dsl b/src/ssdt-proc.dsl
index a461636..0339422 100644
--- a/src/ssdt-proc.dsl
+++ b/src/ssdt-proc.dsl
@@ -14,6 +14,9 @@
  * and a CPON array with the list of active and inactive cpus:
  *     Name(CPON, Package() { One, One, ..., Zero, Zero, ... })
  */
+
+ACPI_EXTRACT_ALL_CODE ssdp_proc_aml
+
 DefinitionBlock ("ssdt-proc.aml", "SSDT", 0x01, "BXPC", "BXSSDT", 0x1)
 {
     ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
diff --git a/tools/acpi_extract.py b/tools/acpi_extract.py
index 9083cff..5f613e4 100755
--- a/tools/acpi_extract.py
+++ b/tools/acpi_extract.py
@@ -29,6 +29,8 @@
 # ACPI_EXTRACT_PROCESSOR_START - start of Processor() block
 # ACPI_EXTRACT_PROCESSOR_STRING - extract a NameString from Processor()
 # ACPI_EXTRACT_PROCESSOR_END - offset at last byte of Processor() + 1
+#
+# ACPI_EXTRACT_ALL_CODE - create an array storing the generated AML bytecode
 # 
 # ACPI_EXTRACT is not allowed anywhere else in code, except in comments.
 
@@ -240,6 +242,11 @@ for i in range(len(asl)):
     array = mext.group(2)
     offset = asl[i].aml_offset
 
+    if (directive == "ACPI_EXTRACT_ALL_CODE"):
+        if array in output:
+            die("%s directive used more than once" % directive)
+        output[array] = aml
+        continue
     if (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
@@ -261,21 +268,25 @@ for i in range(len(asl)):
 
     if array not in output:
         output[array] = []
-    output[array].append("0x%x" % offset)
+    output[array].append(offset)
 
 debug = "at end of file"
 
-#Use type large enough to fit the table
-if (len(aml) >= 0x10000):
-	offsettype = "int"
-elif (len(aml) >= 0x100):
-	offsettype = "short"
-else:
-	offsettype = "char"
+def get_value_type(maxvalue):
+    #Use type large enough to fit the table
+    if (maxvalue >= 0x10000):
+            return "int"
+    elif (maxvalue >= 0x100):
+            return "short"
+    else:
+            return "char"
 
 # Pretty print output
 for array in output.keys():
-    
-    sys.stdout.write("static unsigned %s %s[] = {\n" % (offsettype, array))
-    sys.stdout.write(",\n".join(output[array]))
+    otype = get_value_type(max(output[array]))
+    odata = []
+    for value in output[array]:
+        odata.append("0x%x" % value)
+    sys.stdout.write("static unsigned %s %s[] = {\n" % (otype, array))
+    sys.stdout.write(",\n".join(odata))
     sys.stdout.write('\n};\n');

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC] acpi: extract aml from .lst
  2011-10-26 21:28 [PATCH RFC] acpi: extract aml from .lst Michael S. Tsirkin
@ 2011-10-28  0:08 ` Kevin O'Connor
  2011-10-30 17:51 ` Kevin O'Connor
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin O'Connor @ 2011-10-28  0:08 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: seabios, kvm

On Wed, Oct 26, 2011 at 11:28:02PM +0200, Michael S. Tsirkin wrote:
> Add ACPI_EXTRACT_ALL_CODE directive, to support extracting
> AML code from listing into a named array. Use that instead including C
> file generated by iasl, this makes it possible to include multiple AML
> tables without resorting to preprocessor tricks.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> ---
> 
> Kevin, you suggested something like the below, I think?  Seems to work
> but RFC since I didn't have time to test this properly.

It looks okay to me (I didn't do any exhaustive tests either).  It
would be preferable if we didn't have to change the acpi-dsdt.dsl file
though - that way users could still compile it with the iasl compiler
directly.  Can the output default to "AmlCode" if no directive is
found?

-Kevin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC] acpi: extract aml from .lst
  2011-10-26 21:28 [PATCH RFC] acpi: extract aml from .lst Michael S. Tsirkin
  2011-10-28  0:08 ` Kevin O'Connor
@ 2011-10-30 17:51 ` Kevin O'Connor
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin O'Connor @ 2011-10-30 17:51 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Amos Kong, seabios, Gleb Natapov, kvm, jasowang, alex williamson,
	Marcelo Tosatti

On Wed, Oct 26, 2011 at 11:28:02PM +0200, Michael S. Tsirkin wrote:
> Add ACPI_EXTRACT_ALL_CODE directive, to support extracting
> AML code from listing into a named array. Use that instead including C
> file generated by iasl, this makes it possible to include multiple AML
> tables without resorting to preprocessor tricks.

Thanks - I applied this patch.

-Kevin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-30 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-26 21:28 [PATCH RFC] acpi: extract aml from .lst Michael S. Tsirkin
2011-10-28  0:08 ` Kevin O'Connor
2011-10-30 17:51 ` Kevin O'Connor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).