From: Erik van der Kouwe Date: Fri, 9 Oct 2009 10:48:46 +0000 (+0000) Subject: Add lspci command and SI_PCI_INFO getsysinfo call X-Git-Tag: v3.1.5~19 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=cb6dbfca2c21c1c29d44fb68c47395548106756a;p=minix.git Add lspci command and SI_PCI_INFO getsysinfo call --- diff --git a/commands/simple/Makefile b/commands/simple/Makefile index b40e199ea..9bd5d71f4 100755 --- a/commands/simple/Makefile +++ b/commands/simple/Makefile @@ -119,6 +119,7 @@ ALL = \ lp \ lpd \ ls \ + lspci \ mail \ man \ mesg \ @@ -532,6 +533,10 @@ ls: ls.c $(CCLD) -o $@ $< @install -S 20kw $@ +lspci: lspci.c + $(CCLD) -o $@ $< + @install -S 4kw $@ + mail: mail.c $(CCLD) -o $@ $< @install -S 4kw $@ @@ -1012,6 +1017,7 @@ install: \ /usr/bin/lpd \ /usr/bin/ls \ /bin/ls \ + /usr/bin/lspci \ /usr/bin/mail \ /usr/bin/man \ /usr/bin/mesg \ @@ -1404,6 +1410,9 @@ install: \ /bin/ls: ls install -cs -o bin $< $@ +/usr/bin/lspci: lspci + install -cs -o bin $< $@ + /usr/bin/mail: mail install -cs -o root -m 4755 $< $@ diff --git a/commands/simple/lspci.c b/commands/simple/lspci.c new file mode 100644 index 000000000..ae9db7554 --- /dev/null +++ b/commands/simple/lspci.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009, Erik van der Kouwe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +int main(int argc, char **argv) +{ + struct pciinfo_entry *entry; + struct pciinfo pciinfo; + + /* obtain a list of PCI devices from PM */ + if (getsysinfo(PM_PROC_NR, SI_PCI_INFO, &pciinfo) < 0) + { + perror("getsysinfo failed"); + return -1; + } + + /* print the list of devices */ + entry = pciinfo.pi_entries; + while (pciinfo.pi_count-- > 0) + { + printf("%.4X:%.4X %s\n", entry->pie_vid, entry->pie_did, entry->pie_name); + entry++; + } + + return 0; +} diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 183f3c2ca..d20083d5b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -33,9 +33,6 @@ Created: Jan 2000 by Philip Homburg #include #include -#define NR_PCIBUS 40 -#define NR_PCIDEV 50 - #define PBT_INTEL_HOST 1 #define PBT_PCIBRIDGE 2 #define PBT_CARDBUS 3 diff --git a/include/minix/config.h b/include/minix/config.h index 1b2d991b7..3eed5950d 100755 --- a/include/minix/config.h +++ b/include/minix/config.h @@ -95,4 +95,8 @@ #define SPROFILE 1 /* statistical profiling */ #define CPROFILE 0 /* call profiling */ +/* PCI configuration parameters */ +#define NR_PCIBUS 40 +#define NR_PCIDEV 50 + #endif /* _CONFIG_H */ diff --git a/include/minix/type.h b/include/minix/type.h index b14a98f13..a794a2243 100755 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -193,5 +193,20 @@ struct k_randomness { } bin[RANDOM_SOURCES]; }; +/* information on PCI devices */ + +#define PCIINFO_ENTRY_SIZE 80 + +struct pciinfo_entry { + u16_t pie_vid; + u16_t pie_did; + char pie_name[PCIINFO_ENTRY_SIZE]; +}; + +struct pciinfo { + size_t pi_count; + struct pciinfo_entry pi_entries[NR_PCIDEV]; +}; + #endif /* _TYPE_H */ diff --git a/include/unistd.h b/include/unistd.h index be3fe47ca..ad46bc0b2 100755 --- a/include/unistd.h +++ b/include/unistd.h @@ -48,6 +48,7 @@ #define SI_LOADINFO 6 /* get copy of load average structure */ #define SI_KPROC_TAB 7 /* copy of kernel process table */ #define SI_CALL_STATS 8 /* system call statistics */ +#define SI_PCI_INFO 9 /* get kernel info via PM */ /* NULL must be defined in according to POSIX Sec. 2.7.1. */ #define NULL ((void *)0) diff --git a/lib/syslib/pci_dev_name.c b/lib/syslib/pci_dev_name.c index cd21f87d9..3469205eb 100644 --- a/lib/syslib/pci_dev_name.c +++ b/lib/syslib/pci_dev_name.c @@ -13,7 +13,7 @@ PUBLIC char *pci_dev_name(vid, did) u16_t vid; u16_t did; { - static char name[80]; /* We need a better interface for this */ + static char name[PCIINFO_ENTRY_SIZE]; /* We need a better interface for this */ int r; cp_grant_id_t gid; @@ -41,7 +41,9 @@ u16_t did; if (m.m_type == ENOENT) { +#if DEBUG printf("pci_dev_name: got no name\n"); +#endif return NULL; /* No name for this device */ } if (m.m_type != 0) diff --git a/man/man1/lspci.1 b/man/man1/lspci.1 new file mode 100644 index 000000000..b4631e944 --- /dev/null +++ b/man/man1/lspci.1 @@ -0,0 +1,15 @@ +.TH LSPCI 1 +.SH NAME +lspci \- print table of PCI devices +.SH SYNOPSIS +\fBlspci\fP +.SH DESCRIPTION +The +.B lspci +utility prints a list of devices detected on the PCI bus to the standard output. +Each row specifies the vendor ID, device ID and device name according to the +MINIX PCI table. The vendor ID and device ID are printed in hexadecimal. +Wherever the name is missing, MINIX does not recognize the PCI device. +.SH AUTHOR +This manual page and the utility were written by Erik van der Kouwe +. diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 98f9cc42e..699c0d7dd 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "mproc.h" #include "param.h" #include "../../kernel/proc.h" @@ -62,6 +63,8 @@ PRIVATE char *uts_tbl[] = { PUBLIC unsigned long calls_stats[NCALLS]; #endif +FORWARD _PROTOTYPE( int getpciinfo, (struct pciinfo *pciinfo) ); + /*===========================================================================* * do_allocmem * *===========================================================================*/ @@ -201,6 +204,7 @@ PUBLIC int do_getsysinfo() vir_bytes src_addr, dst_addr; struct kinfo kinfo; struct loadinfo loadinfo; + struct pciinfo pciinfo; static struct proc proctab[NR_PROCS+NR_TASKS]; size_t len; int s, r; @@ -240,6 +244,12 @@ PUBLIC int do_getsysinfo() src_addr = (vir_bytes) &loadinfo; len = sizeof(struct loadinfo); break; + case SI_PCI_INFO: /* PCI info is obtained via PM */ + if ((r=getpciinfo(&pciinfo)) != OK) + return r; + src_addr = (vir_bytes) &pciinfo; + len = sizeof(struct pciinfo); + break; #if ENABLE_SYSCALL_STATS case SI_CALL_STATS: src_addr = (vir_bytes) calls_stats; @@ -593,3 +603,44 @@ char *brk_addr; return 0; } +/*===========================================================================* + * getpciinfo * + *===========================================================================*/ + +PRIVATE int getpciinfo(pciinfo) +struct pciinfo *pciinfo; +{ + int devind, r; + struct pciinfo_entry *entry; + char *name; + u16_t vid, did; + + /* look up PCI process number */ + pci_init(); + + /* start enumerating devices */ + entry = pciinfo->pi_entries; + r = pci_first_dev(&devind, &vid, &did); + while (r) + { + /* fetch device name */ + name = pci_dev_name(vid, did); + if (!name) + name = ""; + + /* store device information in table */ + assert((char *) entry < (char *) (pciinfo + 1)); + entry->pie_vid = vid; + entry->pie_did = did; + strncpy(entry->pie_name, name, sizeof(entry->pie_name)); + entry->pie_name[sizeof(entry->pie_name) - 1] = 0; + entry++; + + /* continue with the next device */ + r = pci_next_dev(&devind, &vid, &did); + } + + /* store number of entries */ + pciinfo->pi_count = entry - pciinfo->pi_entries; + return OK; +}