intel: aubinator: generate a standalone binary

Embed the xml files into the binary, so aubinator can be used from any
location.

v2: Split generation packing into another patch (Jason)
    Check for xxd (Jason)

v3: Fix out of tree builds (Jason)
    Generate custom variable name rather than names generated by xxd
    (Lionel)

v4: Move generated _xml.h files to genxml/ (Sirisha)

v5: Remove newline from makefile (Jason)

v6: Add comment on gen*_xml.h creation (Jason)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Lionel Landwerlin
2016-10-04 16:19:43 +01:00
parent 4d7d9825f3
commit 63a366a881
7 changed files with 103 additions and 53 deletions

View File

@@ -110,6 +110,7 @@ LT_PREREQ([2.2])
LT_INIT([disable-static]) LT_INIT([disable-static])
AC_CHECK_PROG(RM, rm, [rm -f]) AC_CHECK_PROG(RM, rm, [rm -f])
AC_CHECK_PROG(XXD, xxd, [xxd])
AX_PROG_BISON([], AX_PROG_BISON([],
AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-parse.c"], AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-parse.c"],

View File

@@ -21,7 +21,7 @@
BUILT_SOURCES += $(GENXML_GENERATED_FILES) BUILT_SOURCES += $(GENXML_GENERATED_FILES)
SUFFIXES = _pack.h .xml SUFFIXES = _pack.h _xml.h .xml
$(GENXML_GENERATED_FILES): genxml/gen_pack_header.py $(GENXML_GENERATED_FILES): genxml/gen_pack_header.py
@@ -29,6 +29,16 @@ $(GENXML_GENERATED_FILES): genxml/gen_pack_header.py
$(MKDIR_GEN) $(MKDIR_GEN)
$(PYTHON_GEN) $(srcdir)/genxml/gen_pack_header.py $< > $@ $(PYTHON_GEN) $(srcdir)/genxml/gen_pack_header.py $< > $@
# xxd generates variable names based on the path of the input file. We
# prefer to generate our own name here, so it doesn't vary from
# in/out-of-tree builds.
%_xml.h: %.xml Makefile
$(MKDIR_GEN)
$(AM_V_GEN) echo -n "static const uint8_t " > $@; \
sed -e 's,_xml.h,,' <<< "`basename $@`_xml[] = {" >> $@; \
cat $< | $(XXD) -i >> $@; \
echo "};" >> $@
EXTRA_DIST += \ EXTRA_DIST += \
genxml/gen4.xml \ genxml/gen4.xml \
genxml/gen45.xml \ genxml/gen45.xml \

View File

@@ -21,7 +21,12 @@ GENXML_GENERATED_FILES = \
genxml/gen7_pack.h \ genxml/gen7_pack.h \
genxml/gen75_pack.h \ genxml/gen75_pack.h \
genxml/gen8_pack.h \ genxml/gen8_pack.h \
genxml/gen9_pack.h genxml/gen9_pack.h \
genxml/gen6_xml.h \
genxml/gen7_xml.h \
genxml/gen75_xml.h \
genxml/gen8_xml.h \
genxml/gen9_xml.h
ISL_FILES = \ ISL_FILES = \
isl/isl.c \ isl/isl.c \

View File

@@ -1 +1,2 @@
gen*_pack.h gen*_pack.h
gen*_xml.h

View File

@@ -1048,21 +1048,19 @@ int main(int argc, char *argv[])
int c, i; int c, i;
bool help = false, pager = true; bool help = false, pager = true;
const char *input_file = NULL; const char *input_file = NULL;
char gen_file[256], gen_val[24]; char gen_val[24];
const struct { const struct {
const char *name; const char *name;
int pci_id; int pci_id;
int major;
int minor;
} gens[] = { } gens[] = {
{ "ivb", 0x0166, 7, 0 }, /* Intel(R) Ivybridge Mobile GT2 */ { "ivb", 0x0166 }, /* Intel(R) Ivybridge Mobile GT2 */
{ "hsw", 0x0416, 7, 5 }, /* Intel(R) Haswell Mobile GT2 */ { "hsw", 0x0416 }, /* Intel(R) Haswell Mobile GT2 */
{ "byt", 0x0155, 7, 5 }, /* Intel(R) Bay Trail */ { "byt", 0x0155 }, /* Intel(R) Bay Trail */
{ "bdw", 0x1616, 8, 0 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */ { "bdw", 0x1616 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
{ "chv", 0x22B3, 8, 0 }, /* Intel(R) HD Graphics (Cherryview) */ { "chv", 0x22B3 }, /* Intel(R) HD Graphics (Cherryview) */
{ "skl", 0x1912, 9, 0 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */ { "skl", 0x1912 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */
{ "kbl", 0x591D, 9, 0 }, /* Intel(R) Kabylake GT2 */ { "kbl", 0x591D }, /* Intel(R) Kabylake GT2 */
{ "bxt", 0x0A84, 9, 0 } /* Intel(R) HD Graphics (Broxton) */ { "bxt", 0x0A84 } /* Intel(R) HD Graphics (Broxton) */
}, *gen = NULL; }, *gen = NULL;
const struct option aubinator_opts[] = { const struct option aubinator_opts[] = {
{ "help", no_argument, (int *) &help, true }, { "help", no_argument, (int *) &help, true },
@@ -1073,6 +1071,7 @@ int main(int argc, char *argv[])
{ "color", required_argument, NULL, 'c' }, { "color", required_argument, NULL, 'c' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
struct gen_device_info devinfo;
i = 0; i = 0;
while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) { while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) {
@@ -1118,6 +1117,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!gen_get_device_info(gen->pci_id, &devinfo)) {
fprintf(stderr, "can't find device information: pci_id=0x%x name=%s\n",
gen->pci_id, gen->name);
exit(EXIT_FAILURE);
}
/* Do this before we redirect stdout to pager. */ /* Do this before we redirect stdout to pager. */
if (option_color == COLOR_AUTO) if (option_color == COLOR_AUTO)
option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER; option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
@@ -1125,14 +1131,7 @@ int main(int argc, char *argv[])
if (isatty(1) && pager) if (isatty(1) && pager)
setup_pager(); setup_pager();
if (gen->minor > 0) { spec = gen_spec_load(&devinfo);
snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d%d.xml",
gen->major, gen->minor);
} else {
snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml", gen->major);
}
spec = gen_spec_load(gen_file);
disasm = gen_disasm_create(gen->pci_id); disasm = gen_disasm_create(gen->pci_id);
if (input_file == NULL) { if (input_file == NULL) {

View File

@@ -33,6 +33,12 @@
#include "decoder.h" #include "decoder.h"
#include "genxml/gen6_xml.h"
#include "genxml/gen7_xml.h"
#include "genxml/gen75_xml.h"
#include "genxml/gen8_xml.h"
#include "genxml/gen9_xml.h"
#define XML_BUFFER_SIZE 4096 #define XML_BUFFER_SIZE 4096
#define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) ) #define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
@@ -395,57 +401,83 @@ character_data(void *data, const XML_Char *s, int len)
{ {
} }
static int
devinfo_to_gen(const struct gen_device_info *devinfo)
{
int value = 10 * devinfo->gen;
if (devinfo->is_baytrail || devinfo->is_haswell)
value += 5;
return value;
}
static const struct {
int gen;
const uint8_t *data;
size_t data_length;
} gen_data[] = {
{ .gen = 60, .data = gen6_xml, .data_length = sizeof(gen6_xml) },
{ .gen = 70, .data = gen7_xml, .data_length = sizeof(gen7_xml) },
{ .gen = 75, .data = gen75_xml, .data_length = sizeof(gen75_xml) },
{ .gen = 80, .data = gen8_xml, .data_length = sizeof(gen8_xml) },
{ .gen = 90, .data = gen9_xml, .data_length = sizeof(gen9_xml) }
};
static const uint8_t *
devinfo_to_xml_data(const struct gen_device_info *devinfo,
uint32_t *data_length)
{
int i, gen = devinfo_to_gen(devinfo);
for (i = 0; i < ARRAY_SIZE(gen_data); i++) {
if (gen_data[i].gen == gen) {
*data_length = gen_data[i].data_length;
return gen_data[i].data;
}
}
unreachable("Unknown generation");
return NULL;
}
struct gen_spec * struct gen_spec *
gen_spec_load(const char *filename) gen_spec_load(const struct gen_device_info *devinfo)
{ {
struct parser_context ctx; struct parser_context ctx;
void *buf; void *buf;
int len; const void *data;
FILE *input; uint32_t data_length = 0;
input = fopen(filename, "r");
printf("xml filename = %s\n", filename);
if (input == NULL) {
fprintf(stderr, "failed to open xml description\n");
exit(EXIT_FAILURE);
}
memset(&ctx, 0, sizeof ctx); memset(&ctx, 0, sizeof ctx);
ctx.parser = XML_ParserCreate(NULL); ctx.parser = XML_ParserCreate(NULL);
XML_SetUserData(ctx.parser, &ctx); XML_SetUserData(ctx.parser, &ctx);
if (ctx.parser == NULL) { if (ctx.parser == NULL) {
fprintf(stderr, "failed to create parser\n"); fprintf(stderr, "failed to create parser\n");
fclose(input);
return NULL; return NULL;
} }
XML_SetElementHandler(ctx.parser, start_element, end_element); XML_SetElementHandler(ctx.parser, start_element, end_element);
XML_SetCharacterDataHandler(ctx.parser, character_data); XML_SetCharacterDataHandler(ctx.parser, character_data);
ctx.loc.filename = filename;
ctx.spec = xzalloc(sizeof(*ctx.spec)); ctx.spec = xzalloc(sizeof(*ctx.spec));
do { data = devinfo_to_xml_data(devinfo, &data_length);
buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE); buf = XML_GetBuffer(ctx.parser, data_length);
len = fread(buf, 1, XML_BUFFER_SIZE, input);
if (len < 0) { memcpy(buf, data, data_length);
fprintf(stderr, "fread: %m\n");
fclose(input); if (XML_ParseBuffer(ctx.parser, data_length, true) == 0) {
return NULL;
}
if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
fprintf(stderr, fprintf(stderr,
"Error parsing XML at line %ld col %ld: %s\n", "Error parsing XML at line %ld col %ld: %s\n",
XML_GetCurrentLineNumber(ctx.parser), XML_GetCurrentLineNumber(ctx.parser),
XML_GetCurrentColumnNumber(ctx.parser), XML_GetCurrentColumnNumber(ctx.parser),
XML_ErrorString(XML_GetErrorCode(ctx.parser))); XML_ErrorString(XML_GetErrorCode(ctx.parser)));
fclose(input); XML_ParserFree(ctx.parser);
return NULL; return NULL;
} }
} while (len > 0);
XML_ParserFree(ctx.parser); XML_ParserFree(ctx.parser);
fclose(input);
return ctx.spec; return ctx.spec;
} }

View File

@@ -26,6 +26,8 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "common/gen_device_info.h"
struct gen_spec; struct gen_spec;
struct gen_group; struct gen_group;
struct gen_field; struct gen_field;
@@ -36,7 +38,7 @@ static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
} }
struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name); struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
struct gen_spec *gen_spec_load(const char *filename); struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
uint32_t gen_spec_get_gen(struct gen_spec *spec); uint32_t gen_spec_get_gen(struct gen_spec *spec);
struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p); struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset); struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);