[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/13: linux-modules: Add 'load-pci-device-database'.
From: |
guix-commits |
Subject: |
03/13: linux-modules: Add 'load-pci-device-database'. |
Date: |
Tue, 15 Nov 2022 06:19:51 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit afbd4d8470ad2e0b3bd5dd84b983bb343b4451f9
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Nov 3 14:37:45 2022 +0100
linux-modules: Add 'load-pci-device-database'.
* 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 @@
storage-pci-device?
network-pci-device?
display-pci-device?
+ load-pci-device-database
current-module-debugging-port
@@ -488,6 +489,79 @@ key such as 'MAJOR or 'DEVTYPE and each cdr is the
corresponding value."
(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 <https://pci-ids.ucw.cz/>."
+ (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 <https://pci-ids.ucw.cz/>) 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:
- branch master updated (de61a0aa4a -> 5b555d639d), guix-commits, 2022/11/15
- 01/13: installer: Warn about hardware support after the welcome page., guix-commits, 2022/11/15
- 03/13: linux-modules: Add 'load-pci-device-database'.,
guix-commits <=
- 02/13: linux-modules: Add support for listing PCI devices., guix-commits, 2022/11/15
- 07/13: installer: Migrate to 'guile-gnutls'., guix-commits, 2022/11/15
- 08/13: gnu: Add safeint., guix-commits, 2022/11/15
- 10/13: doc: Refer to the pt_BR translation., guix-commits, 2022/11/15
- 04/13: installer: Use 'current-guix' for extensions., guix-commits, 2022/11/15
- 09/13: gnu: Add fuzzel., guix-commits, 2022/11/15
- 11/13: doc: Build pt_BR manual., guix-commits, 2022/11/15
- 12/13: doc: Link to the Git book instead of the git-scm.com homepage., guix-commits, 2022/11/15
- 13/13: doc: Add missing closing parentheses in examples., guix-commits, 2022/11/15
- 05/13: installer: Error page width is parameterized., guix-commits, 2022/11/15