lp \
lpd \
ls \
+ lspci \
mail \
man \
mesg \
$(CCLD) -o $@ $<
@install -S 20kw $@
+lspci: lspci.c
+ $(CCLD) -o $@ $<
+ @install -S 4kw $@
+
mail: mail.c
$(CCLD) -o $@ $<
@install -S 4kw $@
/usr/bin/lpd \
/usr/bin/ls \
/bin/ls \
+ /usr/bin/lspci \
/usr/bin/mail \
/usr/bin/man \
/usr/bin/mesg \
/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 $< $@
--- /dev/null
+/*
+ * 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 <minix/com.h>
+#include <stdio.h>
+#include <unistd.h>
+
+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;
+}
#include <string.h>
#include <minix/sysutil.h>
-#define NR_PCIBUS 40
-#define NR_PCIDEV 50
-
#define PBT_INTEL_HOST 1
#define PBT_PCIBRIDGE 2
#define PBT_CARDBUS 3
#define SPROFILE 1 /* statistical profiling */
#define CPROFILE 0 /* call profiling */
+/* PCI configuration parameters */
+#define NR_PCIBUS 40
+#define NR_PCIDEV 50
+
#endif /* _CONFIG_H */
} 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 */
#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 <unistd.h> according to POSIX Sec. 2.7.1. */
#define NULL ((void *)0)
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;
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)
--- /dev/null
+.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
+<vdkouwe@cs.vu.nl>.
#include <archconst.h>
#include <archtypes.h>
#include <lib.h>
+#include <assert.h>
#include "mproc.h"
#include "param.h"
#include "../../kernel/proc.h"
PUBLIC unsigned long calls_stats[NCALLS];
#endif
+FORWARD _PROTOTYPE( int getpciinfo, (struct pciinfo *pciinfo) );
+
/*===========================================================================*
* do_allocmem *
*===========================================================================*/
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;
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;
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;
+}