[PATCH 1/2] xfree86: add pci id matching to OutputClass
Dave Airlie
airlied at gmail.com
Tue Feb 9 03:24:51 UTC 2016
This will be used by drivers to denote PCI ids in the future
instead of hardcoding them in the server.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
hw/xfree86/common/xf86platformBus.c | 14 ++++++++++++++
hw/xfree86/parser/OutputClass.c | 21 +++++++++++++++++++++
hw/xfree86/parser/xf86Parser.h | 1 +
hw/xfree86/parser/xf86tokens.h | 1 +
4 files changed, 37 insertions(+)
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 96895a6..70064ae 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -164,6 +164,12 @@ xf86_check_platform_slot(const struct xf86_platform_device *pd)
return TRUE;
}
+static int
+match_substring(const char *attr, const char *pattern)
+{
+ return (strstr(attr, pattern)) ? 0 : -1;
+}
+
static Bool
MatchToken(const char *value, struct xorg_list *patterns,
int (*compare)(const char *, const char *))
@@ -205,10 +211,18 @@ static Bool
OutputClassMatches(const XF86ConfOutputClassPtr oclass, int index)
{
char *driver = xf86_platform_odev_attributes(index)->driver;
+ struct pci_device *pdev = xf86_platform_devices[index].pdev;
+ char pciid_str[64];
if (!MatchToken(driver, &oclass->match_driver, strcmp))
return FALSE;
+ if (pdev) {
+ snprintf(pciid_str, 64, "%04x:%04x", pdev->vendor_id, pdev->device_id);
+ if (!MatchToken(pciid_str, &oclass->match_pciid, match_substring))
+ return FALSE;
+ }
+
return TRUE;
}
diff --git a/hw/xfree86/parser/OutputClass.c b/hw/xfree86/parser/OutputClass.c
index 3f2082e..2dad412 100644
--- a/hw/xfree86/parser/OutputClass.c
+++ b/hw/xfree86/parser/OutputClass.c
@@ -38,6 +38,7 @@ xf86ConfigSymTabRec OutputClassTab[] = {
{IDENTIFIER, "identifier"},
{DRIVER, "driver"},
{MATCH_DRIVER, "matchdriver"},
+ {MATCH_PCIID, "matchpciid"},
{-1, ""},
};
@@ -61,6 +62,13 @@ xf86freeOutputClassList(XF86ConfOutputClassPtr ptr)
free(group);
}
+ xorg_list_for_each_entry_safe(group, next, &ptr->match_pciid, entry) {
+ xorg_list_del(&group->entry);
+ for (list = group->values; *list; list++)
+ free(*list);
+ free(group);
+ }
+
prev = ptr;
ptr = ptr->list.next;
free(prev);
@@ -93,6 +101,7 @@ xf86parseOutputClassSection(void)
/* Initialize MatchGroup lists */
xorg_list_init(&ptr->match_driver);
+ xorg_list_init(&ptr->match_pciid);
while ((token = xf86getToken(OutputClassTab)) != ENDSECTION) {
switch (token) {
@@ -120,6 +129,13 @@ xf86parseOutputClassSection(void)
xstrtokenize(xf86_lex_val.str, TOKEN_SEP));
free(xf86_lex_val.str);
break;
+ case MATCH_PCIID:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchPCIID");
+ add_group_entry(&ptr->match_pciid,
+ xstrtokenize(xf86_lex_val.str, TOKEN_SEP));
+ free(xf86_lex_val.str);
+ break;
case EOF_TOKEN:
Error(UNEXPECTED_EOF_MSG);
break;
@@ -158,6 +174,11 @@ xf86printOutputClassSection(FILE * cf, XF86ConfOutputClassPtr ptr)
for (cur = group->values; *cur; cur++)
fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP,
*cur);
+ fprintf(cf, "\"\n");
+ fprintf(cf, "\tMatchPCIID \"");
+ for (cur = group->values; *cur; cur++)
+ fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP,
+ *cur);
fprintf(cf, "\"\n");
}
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index a038f9e..26a7fbc 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -337,6 +337,7 @@ typedef struct {
char *identifier;
char *driver;
struct xorg_list match_driver;
+ struct xorg_list match_pciid;
char *comment;
} XF86ConfOutputClassRec, *XF86ConfOutputClassPtr;
diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h
index f955af0..dfb8b7a 100644
--- a/hw/xfree86/parser/xf86tokens.h
+++ b/hw/xfree86/parser/xf86tokens.h
@@ -278,6 +278,7 @@ typedef enum {
MATCH_OS,
MATCH_PNPID,
MATCH_USBID,
+ MATCH_PCIID,
MATCH_DRIVER,
MATCH_TAG,
MATCH_LAYOUT,
--
2.5.0
More information about the xorg-devel
mailing list