@@ -18,12 +18,24 @@ product information.
1818The ` pcidb.New() ` function returns a ` pcidb.PCIDB ` struct or an error if the
1919PCI database could not be loaded.
2020
21- > ` pcidb ` 's default behaviour is to first search for pci-ids DB files on the
22- > local host system in well-known filesystem paths. If ` pcidb ` cannot find a
23- > pci-ids DB file on the local host system, you can configure ` pcidb ` to fetch
24- > a current pci-ids DB file from the network. You can enable this
25- > network-fetching behaviour with the ` pcidb.WithEnableNetworkFetch() ` function
26- > or set the ` PCIDB_ENABLE_NETWORK_FETCH ` to a non-0 value.
21+ ``` go
22+ package main
23+
24+ import (
25+ " fmt"
26+
27+ " github.com/jaypipes/pcidb"
28+ )
29+
30+ func main () {
31+ pci , err := pcidb.New ()
32+ if err != nil {
33+ fmt.Printf (" Error getting PCI info: %v " , err)
34+ }
35+ }
36+ ```
37+
38+ > Learn about [ how ` pcidb ` discovers ` pci.ids ` database files] [ #discovery ] .
2739
2840The ` pcidb.PCIDB ` struct contains a number of fields that may be queried for
2941PCI information:
@@ -42,27 +54,6 @@ PCI information:
4254the term "product ID" in ` pcidb ` because it more accurately reflects what the
4355identifier is for: a specific product line produced by the vendor.
4456
45- ### Overriding the root mountpoint ` pcidb ` uses
46-
47- The default root mountpoint that ` pcidb ` uses when looking for information
48- about the host system is ` / ` . So, for example, when looking up known PCI IDS DB
49- files on Linux, ` pcidb ` will attempt to discover a pciids DB file at
50- ` /usr/share/misc/pci.ids ` . If you are calling ` pcidb ` from a system that has an
51- alternate root mountpoint, you can either set the ` PCIDB_CHROOT ` environment
52- variable to that alternate path, or call the ` pcidb.New() ` function with the
53- ` pcidb.WithChroot() ` modifier.
54-
55- For example, if you are executing from within an application container that has
56- bind-mounted the root host filesystem to the mount point ` /host ` , you would set
57- ` PCIDB_CHROOT ` to ` /host ` so that pcidb can find files like
58- ` /usr/share/misc/pci.ids ` at ` /host/usr/share/misc/pci.ids ` .
59-
60- Alternately, you can use the ` pcidb.WithChroot() ` function like so:
61-
62- ``` go
63- pci := pcidb.New (pcidb.WithChroot (" /host" ))
64- ```
65-
6657### PCI device classes
6758
6859Let's take a look at the PCI device class information and how to query the PCI
@@ -178,25 +169,11 @@ package main
178169
179170import (
180171 " fmt"
181- " sort "
172+ " slices "
182173
183174 " github.com/jaypipes/pcidb"
184175)
185176
186- type ByCountProducts []*pcidb.Vendor
187-
188- func (v ByCountProducts ) Len () int {
189- return len (v)
190- }
191-
192- func (v ByCountProducts ) Swap (i , j int ) {
193- v[i], v[j] = v[j], v[i]
194- }
195-
196- func (v ByCountProducts ) Less (i , j int ) bool {
197- return len (v[i].Products ) > len (v[j].Products )
198- }
199-
200177func main () {
201178 pci , err := pcidb.New ()
202179 if err != nil {
@@ -210,7 +187,10 @@ func main() {
210187 x++
211188 }
212189
213- sort.Sort (ByCountProducts (vendors))
190+ slices.SortFunc (vendors, func (a, b *pcidb.Vendor ) int {
191+ return cmp.Compare (len (a.Products ), len (b.Products ))
192+ })
193+ slices.Reverse (vendors)
214194
215195 fmt.Println (" Top 5 vendors by product" )
216196 fmt.Println (" ====================================================" )
@@ -220,16 +200,16 @@ func main() {
220200}
221201```
222202
223- which yields (on my local workstation as of July 7th, 2018 ):
203+ which yields (on my local workstation as of August 23rd, 2025 ):
224204
225205```
226206Top 5 vendors by product
227207====================================================
228- Intel Corporation ('8086') has 3389 products
229- NVIDIA Corporation ('10de') has 1358 products
230- Advanced Micro Devices, Inc. [AMD/ATI] ('1002') has 886 products
231- National Instruments ('1093 ') has 601 products
232- Chelsio Communications Inc ('1425 ') has 525 products
208+ Intel Corporation ('8086') has 4461 products
209+ NVIDIA Corporation ('10de') has 1853 products
210+ Advanced Micro Devices, Inc. [AMD/ATI] ('1002') has 1115 products
211+ Chelsio Communications Inc ('1425 ') has 669 products
212+ National Instruments ('1093 ') has 609 products
233213```
234214
235215The following is an example of querying the PCI product and subsystem
@@ -324,81 +304,144 @@ func main() {
324304}
325305```
326306
327- which yields (on my local workstation as of July 7th, 2018 ):
307+ which yields (on my local workstation as of August 23rd, 2025 ):
328308
329309```
330310Top 2 products by # different subvendors
331311====================================================
332312RTL-8100/8101L/8139 PCI Fast Ethernet Adapter ('8139') from Realtek Semiconductor Co., Ltd.
333313 -> 34 subsystems under the following different vendors:
334- - OVISLINK Corp. ('149c')
335- - EPoX Computer Co., Ltd. ('1695')
336- - Red Hat, Inc ('1af4')
337- - Mitac ('1071')
338- - Netgear ('1385')
339- - Micro-Star International Co., Ltd. [MSI] ('1462')
340- - Hangzhou Silan Microelectronics Co., Ltd. ('1904')
341- - Compex ('11f6')
342- - Edimax Computer Co. ('1432')
343- - KYE Systems Corporation ('1489')
344- - ZyXEL Communications Corporation ('187e')
345- - Acer Incorporated [ALI] ('1025')
314+ - ASUSTeK Computer Inc. ('1043')
346315 - Matsushita Electric Industrial Co., Ltd. ('10f7')
316+ - Compex ('11f6')
317+ - Allied Telesis ('1259')
318+ - Samsung Electronics Co Ltd ('144d')
319+ - Micro-Star International Co., Ltd. [MSI] ('1462')
347320 - Ruby Tech Corp. ('146c')
321+ - ZyXEL Communications Corporation ('187e')
322+ - TTTech Computertechnik AG (Wrong ID) ('0357')
323+ - Accton Technology Corporation ('1113')
324+ - Billionton Systems Inc ('14cb')
348325 - Belkin ('1799')
349- - Allied Telesis ('1259')
350- - Unex Technology Corp. ('1429')
351- - CIS Technology Inc ('1436')
352- - D-Link System Inc ('1186')
353- - Ambicom Inc ('1395')
326+ - Hangzhou Silan Microelectronics Co., Ltd. ('1904')
354327 - AOPEN Inc. ('a0a0')
355- - TTTech Computertechnik AG (Wrong ID) ('0357')
356- - Gigabyte Technology Co., Ltd ('1458')
328+ - Acer Incorporated [ALI] ('1025')
329+ - Surecom Technology ('10bd')
330+ - D-Link System Inc ('1186')
331+ - Hewlett-Packard Company ('103c')
332+ - Mitac ('1071')
333+ - Netgear ('1385')
334+ - Edimax Computer Co. ('1432')
357335 - Packard Bell B.V. ('1631')
358- - Billionton Systems Inc ('14cb')
359- - Kingston Technologies ('2646')
360- - Accton Technology Corporation ('1113')
361- - Samsung Electronics Co Ltd ('144d')
336+ - Gigabyte Technology Co., Ltd ('1458')
337+ - KTI ('8e2e')
338+ - CIS Technology Inc ('1436')
339+ - Red Hat, Inc. ('1af4')
340+ - Kingston Technology Company, Inc. ('2646')
341+ - KYE Systems Corporation ('1489')
342+ - Ambicom Inc ('1395')
343+ - Unex Technology Corp. ('1429')
344+ - OVISLINK Corp. ('149c')
362345 - Biostar Microtech Int'l Corp ('1565')
346+ - EPoX Computer Co., Ltd. ('1695')
363347 - U.S. Robotics ('16ec')
364- - KTI ('8e2e')
365- - Hewlett-Packard Company ('103c')
366- - ASUSTeK Computer Inc. ('1043')
367- - Surecom Technology ('10bd')
368348Bt878 Video Capture ('036e') from Brooktree Corporation
369- -> 30 subsystems under the following different vendors:
370- - iTuner ('aa00')
371- - Nebula Electronics Ltd. ('0071')
372- - DViCO Corporation ('18ac')
373- - iTuner ('aa05')
374- - iTuner ('aa0d')
375- - LeadTek Research Inc. ('107d')
349+ -> 32 subsystems under the following different vendors:
350+ - Hauppauge computer works Inc. ('0070')
351+ - Askey Computer Corp. ('144f')
376352 - Avermedia Technologies Inc ('1461')
377- - Chaintech Computer Co. Ltd ('270f')
378- - iTuner ('aa07')
379- - iTuner ('aa0a')
380- - Microtune, Inc. ('1851')
381- - iTuner ('aa01')
382- - iTuner ('aa04')
383- - iTuner ('aa06')
353+ - iTuner ('aa00')
384354 - iTuner ('aa0f')
385- - iTuner ('aa02')
386- - iTuner ('aa0b')
387- - Pinnacle Systems, Inc. (Wrong ID) ('bd11')
388- - Rockwell International ('127a')
389- - Askey Computer Corp. ('144f')
355+ - Pinnacle Systems Inc. ('11bd')
356+ - Euresys S.A. ('1805')
390357 - Twinhan Technology Co. Ltd ('1822')
391- - Anritsu Corp. ('1852 ')
358+ - iTuner ('aa05 ')
392359 - iTuner ('aa08')
393- - Hauppauge computer works Inc . ('0070 ')
394- - Pinnacle Systems Inc. ('11bd ')
360+ - Nebula Electronics Ltd . ('0071 ')
361+ - Chaintech Computer Co. Ltd ('270f ')
395362 - Conexant Systems, Inc. ('14f1')
396- - iTuner ('aa09 ')
363+ - iTuner ('aa01 ')
397364 - iTuner ('aa03')
365+ - iTuner ('aa0b')
366+ - iTuner ('aa0d')
367+ - Microtune, Inc. ('1851')
368+ - iTuner ('aa02')
369+ - iTuner ('aa06')
370+ - iTuner ('aa09')
371+ - Anritsu Corp. ('1852')
372+ - iTuner ('aa04')
373+ - iTuner ('aa07')
398374 - iTuner ('aa0c')
375+ - Pinnacle Systems, Inc. (Wrong ID) ('bd11')
376+ - Unknown subvendor ('0000')
377+ - Rockwell International ('127a')
378+ - DViCO Corporation ('18ac')
399379 - iTuner ('aa0e')
380+ - LeadTek Research Inc. ('107d')
381+ - iTuner ('aa0a')
400382```
401383
384+ ## Discovery
385+
386+ ` pcidb ` tries its best to automatically discover a ` pci.ids ` database file on
387+ the local host.
388+
389+ ` pcidb ` 's default behaviour is to first search for ` pci.ids ` DB files on the
390+ local host system in well-known filesystem paths (Linux and MacOS):
391+
392+ * ` /usr/share/hwdata/pci.ids `
393+ * ` /usr/share/misc/pci.ids.gz `
394+ * ` /usr/share/hwdata/pci.ids `
395+ * ` /usr/share/misc/pci.ids.gz `
396+
397+ > ** NOTE** : Windows does not have a ` pci.ids ` database file installed by
398+ > default.
399+
400+ You can influence this discovery behaviour with the functions discussed in the
401+ following sections.
402+
403+ ### Overriding the location of the ` pci.ids ` database file
404+
405+ If you have a copy of a ` pci.ids ` database file in a non-standard location or
406+ are working in an environment like Windows that does not have a ` pci.ids `
407+ database file installed by default and do not want ` pcidb ` to fetch an
408+ up-to-date ` pci.ids ` database file over the network, you can tell ` pcidb `
409+ exactly where to find the ` pci.ids ` database using the ` pcidb.WithPath() `
410+ function, like so:
411+
412+ ``` go
413+ pci := pcidb.New (pcidb.WithPath (" /path/to/pci.ids.gz" ))
414+ ```
415+
416+ ### Overriding the root mountpoint ` pcidb ` uses
417+
418+ The default root mountpoint that ` pcidb ` uses when looking for information
419+ about the host system is ` / ` . So, for example, when looking up known ` pci.ids `
420+ database files on Linux, ` pcidb ` will attempt to discover a ` pci.ids ` database
421+ file at ` /usr/share/misc/pci.ids ` . If you are calling ` pcidb ` from a system
422+ that has an alternate root mountpoint, you can either set the ` PCIDB_CHROOT `
423+ environment variable to that alternate path, or call the ` pcidb.New() ` function
424+ with the ` pcidb.WithChroot() ` modifier.
425+
426+ For example, if you are executing from within an application container that has
427+ bind-mounted the root host filesystem to the mount point ` /host ` , you would set
428+ ` PCIDB_CHROOT ` to ` /host ` so that pcidb can find files like
429+ ` /usr/share/misc/pci.ids ` at ` /host/usr/share/misc/pci.ids ` .
430+
431+ Alternately, you can use the ` pcidb.WithChroot() ` function like so:
432+
433+ ``` go
434+ pci := pcidb.New (pcidb.WithChroot (" /host" ))
435+ ```
436+
437+ ### Fetching ` pci.ids ` database file over the network
438+
439+ If ` pcidb ` cannot find a ` pci.ids ` DB file on the local host system, you can
440+ configure ` pcidb ` to fetch a current ` pci.ids ` DB file from the network. You
441+ can enable this network-fetching behaviour with the
442+ ` pcidb.WithEnableNetworkFetch() ` function or set the
443+ ` PCIDB_ENABLE_NETWORK_FETCH ` environs variable to a non-0 value.
444+
402445## Developers
403446
404447Contributions to ` pcidb ` are welcomed! Fork the repo on GitHub and submit a pull
@@ -409,7 +452,6 @@ request or bug report.
409452
410453You can run unit tests easily using the ` make test ` command, like so:
411454
412-
413455```
414456[jaypipes@uberbox pcidb]$ make test
415457go test github.com/jaypipes/pcidb
0 commit comments