From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id APEDH4gibGO2DgEAbAwnHQ (envelope-from ) for ; Wed, 09 Nov 2022 22:58:32 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id iPw0HogibGPATwEAG6o9tA (envelope-from ) for ; Wed, 09 Nov 2022 22:58:32 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2CBAA2E69F for ; Wed, 9 Nov 2022 22:58:28 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ost5E-0006Bs-7W; Wed, 09 Nov 2022 16:58:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ost5A-0006A1-O0 for guix-patches@gnu.org; Wed, 09 Nov 2022 16:58:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ost5A-0004UL-Ft for guix-patches@gnu.org; Wed, 09 Nov 2022 16:58:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ost5A-0003jj-B9 for guix-patches@gnu.org; Wed, 09 Nov 2022 16:58:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#59003] [PATCH v2 3/6] linux-modules: Add 'load-pci-device-database'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 09 Nov 2022 21:58:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59003 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 59003@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 59003-submit@debbugs.gnu.org id=B59003.166803103414253 (code B ref 59003); Wed, 09 Nov 2022 21:58:04 +0000 Received: (at 59003) by debbugs.gnu.org; 9 Nov 2022 21:57:14 +0000 Received: from localhost ([127.0.0.1]:41200 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ost4M-0003hk-6O for submit@debbugs.gnu.org; Wed, 09 Nov 2022 16:57:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ost4G-0003gM-5G for 59003@debbugs.gnu.org; Wed, 09 Nov 2022 16:57:09 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ost48-00018c-1d; Wed, 09 Nov 2022 16:57:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=7Aed3jnUd50+ZQc08YclTlx5MAYdpPY3hhZfxXuM9bw=; b=hV0pJQED0eWpWbHQG/mY lij4m9WmI+jXrP4UAlDomXjrb1imaygNmX1S3RDjggZhgv8KqtVSee1DKs8NSSlifB3pmPmHRxV0g gtK6R5m1503/1zZMm2VxsfgFaNyvsY5mAvGKiUw7LkbB15ROIMQR1pMsRs8uwGigKxUM15nuSGm5r L4S2gQc4xQby1xXlnet4cGiRkUQom0qnH5mynflJ2u+Hpvss7NZ2KsMfYC80lOAir5DQLWNNjRSHM b28mBHlfzTZr4Tt00H4gFwxIYVMUhUauwcK2rVwC1X01zV2jVQGSt5E+eNRR6zufuO6EMiR5tDcyW N/aEPCeO/ei3cQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ost47-0000ES-Ak; Wed, 09 Nov 2022 16:56:59 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 9 Nov 2022 22:56:34 +0100 Message-Id: <20221109215637.22445-4-ludo@gnu.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221109215637.22445-1-ludo@gnu.org> References: <20221103191756.16265-1-ludo@gnu.org> <20221109215637.22445-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1668031108; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=7Aed3jnUd50+ZQc08YclTlx5MAYdpPY3hhZfxXuM9bw=; b=LUV0BKLvcXl3PDnJOC2Y3B99chWgfSISsiMIjzvRG17q/T4PRmRZ78xmEJd2Bn3jV32JoD gNPJVeCUq0KtiRoLQAFATqKrmPWEt2CnwGEZkuRTfW+gSKNMAvbzqXV/tQDeXyJYfq7Jpn 0AGnEETntBUG8TxDzvFBg6SmZGGDyXavfME7ekZqdFkn5rebl4KaBLvQ2s2GrROsy1z9QL NBCT1c2Ke2JWNmTfyKbUnWgPTcyuWcQt56+6LMIyveK2A3b3CeABvYPRxqXsvnIMKIksbd GhiPhqBMbGX2DKni4k++R3hSpq05Oz7FOUlaD4Vi10gMAa/Q4h9LF0ZgTdNXkw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1668031108; a=rsa-sha256; cv=none; b=AXhTim9z/26ZWKRlmtNUta1ZM/G3iF1tP+NnK0V+KB/hE4aA9aP38otBaUSy+M+jRgQyvP 6CQ0i+mXprXTd8vTNkKdqhjGjR4jf6fbCa+tHHKFJvuGNqY+CyktA8bDIrijAzem7MmZjU 9MvST9bkJlG0hjjJhCZ6O/+d6JeqAHvfxMz3PvNdYAmr22AcQdb6kEhJYex+PyOX4hmEZM 9BYDSAQAcIvK6PfjsuQIiFC5bcqeCji7Up9J8hVjtlvY/wu8HxdV9YlouZPGgKY+7OtbOq ffjI79v9VX4mifZ6HkxJ9uGzFBDc54wiCp3AhNx6AtjCA+2ZPOPiNJZeqVLcRA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=hV0pJQED; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.42 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=hV0pJQED; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 2CBAA2E69F X-Spam-Score: -2.42 X-Migadu-Scanner: scn1.migadu.com X-TUID: Qt5VGo9XpHeA * gnu/build/linux-modules.scm (read-pci-device-database) (load-pci-device-database): New procedures. --- gnu/build/linux-modules.scm | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 09cf752bef..3b1f512663 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -60,6 +60,7 @@ (define-module (gnu build linux-modules) storage-pci-device? network-pci-device? display-pci-device? + load-pci-device-database current-module-debugging-port @@ -488,6 +489,79 @@ (define class (find-files "/sys/bus/pci/devices" #:stat lstat))) +(define (read-pci-device-database port) + "Parse the 'pci.ids' database that ships with the pciutils package and is +maintained at ." + (define (comment? str) + (string-prefix? "#" (string-trim str))) + (define (blank? str) + (string-null? (string-trim-both str))) + (define (device? str) + (eqv? #\tab (string-ref str 0))) + (define (subvendor? str) + (string-prefix? "\t\t" str)) + (define (class? str) + (string-prefix? "C " str)) + (define (parse-id-line str) + (let* ((str (string-trim-both str)) + (space (string-index str char-set:whitespace))) + (values (string->number (string-take str space) 16) + (string-trim (string-drop str (+ 1 space)))))) + (define (finish vendor vendor-id devices table) + (fold (lambda (device table) + (match device + ((device-id . name) + (vhash-consv (logior (ash vendor-id 16) device-id) + (cons vendor name) + table)))) + table + devices)) + + (let loop ((table vlist-null) + (vendor-id #f) + (vendor #f) + (devices '())) + (match (read-line port) + ((? eof-object?) + (let ((table (if (and vendor vendor-id) + (finish vendor vendor-id devices table) + table))) + (lambda (vendor device) + (match (vhash-assv (logior (ash vendor 16) device) table) + (#f + (values #f #f)) + ((_ . (vendor . name)) + (values vendor name)))))) + ((? comment?) + (loop table vendor-id vendor devices)) + ((? blank?) + (loop table vendor-id vendor devices)) + ((? subvendor?) ;currently ignored + (loop table vendor-id vendor devices)) + ((? class?) ;currently ignored + (loop table vendor-id vendor devices)) + ((? device? line) + (let-values (((id name) (parse-id-line line))) + (loop table vendor-id vendor + (if (and vendor-id vendor) ;class or device? + (alist-cons id name devices) + devices)))) + (line + (let ((table (if (and vendor vendor-id) + (finish vendor vendor-id devices table) + table))) + (let-values (((vendor-id vendor) (parse-id-line line))) + (loop table vendor-id vendor '()))))))) + +(define (load-pci-device-database file) + "Read the 'pci.ids' database at FILE (get it from the pciutils package or +from ) and return a lookup procedure that takes a PCI +vendor ID and a device ID (two integers) and returns the vendor name and +device name as two values." + (let ((port (open-file file "r0"))) + (call-with-gzip-input-port port + read-pci-device-database))) + (define (device-module-aliases device) "Return the list of module aliases required by DEVICE, a /dev file name, as in this example: -- 2.38.0