1/*	$OpenBSD: patterns.c,v 1.13 2024/05/22 12:33:07 claudio Exp $	*/
2
3/*
4 * Copyright (c) 1995, 1996 Christopher G. Demetriou.  All rights reserved.
5 * Copyright (c) 1994 Charles Hannum.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Charles Hannum.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/types.h>
34#include <dev/pci/pcivar.h>
35#include <dev/pci/pcidevs.h>
36#include <dev/pci/pcidevs_data.h>
37
38#include "amdgpu_devlist.h"
39#include "i915_devlist.h"
40#include "radeon_devlist.h"
41
42#include <stdio.h>
43
44#define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
45
46const char *
47pci_findvendor(pci_vendor_id_t vendor)
48{
49	const struct pci_known_vendor *kdp = pci_known_vendors;
50
51        while (kdp->vendorname != NULL) {	/* all have vendor name */
52                if (kdp->vendor == vendor)
53                        break;
54		kdp++;
55	}
56        return (kdp->vendorname);
57}
58
59const char *
60pci_findproduct(pci_vendor_id_t vendor, pci_product_id_t product)
61{
62	const struct pci_known_product *pkp = pci_known_products;
63
64	while (pkp->productname != NULL) {	/* all have product name */
65		if (pkp->vendor == vendor && pkp->product == product)
66			break;
67		pkp++;
68	}
69	return (pkp->productname);
70}
71
72void
73print_devices(char driver[], const struct pci_matchid devices[], int items)
74{
75	const char *v, *p;
76	int i;
77
78	for (i = 0; i < items; i++) {
79		v = pci_findvendor(devices[i].pm_vid);
80		p = pci_findproduct(devices[i].pm_vid,
81		    devices[i].pm_pid);
82		if ( v && p )
83		    printf("%s \"%s %s\"\n", driver, v ? v : "", p ? p : "");
84	}
85}
86
87int
88main(void)
89{
90	printf("%s\n", "acx");
91	printf("%s\n", "amd");
92	printf("%s\n", "amd ^cpu0:* AMD");
93	printf("%s\n", "amdgpu");
94	print_devices("amdgpu", amdgpu_devices, nitems(amdgpu_devices));
95	printf("%s\n", "amdgpu ^vga*vendor \"ATI\", unknown product");
96	printf("%s\n", "amdgpu ^vendor \"ATI\", unknown product*class display");
97	printf("%s\n", "apple-boot ^cpu0*Apple");
98	printf("%s\n", "arm64-qcom-dtb ^qcgpio0");
99	printf("%s\n", "athn");
100	printf("%s\n", "bwfm");
101	printf("%s\n", "bwi");
102	printf("%s\n", "intel");
103	printf("%s\n", "intel ^cpu0:*Intel");
104	printf("%s\n", "inteldrm");
105	print_devices("inteldrm", i915_devices, nitems(i915_devices));
106	printf("%s\n", "ipw");
107	printf("%s\n", "iwi");
108	printf("%s\n", "iwm");
109	printf("%s\n", "iwn");
110	printf("%s\n", "iwx");
111	printf("%s\n", "malo");
112	printf("%s\n", "mtw");
113	printf("%s\n", "mwx");
114	printf("%s\n", "ogx");
115	printf("%s\n", "otus");
116	printf("%s\n", "pgt");
117	printf("%s\n", "qcpas");
118	printf("%s\n", "qcpas ^ppb0*\"Qualcomm SC8280XP PCIe\"");
119	printf("%s\n", "qwx");
120	printf("%s\n", "radeondrm");
121	print_devices("radeondrm", radeon_devices, nitems(radeon_devices));
122	printf("%s\n", "rsu");
123	printf("%s\n", "uath");
124	printf("%s\n", "upgt");
125	printf("%s\n", "uvideo");
126	printf("%s\n", "vmm");
127	printf("%s\n", "wpi");
128
129	return 0;
130}
131