From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iKhHMssUZGPvRgAAbAwnHQ (envelope-from ) for ; Thu, 03 Nov 2022 20:21:47 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id WFkXMssUZGNg/AAAauVa8A (envelope-from ) for ; Thu, 03 Nov 2022 20:21:47 +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 70AA125EAC for ; Thu, 3 Nov 2022 20:21:47 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqflx-0004zi-Cx; Thu, 03 Nov 2022 15:21:05 -0400 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 1oqflw-0004yG-61 for guix-patches@gnu.org; Thu, 03 Nov 2022 15:21:04 -0400 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 1oqflv-0004mM-TK for guix-patches@gnu.org; Thu, 03 Nov 2022 15:21:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oqflv-0004pe-NI for guix-patches@gnu.org; Thu, 03 Nov 2022 15:21:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#59003] [PATCH 3/7] 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: Thu, 03 Nov 2022 19:21:03 +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.166750320418427 (code B ref 59003); Thu, 03 Nov 2022 19:21:03 +0000 Received: (at 59003) by debbugs.gnu.org; 3 Nov 2022 19:20:04 +0000 Received: from localhost ([127.0.0.1]:50769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqfky-0004n1-5J for submit@debbugs.gnu.org; Thu, 03 Nov 2022 15:20:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oqfkn-0004lG-Vt for 59003@debbugs.gnu.org; Thu, 03 Nov 2022 15:19:54 -0400 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 1oqfki-0004Tu-Ob; Thu, 03 Nov 2022 15:19:48 -0400 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=dVRbj8Afrzs/2t27ReW+ NnOywiRjLmvwgZRWCK4N18Yx5PqhLqE5xU97+OM5BAiV+EQLmw8JdyIUNeFnAdpMVd4QbE2Szvmzk y4WS3IxtC5WQb1gNA8wlreXGRLTfGs+j1W/z8f81JTgLRklED0UcxZ+C9NdiYldicMguMJseNIaSt gd6btx91yW2o01oTSDk8lczFeKDITDuUXKs2oZAK1UE9vSc1YCz6ct9N65AP4XIn8kdUl8vWT7DuY WHpxlhX+VUEXowh/18nVn2ayaWpGxItpz1bAHd7IvA/8S5pHBz5HONj4kVKU/VpqfFTgQTxKHf0L9 w0m5JnqUP/9gsQ==; 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 1oqfki-0001MS-Bg; Thu, 03 Nov 2022 15:19:48 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 3 Nov 2022 20:19:31 +0100 Message-Id: <20221103191935.16336-3-ludo@gnu.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221103191935.16336-1-ludo@gnu.org> References: <20221103191935.16336-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: , Sender: "Guix-patches" Errors-To: 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=1667503307; 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=EOYrgssIYJyR8mzkm4i2HalQ2u1it9U1dD0wJgfRtvB8ma/50OhA3K7KAE8KmylkS5PPhC B9v0J6/mQf2zo1kB0uXNv/YxxXilOG31lQ9b951PrjDZzxiyLRaiZrtho6EIHVtwe5P7aM M95GFbPGwEfpj8sYxT4ytBzQ5iYaA7Mrwp9+AffA9OMsbOMcVM7zwdf67qNm7EILoV4fpW eA0eveixftPuF11nF8n9wUs0jg8X4aj91n1gVwlT8n2jcBZUZ4oYX8fnDC78I5fzuMwq6e jZhGqjxkx4x9zlZIQraHyDDm55XS2+hgAu/k9XVhlspDaqmd4IkHXnbrm4PJ+Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667503307; a=rsa-sha256; cv=none; b=B8i6MI9xxst6Ce/X1cvZl1mlj4a7T4WMoMiVVD6aneMPC+B2rrhzmkIrg4MVqEjBq53/Z1 3m47E3eDEEVfJ3mntSfpWJaMfOHDuRLNynZqN36WE85YBAKyt6FxMZRT2x76LcRzBNUS/z i46CpCYSgC9aoKPuSEkVBEEcJI5c4XgdgqsgHRP6BjiqUYFI2B//kByWeNdQNRyXYe4C1k SaBprw39sjHl0PjC3eb8HTyE0/A6eU8Hmw9muzHjgjNuLvQBIYHDQtpoho75/gRQ4WaeCZ PsBoOiMXoB9yKFlGyu8tQhEiyQzBvx8ieFCelrU8SpVfgPv/osxhlMdhB/q3Pg== 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=dVRbj8Af; 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: -1.99 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=dVRbj8Af; 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: 70AA125EAC X-Spam-Score: -1.99 X-Migadu-Scanner: scn0.migadu.com X-TUID: /hop9r5FztNo * 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