[BACK]Return to firmware_patterns.pl CVS log [TXT][DIR] Up to [local] / openbsd / fw_update

Annotation of openbsd/fw_update/firmware_patterns.pl, Revision 1.2

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
1.2     ! afresh1    75:            grep { ! /\s$/ } # ignore items with just a vendor
1.1       afresh1    76:            map { s/^\p{XDigit}+:\p{XDigit}+\s+//r } @patterns;
                     77: }
                     78:
                     79: __DATA__
                     80: #include <sys/types.h>
                     81: #include <stdio.h>
                     82: #include <dev/pci/pcireg.h>
                     83: #include <dev/pci/pcivar.h>
                     84: #include <dev/pci/pcidevs.h>
                     85: #include <dev/pci/pcidevs_data.h>
                     86:
                     87: struct pci_matchid {
                     88:        pci_vendor_id_t         pm_vid;
                     89:        pci_product_id_t        pm_pid;
                     90: };
                     91:
                     92: #include "%type%_devlist.h"
                     93:
                     94: #define nitems(_a)     (sizeof((_a)) / sizeof((_a)[0]))
                     95:
                     96: const char *
                     97: pci_findvendor(pci_vendor_id_t vendor)
                     98: {
                     99:        const struct pci_known_vendor *kdp;
                    100:
                    101:        kdp = pci_known_vendors;
                    102:         while (kdp->vendorname != NULL) {      /* all have vendor name */
                    103:                 if (kdp->vendor == vendor)
                    104:                         break;
                    105:                kdp++;
                    106:        }
                    107:         return (kdp->vendorname);
                    108: }
                    109:
                    110: const char *
                    111: pci_findproduct(pci_vendor_id_t vendor, pci_product_id_t product)
                    112: {
                    113:        const struct pci_known_product *pkp;
                    114:
                    115:        pkp = pci_known_products;
                    116:        while (pkp->productname != NULL) {      /* all have product name */
                    117:                if (pkp->vendor == vendor && pkp->product == product)
                    118:                        break;
                    119:                pkp++;
                    120:        }
                    121:        return (pkp->productname);
                    122: }
                    123:
                    124: int
                    125: main(void)
                    126: {
                    127:        int i;
                    128:        const char *v, *p;
                    129:        for (i = 0; i < nitems(%type%_devices); i++) {
                    130:                v = pci_findvendor(%type%_devices[i].pm_vid);
                    131:                p = pci_findproduct(%type%_devices[i].pm_vid,
                    132:                    %type%_devices[i].pm_pid);
                    133:                printf("%04x:%04x", %type%_devices[i].pm_vid,
                    134:                    %type%_devices[i].pm_pid);
                    135:                printf(" %s %s\n", v ? v : "", p ? p : "");
                    136:        }
                    137:
                    138:        return 0;
                    139: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>