<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 4, 2016 at 7:38 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:llandwerlin@gmail.com" target="_blank">llandwerlin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Embed the xml files into the binary, so aubinator can be used from any<br>
location.<br></blockquote><div><br></div><div>Thank you for doing this!!! Dynamically loading the xml has a few benefits, but I think the benefits of not having to find them on disk are far bigger.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
Cc: Sirisha Gandikota <<a href="mailto:Sirisha.Gandikota@intel.com">Sirisha.Gandikota@intel.com</a>><br>
---<br>
src/intel/Makefile.am | 1 +<br>
src/intel/<a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.aubinator.<wbr>am</a> | 36 +++++++++++++++<br>
src/intel/Makefile.sources | 7 +++<br>
src/intel/tools/.gitignore | 5 +++<br>
src/intel/tools/aubinator.c | 97 +++++++++++++++++-------------<wbr>-----------<br>
src/intel/tools/decoder.c | 82 ++++++++++++++++++++----------<wbr>----<br>
src/intel/tools/decoder.h | 4 +-<br>
7 files changed, 141 insertions(+), 91 deletions(-)<br>
create mode 100644 src/intel/<a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.aubinator.<wbr>am</a><br>
<br>
diff --git a/src/intel/Makefile.am b/src/intel/Makefile.am<br>
index 9186b5c..c3cb9fb 100644<br>
--- a/src/intel/Makefile.am<br>
+++ b/src/intel/Makefile.am<br>
@@ -52,6 +52,7 @@ BUILT_SOURCES =<br>
CLEANFILES =<br>
EXTRA_DIST =<br>
<br>
+include <a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.aubinator.am</a><br>
include <a href="http://Makefile.blorp.am" rel="noreferrer" target="_blank">Makefile.blorp.am</a><br>
include <a href="http://Makefile.common.am" rel="noreferrer" target="_blank">Makefile.common.am</a><br>
include <a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a><br>
diff --git a/src/intel/<a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.<wbr>aubinator.am</a> b/src/intel/<a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.<wbr>aubinator.am</a><br>
new file mode 100644<br>
index 0000000..9772700<br>
--- /dev/null<br>
+++ b/src/intel/<a href="http://Makefile.aubinator.am" rel="noreferrer" target="_blank">Makefile.<wbr>aubinator.am</a><br>
@@ -0,0 +1,36 @@<br>
+# Copyright © 2016 Intel Corporation<br>
+#<br>
+# Permission is hereby granted, free of charge, to any person obtaining a<br>
+# copy of this software and associated documentation files (the "Software"),<br>
+# to deal in the Software without restriction, including without limitation<br>
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+# and/or sell copies of the Software, and to permit persons to whom the<br>
+# Software is furnished to do so, subject to the following conditions:<br>
+#<br>
+# The above copyright notice and this permission notice (including the next<br>
+# paragraph) shall be included in all copies or substantial portions of the<br>
+# Software.<br>
+#<br>
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+# IN THE SOFTWARE.<br>
+<br>
+BUILT_SOURCES += $(AUBINATOR_GENERATED_FILES)<br>
+<br>
+SUFFIXES = _aubinator_xml.h .xml<br>
+<br>
+tools/gen6_aubinator_xml.h: genxml/gen6.xml<br>
+tools/gen7_aubinator_xml.h: genxml/gen7.xml<br>
+tools/gen75_aubinator_xml.h: genxml/gen75.xml<br>
+tools/gen8_aubinator_xml.h: genxml/gen8.xml<br>
+tools/gen9_aubinator_xml.h: genxml/gen9.xml<br>
+<br>
+$(AUBINATOR_GENERATED_FILES): Makefile<br>
+<br>
+%_aubinator_xml.h:<br>
+ $(MKDIR_GEN)<br>
+ $(AM_V_GEN) xxd -i $< > $@<br></blockquote><div><br></div><div>We should probably check for xxd in <a href="http://configure.ac">configure.ac</a> and use $(XXD) here. I know that it's not installed by default on Fedora, so just using it is kind-of mean.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 94073d2..a5c2bf0 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -1,3 +1,10 @@<br>
+AUBINATOR_GENERATED_FILES = \<br>
+ tools/gen6_aubinator_xml.h \<br>
+ tools/gen7_aubinator_xml.h \<br>
+ tools/gen75_aubinator_xml.h \<br>
+ tools/gen8_aubinator_xml.h \<br>
+ tools/gen9_aubinator_xml.h<br>
+<br>
BLORP_FILES = \<br>
blorp/blorp.c \<br>
blorp/blorp.h \<br>
diff --git a/src/intel/tools/.gitignore b/src/intel/tools/.gitignore<br>
index 0c80a6f..c4eebde 100644<br>
--- a/src/intel/tools/.gitignore<br>
+++ b/src/intel/tools/.gitignore<br>
@@ -1 +1,6 @@<br>
/aubinator<br>
+gen6_aubinator_xml.h<br>
+gen75_aubinator_xml.h<br>
+gen7_aubinator_xml.h<br>
+gen8_aubinator_xml.h<br>
+gen9_aubinator_xml.h<br>
diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c<br>
index a31dcb2..83328b5 100644<br>
--- a/src/intel/tools/aubinator.c<br>
+++ b/src/intel/tools/aubinator.c<br>
@@ -35,6 +35,8 @@<br>
#include <sys/wait.h><br>
#include <sys/mman.h><br>
<br>
+#include "util/macros.h"<br>
+<br>
#include "decoder.h"<br>
#include "intel_aub.h"<br>
#include "gen_disasm.h"<br>
@@ -1059,11 +1061,24 @@ int main(int argc, char *argv[])<br>
{<br>
struct gen_spec *spec;<br>
struct aub_file *file;<br>
- int i, pci_id = 0;<br>
+ int i;<br>
bool found_arg_gen = false, pager = true;<br>
- int gen_major, gen_minor;<br>
- const char *value;<br>
- char gen_file[256], gen_val[24];<br>
+ const char *value, *input_file = NULL;<br>
+ char gen_val[24];<br>
+ const struct {<br>
+ const char *name;<br>
+ int pci_id;<br>
+ } gens[] = {<br>
+ { "ivb", 0x0166 }, /* Intel(R) Ivybridge Mobile GT2 */<br>
+ { "hsw", 0x0416 }, /* Intel(R) Haswell Mobile GT2 */<br>
+ { "byt", 0x0155 }, /* Intel(R) Bay Trail */<br>
+ { "bdw", 0x1616 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */<br>
+ { "chv", 0x22B3 }, /* Intel(R) HD Graphics (Cherryview) */<br>
+ { "skl", 0x1912 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */<br>
+ { "kbl", 0x591D }, /* Intel(R) Kabylake GT2 */<br>
+ { "bxt", 0x0A84 } /* Intel(R) HD Graphics (Broxton) */<br>
+ }, *gen = NULL;<br>
+ struct gen_device_info devinfo;<br>
<br>
if (argc == 1) {<br>
print_help(argv[0], stderr);<br>
@@ -1081,8 +1096,6 @@ int main(int argc, char *argv[])<br>
exit(EXIT_FAILURE);<br>
}<br>
found_arg_gen = true;<br>
- gen_major = 0;<br>
- gen_minor = 0;<br>
snprintf(gen_val, sizeof(gen_val), "%s", value);<br>
} else if (strcmp(argv[i], "--headers") == 0) {<br>
option_full_decode = false;<br>
@@ -1105,6 +1118,7 @@ int main(int argc, char *argv[])<br>
fprintf(stderr, "unknown option %s\n", argv[i]);<br>
exit(EXIT_FAILURE);<br>
}<br>
+ input_file = argv[i];<br>
break;<br>
}<br>
}<br>
@@ -1114,52 +1128,26 @@ int main(int argc, char *argv[])<br>
exit(EXIT_FAILURE);<br>
}<br>
<br>
- if (strstr(gen_val, "ivb") != NULL) {<br>
- /* Intel(R) Ivybridge Mobile GT2 */<br>
- pci_id = 0x0166;<br>
- gen_major = 7;<br>
- gen_minor = 0;<br>
- } else if (strstr(gen_val, "hsw") != NULL) {<br>
- /* Intel(R) Haswell Mobile GT2 */<br>
- pci_id = 0x0416;<br>
- gen_major = 7;<br>
- gen_minor = 5;<br>
- } else if (strstr(gen_val, "byt") != NULL) {<br>
- /* Intel(R) Bay Trail */<br>
- pci_id = 0x0155;<br>
- gen_major = 7;<br>
- gen_minor = 5;<br>
- } else if (strstr(gen_val, "bdw") != NULL) {<br>
- /* Intel(R) HD Graphics 5500 (Broadwell GT2) */<br>
- pci_id = 0x1616;<br>
- gen_major = 8;<br>
- gen_minor = 0;<br>
- } else if (strstr(gen_val, "chv") != NULL) {<br>
- /* Intel(R) HD Graphics (Cherryview) */<br>
- pci_id = 0x22B3;<br>
- gen_major = 8;<br>
- gen_minor = 0;<br>
- } else if (strstr(gen_val, "skl") != NULL) {<br>
- /* Intel(R) HD Graphics 530 (Skylake GT2) */<br>
- pci_id = 0x1912;<br>
- gen_major = 9;<br>
- gen_minor = 0;<br>
- } else if (strstr(gen_val, "kbl") != NULL) {<br>
- /* Intel(R) Kabylake GT2 */<br>
- pci_id = 0x591D;<br>
- gen_major = 9;<br>
- gen_minor = 0;<br>
- } else if (strstr(gen_val, "bxt") != NULL) {<br>
- /* Intel(R) HD Graphics (Broxton) */<br>
- pci_id = 0x0A84;<br>
- gen_major = 9;<br>
- gen_minor = 0;<br>
- } else {<br>
+ for (i = 0; i < ARRAY_SIZE(gens); i++) {<br>
+ if (!strcmp(gen_val, gens[i].name)) {<br>
+ gen = &gens[i];<br>
+ break;<br>
+ }<br>
+ }<br></blockquote><div><br></div><div>I like this change but it feels like something that should be in it's own patch.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ if (gen == NULL) {<br>
fprintf(stderr, "can't parse gen: %s, expected ivb, byt, hsw, "<br>
"bdw, chv, skl, kbl or bxt\n", gen_val);<br>
exit(EXIT_FAILURE);<br>
}<br>
<br>
+ if (!gen_get_device_info(gen-><wbr>pci_id, &devinfo)) {<br>
+ fprintf(stderr, "can't find device information: pci_id=0x%x name=%s\n",<br>
+ gen->pci_id, gen->name);<br>
+ exit(EXIT_FAILURE);<br>
+ }<br>
+<br>
+<br>
/* Do this before we redirect stdout to pager. */<br>
if (option_color == COLOR_AUTO)<br>
option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;<br>
@@ -1167,21 +1155,14 @@ int main(int argc, char *argv[])<br>
if (isatty(1) && pager)<br>
setup_pager();<br>
<br>
- if (gen_minor > 0) {<br>
- snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d%d.xml",<br>
- gen_major, gen_minor);<br>
- } else {<br>
- snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml", gen_major);<br>
- }<br>
-<br>
- spec = gen_spec_load(gen_file);<br>
- disasm = gen_disasm_create(pci_id);<br>
+ spec = gen_spec_load(&devinfo);<br>
+ disasm = gen_disasm_create(gen->pci_id)<wbr>;<br>
<br>
- if (argv[i] == NULL) {<br>
+ if (input_file == NULL) {<br>
print_help(argv[0], stderr);<br>
exit(EXIT_FAILURE);<br>
} else {<br>
- file = aub_file_open(argv[i]);<br>
+ file = aub_file_open(input_file);<br>
}<br>
<br>
while (aub_file_more_stuff(file))<br>
diff --git a/src/intel/tools/decoder.c b/src/intel/tools/decoder.c<br>
index be3558b..f3edc71 100644<br>
--- a/src/intel/tools/decoder.c<br>
+++ b/src/intel/tools/decoder.c<br>
@@ -32,6 +32,12 @@<br>
<br>
#include "decoder.h"<br>
<br>
+#include "gen6_aubinator_xml.h"<br>
+#include "gen7_aubinator_xml.h"<br>
+#include "gen75_aubinator_xml.h"<br>
+#include "gen8_aubinator_xml.h"<br>
+#include "gen9_aubinator_xml.h"<br>
+<br>
#define XML_BUFFER_SIZE 4096<br>
<br>
#define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )<br>
@@ -394,57 +400,69 @@ character_data(void *data, const XML_Char *s, int len)<br>
{<br>
}<br>
<br>
+static void *<br>
+devinfo_to_xml_data(const struct gen_device_info *devinfo,<br>
+ uint32_t *data_length)<br>
+{<br>
+ switch (devinfo->gen) {<br>
+ case 6:<br>
+ *data_length = sizeof(genxml_gen6_xml);<br>
+ return genxml_gen6_xml;<br>
+ case 7:<br>
+ if (devinfo->is_haswell) {<br>
+ *data_length = sizeof(genxml_gen75_xml);<br>
+ return genxml_gen75_xml;<br>
+ }<br>
+ *data_length = sizeof(genxml_gen7_xml);<br>
+ return genxml_gen7_xml;<br>
+ case 8:<br>
+ *data_length = sizeof(genxml_gen8_xml);<br>
+ return genxml_gen8_xml;<br>
+ case 9:<br>
+ *data_length = sizeof(genxml_gen9_xml);<br>
+ return genxml_gen9_xml;<br>
+ default:<br>
+ return NULL;<br>
+ }<br>
+}<br>
+<br>
struct gen_spec *<br>
-gen_spec_load(const char *filename)<br>
+gen_spec_load(const struct gen_device_info *devinfo)<br>
{<br>
struct parser_context ctx;<br>
- void *buf;<br>
- int len;<br>
- FILE *input;<br>
-<br>
- input = fopen(filename, "r");<br>
- printf("xml filename = %s\n", filename);<br>
- if (input == NULL) {<br>
- fprintf(stderr, "failed to open xml description\n");<br>
- exit(EXIT_FAILURE);<br>
- }<br>
+ void *buf, *data;<br>
+ uint32_t data_length = 0;<br>
<br>
memset(&ctx, 0, sizeof ctx);<br>
ctx.parser = XML_ParserCreate(NULL);<br>
XML_SetUserData(ctx.parser, &ctx);<br>
if (ctx.parser == NULL) {<br>
fprintf(stderr, "failed to create parser\n");<br>
- fclose(input);<br>
return NULL;<br>
}<br>
<br>
XML_SetElementHandler(ctx.<wbr>parser, start_element, end_element);<br>
XML_SetCharacterDataHandler(<wbr>ctx.parser, character_data);<br>
- ctx.loc.filename = filename;<br>
<br>
ctx.spec = xzalloc(sizeof(*ctx.spec));<br>
<br>
- do {<br>
- buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);<br>
- len = fread(buf, 1, XML_BUFFER_SIZE, input);<br>
- if (len < 0) {<br>
- fprintf(stderr, "fread: %m\n");<br>
- fclose(input);<br>
- return NULL;<br>
- }<br>
- if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {<br>
- fprintf(stderr,<br>
- "Error parsing XML at line %ld col %ld: %s\n",<br>
- XML_GetCurrentLineNumber(ctx.<wbr>parser),<br>
- XML_GetCurrentColumnNumber(<wbr>ctx.parser),<br>
- XML_ErrorString(XML_<wbr>GetErrorCode(ctx.parser)));<br>
- fclose(input);<br>
- return NULL;<br>
- }<br>
- } while (len > 0);<br>
+<br>
+ data = devinfo_to_xml_data(devinfo, &data_length);<br>
+ buf = XML_GetBuffer(ctx.parser, data_length);<br>
+<br>
+ memcpy(buf, data, data_length);<br>
+<br>
+ if (XML_ParseBuffer(ctx.parser, data_length, data_length == 0) == 0) {<br>
+ fprintf(stderr,<br>
+ "Error parsing XML at line %ld col %ld: %s\n",<br>
+ XML_GetCurrentLineNumber(ctx.<wbr>parser),<br>
+ XML_GetCurrentColumnNumber(<wbr>ctx.parser),<br>
+ XML_ErrorString(XML_<wbr>GetErrorCode(ctx.parser)));<br>
+ XML_ParserFree(ctx.parser);<br>
+ return NULL;<br>
+ }<br>
<br>
XML_ParserFree(ctx.parser);<br>
- fclose(input);<br>
<br>
return ctx.spec;<br>
}<br>
diff --git a/src/intel/tools/decoder.h b/src/intel/tools/decoder.h<br>
index f688ba5..5bea9b9 100644<br>
--- a/src/intel/tools/decoder.h<br>
+++ b/src/intel/tools/decoder.h<br>
@@ -26,6 +26,8 @@<br>
#include <stdint.h><br>
#include <stdbool.h><br>
<br>
+#include "common/gen_device_info.h"<br>
+<br>
struct gen_spec;<br>
struct gen_group;<br>
struct gen_field;<br>
@@ -36,7 +38,7 @@ static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)<br>
}<br>
<br>
struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);<br>
-struct gen_spec *gen_spec_load(const char *filename);<br>
+struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);<br>
uint32_t gen_spec_get_gen(struct gen_spec *spec);<br>
struct gen_group *gen_spec_find_instruction(<wbr>struct gen_spec *spec, const uint32_t *p);<br>
struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>