Text of rust.docs.kernel.org › next › src › kernel › pci › id.rs.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

id.rs - source

Skip to main content kernel/pci/ id.rs 1 // SPDX-License-Identifier: GPL-2.0 2 3 //! PCI device identifiers and related types. 4 //! 5 //! This module contains PCI class codes, Vendor IDs, and supporting types. 6 7 use crate ::{ 8 bindings, 9 fmt , 10 prelude :: * , // 11 }; 12 13 /// PCI device class codes. 14 /// 15 /// Each entry contains the full 24-bit PCI class code (base class in bits 16 /// 23-16, subclass in bits 15-8, programming interface in bits 7-0).

17 /// 18 /// # Examples 19 /// 20 /// ``` 21 /// # use kernel::{device::Core, pci::{self, Class}, prelude::*}; 22 /// fn probe_device(pdev: &pci::Device<Core<'_>>) -> Result { 23 /// let pci_class = pdev.pci_class(); 24 /// dev_info!( 25 /// pdev, 26 /// "Detected PCI class: {}\n", 27 /// pci_class 28 /// ); 29 /// Ok(()) 30 /// } 31 /// ``` 32 #[derive( Clone , Copy , PartialEq , Eq )] 33 #[repr(transparent)] 34 pub struct Class ( u32 ); 35 36 /// PCI class mask constants for matching [`Class`] codes.

37 #[repr(u32)] 38 #[derive( Debug , Clone , Copy , PartialEq , Eq )] 39 pub enum ClassMask { 40 /// Match the full 24-bit class code. 41 Full = 0xffffff , 42 /// Match the upper 16 bits of the class code (base class and subclass only) 43 ClassSubclass = 0xffff00 , 44 } 45 46 macro_rules! define_all_pci_classes { 47 ( 48 $( $variant :ident = $binding :expr,)+ 49 ) => { 50 impl Class { 51 $( 52 #[allow(missing_docs)] 53 pub const $variant : Self = Self ( Self ::to_24bit_class( $binding )); 54 )+ 55 } 56 57 impl fmt::Display for Class { 58 fn fmt( & self , f: &mut fmt::Formatter< '_ >) -> fmt::Result { 59 match self { 60 $( 61 & Self :: $variant => write! (f, stringify! ( $variant )), 62 )+ 63 _ => < Self as fmt::Debug>::fmt( self , f), 64 } 65 } 66 } 67 }; 68 } 69 70 /// Once constructed, a [`Class`] contains a valid PCI class code.

71 impl Class { 72 /// Create a [`Class`] from a raw 24-bit class code. 73 #[inline] 74 pub ( super ) fn from_raw(class_code: u32 ) -> Self { 75 Self ( class_code ) 76 } 77 78 /// Get the raw 24-bit class code value. 79 #[inline] 80 pub const fn as_raw( self ) -> u32 { 81 self . 0 82 } 83 84 // Converts a PCI class constant to 24-bit format. 85 // 86 // Many device drivers use only the upper 16 bits (base class and subclass), 87 // but some use the full 24 bits.

In order to support both cases, store the 88 // class code as a 24-bit value, where 16-bit values are shifted up 8 bits. 89 const fn to_24bit_class(val: u32 ) -> u32 { 90 if val > 0xFFFF { 91 val 92 } else { 93 val << 8 94 } 95 } 96 } 97 98 impl fmt::Debug for Class { 99 fn fmt( & self , f: &mut fmt:: Formatter < '_ >) -> fmt:: Result { 100 write! ( f , "0x{:06x}" , self . 0 ) 101 } 102 } 103 104 impl ClassMask { 105 /// Get the raw mask value.

106 #[inline] 107 pub const fn as_raw( self ) -> u32 { 108 self as u32 109 } 110 } 111 112 impl TryFrom < u32 > for ClassMask { 113 type Error = Error ; 114 115 fn try_from(value: u32 ) -> Result < Self , Self ::Error> { 116 match value { 117 0xffffff => Ok (ClassMask:: Full ), 118 0xffff00 => Ok (ClassMask:: ClassSubclass ), 119 _ => Err ( EINVAL ), 120 } 121 } 122 } 123 124 /// PCI vendor IDs. 125 /// 126 /// Each entry contains the 16-bit PCI vendor ID as assigned by the PCI SIG.

127 #[derive( Clone , Copy , PartialEq , Eq )] 128 #[repr(transparent)] 129 pub struct Vendor ( u16 ); 130 131 macro_rules! define_all_pci_vendors { 132 ( 133 $( $variant :ident = $binding :expr,)+ 134 ) => { 135 impl Vendor { 136 $( 137 #[allow(missing_docs)] 138 pub const $variant : Self = Self ( $binding as u16); 139 )+ 140 } 141 142 impl fmt::Display for Vendor { 143 fn fmt( & self , f: &mut fmt::Formatter< '_ >) -> fmt::Result { 144 match self { 145 $( 146 & Self :: $variant => write! (f, stringify! ( $variant )), 147 )+ 148 _ => < Self as fmt::Debug>::fmt( self , f), 149 } 150 } 151 } 152 }; 153 } 154 155 /// Once constructed, a `Vendor` contains a valid PCI Vendor ID.

156 impl Vendor { 157 /// Create a Vendor from a raw 16-bit vendor ID. 158 #[inline] 159 pub ( super ) fn from_raw(vendor_id: u16 ) -> Self { 160 Self ( vendor_id ) 161 } 162 163 /// Get the raw 16-bit vendor ID value. 164 #[inline] 165 pub const fn as_raw( self ) -> u16 { 166 self . 0 167 } 168 } 169 170 impl fmt::Debug for Vendor { 171 #[inline] 172 fn fmt( & self , f: &mut fmt:: Formatter < '_ >) -> fmt:: Result { 173 write! ( f , "0x{:04x}" , self .

0 ) 174 } 175 } 176 177 define_all_pci_classes! { 178 NOT_DEFINED = bindings::PCI_CLASS_NOT_DEFINED, // 0x000000 179 NOT_DEFINED_VGA = bindings::PCI_CLASS_NOT_DEFINED_VGA, // 0x000100 180 181 STORAGE_SCSI = bindings::PCI_CLASS_STORAGE_SCSI, // 0x010000 182 STORAGE_IDE = bindings::PCI_CLASS_STORAGE_IDE, // 0x010100 183 STORAGE_FLOPPY = bindings::PCI_CLASS_STORAGE_FLOPPY, // 0x010200 184 STORAGE_IPI = bindings::PCI_CLASS_STORAGE_IPI, // 0x010300 185 STORAGE_RAID = bindings::PCI_CLASS_STORAGE_RAID, // 0x010400 186 STORAGE_SATA = bindings::PCI_CLASS_STORAGE_SATA, // 0x010600 187 STORAGE_SATA_AHCI = bindings::PCI_CLASS_STORAGE_SATA_AHCI, // 0x010601 188 STORAGE_SAS = bindings::PCI_CLASS_STORAGE_SAS, // 0x010700 189 STORAGE_EXPRESS = bindings::PCI_CLASS_STORAGE_EXPRESS, // 0x010802 190 STORAGE_OTHER = bindings::PCI_CLASS_STORAGE_OTHER, // 0x018000 191 192 NETWORK_ETHERNET = bindings::PCI_CLASS_NETWORK_ETHERNET, // 0x020000 193 NETWORK_TOKEN_RING = bindings::PCI_CLASS_NETWORK_TOKEN_RING, // 0x020100 194 NETWORK_FDDI = bindings::PCI_CLASS_NETWORK_FDDI, // 0x020200 195 NETWORK_ATM = bindings::PCI_CLASS_NETWORK_ATM, // 0x020300 196 NETWORK_OTHER = bindings::PCI_CLASS_NETWORK_OTHER, // 0x028000 197 198 DISPLAY_VGA = bindings::PCI_CLASS_DISPLAY_VGA, // 0x030000 199 DISPLAY_XGA = bindings::PCI_CLASS_DISPLAY_XGA, // 0x030100 200 DISPLAY_3D = bindings::PCI_CLASS_DISPLAY_3D, // 0x030200 201 DISPLAY_OTHER = bindings::PCI_CLASS_DISPLAY_OTHER, // 0x038000 202 203 MULTIMEDIA_VIDEO = bindings::PCI_CLASS_MULTIMEDIA_VIDEO, // 0x040000 204 MULTIMEDIA_AUDIO = bindings::PCI_CLASS_MULTIMEDIA_AUDIO, // 0x040100 205 MULTIMEDIA_PHONE = bindings::PCI_CLASS_MULTIMEDIA_PHONE, // 0x040200 206 MULTIMEDIA_HD_AUDIO = bindings::PCI_CLASS_MULTIMEDIA_HD_AUDIO, // 0x040300 207 MULTIMEDIA_OTHER = bindings::PCI_CLASS_MULTIMEDIA_OTHER, // 0x048000 208 209 MEMORY_RAM = bindings::PCI_CLASS_MEMORY_RAM, // 0x050000 210 MEMORY_FLASH = bindings::PCI_CLASS_MEMORY_FLASH, // 0x050100 211 MEMORY_CXL = bindings::PCI_CLASS_MEMORY_CXL, // 0x050200 212 MEMORY_OTHER = bindings::PCI_CLASS_MEMORY_OTHER, // 0x058000 213 214 BRIDGE_HOST = bindings::PCI_CLASS_BRIDGE_HOST, // 0x060000 215 BRIDGE_ISA = bindings::PCI_CLASS_BRIDGE_ISA, // 0x060100 216 BRIDGE_EISA = bindings::PCI_CLASS_BRIDGE_EISA, // 0x060200 217 BRIDGE_MC = bindings::PCI_CLASS_BRIDGE_MC, // 0x060300 218 BRIDGE_PCI_NORMAL = bindings::PCI_CLASS_BRIDGE_PCI_NORMAL, // 0x060400 219 BRIDGE_PCI_SUBTRACTIVE = bindings::PCI_CLASS_BRIDGE_PCI_SUBTRACTIVE, // 0x060401 220 BRIDGE_PCMCIA = bindings::PCI_CLASS_BRIDGE_PCMCIA, // 0x060500 221 BRIDGE_NUBUS = bindings::PCI_CLASS_BRIDGE_NUBUS, // 0x060600 222 BRIDGE_CARDBUS = bindings::PCI_CLASS_BRIDGE_CARDBUS, // 0x060700 223 BRIDGE_RACEWAY = bindings::PCI_CLASS_BRIDGE_RACEWAY, // 0x060800 224 BRIDGE_OTHER = bindings::PCI_CLASS_BRIDGE_OTHER, // 0x068000 225 226 COMMUNICATION_SERIAL = bindings::PCI_CLASS_COMMUNICATION_SERIAL, // 0x070000 227 COMMUNICATION_PARALLEL = bindings::PCI_CLASS_COMMUNICATION_PARALLEL, // 0x070100 228 COMMUNICATION_MULTISERIAL = bindings::PCI_CLASS_COMMUNICATION_MULTISERIAL, // 0x070200 229 COMMUNICATION_MODEM = bindings::PCI_CLASS_COMMUNICATION_MODEM, // 0x070300 230 COMMUNICATION_OTHER = bindings::PCI_CLASS_COMMUNICATION_OTHER, // 0x078000 231 232 SYSTEM_PIC = bindings::PCI_CLASS_SYSTEM_PIC, // 0x080000 233 SYSTEM_PIC_IOAPIC = bindings::PCI_CLASS_SYSTEM_PIC_IOAPIC, // 0x080010 234 SYSTEM_PIC_IOXAPIC = bindings::PCI_CLASS_SYSTEM_PIC_IOXAPIC, // 0x080020 235 SYSTEM_DMA = bindings::PCI_CLASS_SYSTEM_DMA, // 0x080100 236 SYSTEM_TIMER = bindings::PCI_CLASS_SYSTEM_TIMER, // 0x080200 237 SYSTEM_RTC = bindings::PCI_CLA

The rest of this page is on the live site.