Annotation of openbsd/fw_update/firmware_patterns.pl, Revision 1.1
1.1 ! afresh1 1: #!/usr/bin/perl
! 2: use v5.30;
! 3: use warnings;
! 4:
! 5: use File::Temp qw<>;
! 6:
! 7: my %drivers = (
! 8: acx => undef,
! 9: amdgpu => { dir => 'sys/dev/pci/drm/amd/amdgpu/', type => 'amdgpu' },
! 10: athn => undef,
! 11: bwfm => undef,
! 12: bwi => undef,
! 13: intel => ['^cpu0: Intel'],
! 14: inteldrm => { dir => 'sys/dev/pci/drm/i915/', type => 'i915' },
! 15: ipw => undef,
! 16: iwi => undef,
! 17: iwm => undef,
! 18: iwn => undef,
! 19: iwx => undef,
! 20: malo => undef,
! 21: ogx => undef,
! 22: otus => undef,
! 23: pgt => undef,
! 24: radeondrm => { dir => 'sys/dev/pci/drm/radeon/', type => 'radeon' },
! 25: rsu => undef,
! 26: rtwn => undef,
! 27: uath => undef,
! 28: upgt => undef,
! 29: urtwn => undef,
! 30: uvideo => undef,
! 31: vmm => undef,
! 32: wpi => undef,
! 33: );
! 34:
! 35: foreach my $driver (sort keys %drivers ) {
! 36: my $def = $drivers{$driver};
! 37:
! 38: say "$driver";
! 39: next unless defined $def;
! 40:
! 41: if ( ref $def eq 'ARRAY' ) {
! 42: say "$driver $_" for @{ $def };
! 43: }
! 44: elsif ( ref $def eq 'HASH' ) {
! 45: say qq{$driver $_} for products($def);
! 46: }
! 47: else { die "Unknown def for $driver!" }
! 48: }
! 49:
! 50: sub products {
! 51: state $C = do { local $/; readline *DATA };
! 52: state $D = File::Temp->newdir("firmware_patterns-XXXXXXXXX");
! 53:
! 54: my ($def) = @_;
! 55: my $type = $def->{type};
! 56:
! 57: my $f = "$D/$type";
! 58: {
! 59: open my $fh, ">", "$f.c" or die "Unable to create $f.c: $!";
! 60: $fh->print( $C =~ s/%type%/$type/gr );
! 61: close $fh;
! 62: }
! 63:
! 64: system(cc => '-o', $f, '-I', "/usr/src/$def->{dir}", "$f.c") == 0
! 65: or die "cc $f.c failed!";
! 66:
! 67: open my $fh, '-|', $f or die "Unable to fork $f: $!";
! 68: my @patterns = $fh->getlines;
! 69: close $fh;
! 70:
! 71: chomp @patterns;
! 72:
! 73: my %seen;
! 74: return map { qq{"$_"} } grep { !$seen{$_}++ } sort
! 75: map { s/^\p{XDigit}+:\p{XDigit}+\s+//r } @patterns;
! 76: }
! 77:
! 78: __DATA__
! 79: #include <sys/types.h>
! 80: #include <stdio.h>
! 81: #include <dev/pci/pcireg.h>
! 82: #include <dev/pci/pcivar.h>
! 83: #include <dev/pci/pcidevs.h>
! 84: #include <dev/pci/pcidevs_data.h>
! 85:
! 86: struct pci_matchid {
! 87: pci_vendor_id_t pm_vid;
! 88: pci_product_id_t pm_pid;
! 89: };
! 90:
! 91: #include "%type%_devlist.h"
! 92:
! 93: #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
! 94:
! 95: const char *
! 96: pci_findvendor(pci_vendor_id_t vendor)
! 97: {
! 98: const struct pci_known_vendor *kdp;
! 99:
! 100: kdp = pci_known_vendors;
! 101: while (kdp->vendorname != NULL) { /* all have vendor name */
! 102: if (kdp->vendor == vendor)
! 103: break;
! 104: kdp++;
! 105: }
! 106: return (kdp->vendorname);
! 107: }
! 108:
! 109: const char *
! 110: pci_findproduct(pci_vendor_id_t vendor, pci_product_id_t product)
! 111: {
! 112: const struct pci_known_product *pkp;
! 113:
! 114: pkp = pci_known_products;
! 115: while (pkp->productname != NULL) { /* all have product name */
! 116: if (pkp->vendor == vendor && pkp->product == product)
! 117: break;
! 118: pkp++;
! 119: }
! 120: return (pkp->productname);
! 121: }
! 122:
! 123: int
! 124: main(void)
! 125: {
! 126: int i;
! 127: const char *v, *p;
! 128: for (i = 0; i < nitems(%type%_devices); i++) {
! 129: v = pci_findvendor(%type%_devices[i].pm_vid);
! 130: p = pci_findproduct(%type%_devices[i].pm_vid,
! 131: %type%_devices[i].pm_pid);
! 132: printf("%04x:%04x", %type%_devices[i].pm_vid,
! 133: %type%_devices[i].pm_pid);
! 134: printf(" %s %s\n", v ? v : "", p ? p : "");
! 135: }
! 136:
! 137: return 0;
! 138: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>