diff --git a/sys/tools/gen_pci_vendors.awk b/sys/tools/gen_pci_vendors.awk new file mode 100755 --- /dev/null +++ b/sys/tools/gen_pci_vendors.awk @@ -0,0 +1,72 @@ +#!/usr/bin/awk -f + +#- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2022 Baptiste Daroussin +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BEGIN { + if (ARGC != 3) { + print "Usage gen_vendors pciidsfile vendorheader" > "/dev/stderr" + exit 1 + } + pci_file=ARGV[1] + header_file=ARGV[2] + while ((getline < header_file) > 0) { + if (NF == 3 && $1 == "#define") + vendors[$2] = $3 + } + while ((getline < pci_file) > 0) { + if ($0 ~ "^[0-9a-f]+") { + id="0x"$1 + $1="" + key=toupper(substr($0, 2)) + gsub(/[ \.\)\(-\/\+\',#]/, "_", key) + gsub(/["\?&]/, "", key) + gsub(/__/, "_", key) + gsub(/\[.+\]/, "", key) + gsub(/\(.+\)/, "", key) + gsub(/_$/, "", key) + if (! vendors[key]) { + vendors[key] = id + } + } + } + guard=header_file + gsub(/\./, "_", guard); + gsub(/\//, "_", guard); + print "/* This file is semi autogenerated, do not manual edit */" > header_file + print "#ifndef _"toupper(guard)"_" > header_file + print "#define _"toupper(guard)"_" > header_file + print ""> header_file + for (i in vendors) { + if (i ~ /^PCI_VENDOR/) { + print "#define "i" "vendors[i] > header_file + } else { + print "#define PCI_VENDOR_"i" "vendors[i] > header_file + } + } + print "#endif" > header_file +}