From 14d6c0a377eff7ac4f488a640249a25703725cac Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 21 Apr 2000 11:58:00 +0000 Subject: [PATCH] Merged in AIX port. --- Makefile | 26 ++++++++++++++++++-------- lib/Makefile | 7 ++++++- lib/access.c | 7 ++++++- lib/configure | 43 ++++++++++++++++++++++++++++++++----------- lib/generic.c | 6 +++--- lib/internal.h | 10 ++++++++-- lib/pci.h | 17 ++++++++++++++--- lib/proc.c | 6 +++--- lspci.c | 17 +++++++++++++++-- pciutils.h | 7 ++++++- 10 files changed, 111 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 5a9b117..045acae 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.32 2000/04/17 15:59:16 mj Exp $ +# $Id: Makefile,v 1.33 2000/04/21 11:58:00 mj Exp $ # Makefile for Linux PCI Utilities # (c) 1998--2000 Martin Mares @@ -6,18 +6,28 @@ OPT=-O2 -fomit-frame-pointer #OPT=-O2 -g CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Werror -VERSION=2.1.6 +VERSION=2.1.7 SUFFIX= #SUFFIX=-alpha -DATE=2000-04-17 +DATE=2000-04-21 +INSTALL=install +DIRINSTALL=install -d ifeq ($(shell uname),FreeBSD) ROOT=/usr/local PREFIX=/usr/local else +ifeq ($(shell uname),AIX) +ROOT=/usr/local +PREFIX=/usr/local +CFLAGS=-g +INSTALL=installbsd +DIRINSTALL=mkdir -p +else ROOT=/ PREFIX=/usr endif +endif MANDIR=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi) export @@ -41,16 +51,16 @@ common.o: common.c pciutils.h lib/libpci.a M=`echo $(DATE) | sed 's/-01-/-January-/;s/-02-/-February-/;s/-03-/-March-/;s/-04-/-April-/;s/-05-/-May-/;s/-06-/-June-/;s/-07-/-July-/;s/-08-/-August-/;s/-09-/-September-/;s/-10-/-October-/;s/-11-/-November-/;s/-12-/-December-/;s/\(.*\)-\(.*\)-\(.*\)/\3 \2 \1/'` ; sed <$< >$@ "s/@TODAY@/$$M/;s/@VERSION@/pciutils-$(VERSION)$(SUFFIX)/" clean: - rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core` + rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core` rm -f lspci setpci lib/config.* *.8 rm -rf dist install: all # -c is ignored on Linux, but required on FreeBSD - install -d -m 755 $(ROOT)/sbin $(PREFIX)/share $(MANDIR)/man8 - install -c -m 755 -s lspci setpci $(ROOT)/sbin - install -c -m 644 pci.ids $(PREFIX)/share - install -c -m 644 lspci.8 setpci.8 $(MANDIR)/man8 + $(DIRINSTALL) -m 755 $(ROOT)/sbin $(PREFIX)/share $(MANDIR)/man8 + $(INSTALL) -c -m 755 -s lspci setpci $(ROOT)/sbin + $(INSTALL) -c -m 644 pci.ids $(PREFIX)/share + $(INSTALL) -c -m 644 lspci.8 setpci.8 $(MANDIR)/man8 # Remove relics from old versions rm -f $(ROOT)/etc/pci.ids diff --git a/lib/Makefile b/lib/Makefile index 5c6c586..808b7d7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 1999/07/20 14:01:27 mj Exp $ +# $Id: Makefile,v 1.4 2000/04/21 11:58:00 mj Exp $ # Makefile for The PCI Library # (c) 1999 Martin Mares @@ -28,6 +28,10 @@ OBJS += fbsd-device.o CFLAGS += -I/usr/src/sys endif +ifdef HAVE_PM_AIX_DEVICE +OBJS += aix-device.o +endif + ifdef HAVE_OWN_HEADER_H INCL += header.h endif @@ -45,6 +49,7 @@ proc.o: proc.c $(INCL) generic.o: generic.c $(INCL) syscalls.o: syscalls.c $(INCL) fbsd-device.o: fbsd-device.c $(INCL) +aix-device.o: aix-device.c $(INCL) dump.o: dump.c $(INCL) names.o: names.c $(INCL) filter.o: filter.c $(INCL) diff --git a/lib/access.c b/lib/access.c index 697f938..b80969e 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,5 +1,5 @@ /* - * $Id: access.c,v 1.6 2000/01/13 22:44:24 mj Exp $ + * $Id: access.c,v 1.7 2000/04/21 11:58:00 mj Exp $ * * The PCI Library -- User Access * @@ -39,6 +39,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { #else NULL, #endif +#ifdef HAVE_PM_AIX_DEVICE + &pm_aix_device, +#else + NULL, +#endif #ifdef HAVE_PM_DUMP &pm_dump, #else diff --git a/lib/configure b/lib/configure index e7ea209..87b111d 100755 --- a/lib/configure +++ b/lib/configure @@ -1,23 +1,39 @@ #!/bin/sh -echo -n "Configuring libpci for your system..." +echo_n() { + if [ -n "$BASH" ] + then + echo -n "$*" + else + echo "$*\c" + fi +} + +echo_n "Configuring libpci for your system..." prefix=${1:-/usr} version=${2:-0.0} sys=`uname -s` rel=`uname -r` -cpu=`uname -m | sed 's/^i.86$/i386/;s/^sun4u$/sparc64/'` -echo "$sys/$cpu $rel" +if [ "$sys" = "AIX" -a -x /usr/bin/oslevel -a -x /usr/sbin/lsattr ] +then + rel=`/usr/bin/oslevel` + proc=`/usr/sbin/lsdev -C -c processor -S available -F name | head -1` + cpu=`/usr/sbin/lsattr -F value -l $proc -a type | sed 's/_.*//'` +else + cpu=`uname -m | sed 's/^i.86$/i386/;s/^sun4u$/sparc64/'` +fi +echo " $sys/$cpu $rel" c=config.h echo >$c "#define ARCH_`echo $cpu | tr 'a-z' 'A-Z'`" -echo >$c "#define OS_`echo $sys | tr 'a-z' 'A-Z'`" +echo >>$c "#define OS_`echo $sys | tr 'a-z' 'A-Z'`" -echo -n "Looking for access methods..." +echo_n "Looking for access methods..." case $sys in Linux) case $rel in - 2.[1-9]*|[3-9]*) echo -n " proc" + 2.[1-9]*|[3-9]*) echo_n " proc" echo >>$c '#define HAVE_PM_LINUX_PROC' echo >>$c '#define HAVE_LINUX_BYTEORDER_H' echo >>$c '#define PATH_PROC_BUS_PCI "/proc/bus/pci"' @@ -25,31 +41,36 @@ case $sys in ;; esac case $cpu in - i386) echo -n " i386-ports" + i386) echo_n " i386-ports" echo >>$c '#define HAVE_PM_INTEL_CONF' ok=1 ;; alpha|ia64) echo >>$c '#define HAVE_64BIT_ADDRESS' -# echo -n " syscalls" +# echo_n " syscalls" # echo >>$c '#define HAVE_PM_SYSCALLS' # ok=1 ;; sparc|sparc64) echo >>$c '#define HAVE_64BIT_ADDRESS' echo >>$c '#define HAVE_LONG_ADDRESS' -# echo -n " syscalls" +# echo_n " syscalls" # echo >>$c '#define HAVE_PM_SYSCALLS' # ok=1 ;; esac ;; FreeBSD) - echo -n " fbsd-device" + echo_n " fbsd-device" echo >>$c '#define HAVE_PM_FBSD_DEVICE' echo >>$c '#define PATH_FBSD_DEVICE "/dev/pci"' ok=1 ;; + AIX) + echo_n " aix-device" + echo >>$c '#define HAVE_PM_AIX_DEVICE' + ok=1 + ;; *) - echo " The PCI library currently supports only Linux and FreeBSD" + echo " The PCI library currently supports only Linux, AIX and FreeBSD" exit 1 ;; esac diff --git a/lib/generic.c b/lib/generic.c index f1d9e30..03e9f72 100644 --- a/lib/generic.c +++ b/lib/generic.c @@ -1,9 +1,9 @@ /* - * $Id: generic.c,v 1.5 1999/07/07 11:23:09 mj Exp $ + * $Id: generic.c,v 1.6 2000/04/21 11:58:00 mj Exp $ * * The PCI Library -- Generic Direct Access Functions * - * Copyright (c) 1997--1999 Martin Mares + * Copyright (c) 1997--2000 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -12,7 +12,7 @@ #include "internal.h" -static void +void pci_generic_scan_bus(struct pci_access *a, byte *busmap, int bus) { int dev, multi, ht; diff --git a/lib/internal.h b/lib/internal.h index b049f3d..ff86b2d 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,5 +1,5 @@ /* - * $Id: internal.h,v 1.3 1999/07/20 14:01:32 mj Exp $ + * $Id: internal.h,v 1.4 2000/04/21 11:58:00 mj Exp $ * * The PCI Library -- Internal Include File * @@ -71,6 +71,7 @@ struct pci_methods { void (*cleanup_dev)(struct pci_dev *); }; +void pci_generic_scan_bus(struct pci_access *, byte *busmap, int bus); void pci_generic_scan(struct pci_access *); int pci_generic_fill_info(struct pci_dev *, int flags); int pci_generic_block_read(struct pci_dev *, int pos, byte *buf, int len); @@ -83,6 +84,11 @@ struct pci_dev *pci_alloc_dev(struct pci_access *); int pci_link_dev(struct pci_access *, struct pci_dev *); extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc, - pm_syscalls, pm_fbsd_device, pm_dump; + pm_syscalls, pm_fbsd_device, pm_aix_device, pm_dump; +#ifdef __GNUC__ #define UNUSED __attribute__((unused)) +#else +#define UNUSED +#define inline +#endif diff --git a/lib/pci.h b/lib/pci.h index e37f8e2..7427cf2 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -1,5 +1,5 @@ /* - * $Id: pci.h,v 1.7 1999/10/09 13:26:14 mj Exp $ + * $Id: pci.h,v 1.8 2000/04/21 11:58:00 mj Exp $ * * The PCI Library * @@ -43,6 +43,16 @@ typedef u_int16_t u16; typedef u_int32_t u32; #endif +#ifdef OS_AIX +#include + +typedef u_int8_t byte; +typedef u_int8_t u8; +typedef u_int16_t word; +typedef u_int16_t u16; +typedef u_int32_t u32; +#endif + #ifdef HAVE_LONG_ADDRESS typedef unsigned long long pciaddr_t; #else @@ -62,8 +72,9 @@ struct nl_entry; #define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */ #define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */ #define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */ -#define PCI_ACCESS_DUMP 6 /* Dump file (params: filename) */ -#define PCI_ACCESS_MAX 7 +#define PCI_ACCESS_AIX_DEVICE 6 /* /dev/pci0, /dev/bus0, etc. */ +#define PCI_ACCESS_DUMP 7 /* Dump file (params: filename) */ +#define PCI_ACCESS_MAX 8 struct pci_access { /* Options you can change: */ diff --git a/lib/proc.c b/lib/proc.c index fc15efb..d4d427a 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -1,5 +1,5 @@ /* - * $Id: proc.c,v 1.7 2000/01/20 21:14:44 mj Exp $ + * $Id: proc.c,v 1.8 2000/04/21 11:58:00 mj Exp $ * * The PCI Library -- Configuration Access via /proc/bus/pci * @@ -48,8 +48,8 @@ static int pwrite(unsigned int fd, void *buf, size_t size, loff_t where) #include static _syscall5(int, pread, unsigned int, fd, void *, buf, size_t, size, u32, where_lo, u32, where_hi); static _syscall5(int, pwrite, unsigned int, fd, void *, buf, size_t, size, u32, where_lo, u32, where_hi); -static int do_read(struct pci_dev *d __attribute__((unused)), int fd, void *buf, size_t size, int where) { return pread(fd, buf, size, where, 0); } -static int do_write(struct pci_dev *d __attribute__((unused)), int fd, void *buf, size_t size, int where) { return pwrite(fd, buf, size, where, 0); } +static int do_read(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pread(fd, buf, size, where, 0); } +static int do_write(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pwrite(fd, buf, size, where, 0); } #define HAVE_DO_READ #else diff --git a/lspci.c b/lspci.c index 656e445..b2ce104 100644 --- a/lspci.c +++ b/lspci.c @@ -1,5 +1,5 @@ /* - * $Id: lspci.c,v 1.35 2000/01/23 05:57:04 mj Exp $ + * $Id: lspci.c,v 1.36 2000/04/21 11:58:00 mj Exp $ * * Linux PCI Utilities -- List All PCI Devices * @@ -74,6 +74,16 @@ static struct pci_access *pacc; #define IO_FORMAT "%04lx" #endif +/* + * If we aren't being compiled by GCC, use malloc() instead of alloca(). + * This increases our memory footprint, but only slightly since we don't + * use alloca() much. + */ + +#ifndef __GNUC__ +#define alloca malloc +#endif + /* Our view of the PCI bus */ struct device { @@ -1006,7 +1016,10 @@ insert_dev(struct device *d, struct bridge *b) struct bridge *c; for(c=b->child; c; c=c->next) if (c->secondary <= p->bus && p->bus <= c->subordinate) - return insert_dev(d, c); + { + insert_dev(d, c); + return; + } bus = new_bus(b, p->bus); } /* Simple insertion at the end _does_ guarantee the correct order as the diff --git a/pciutils.h b/pciutils.h index d223353..ba709f5 100644 --- a/pciutils.h +++ b/pciutils.h @@ -1,5 +1,5 @@ /* - * $Id: pciutils.h,v 1.12 1999/01/22 21:04:59 mj Exp $ + * $Id: pciutils.h,v 1.13 2000/04/21 11:58:01 mj Exp $ * * Linux PCI Utilities -- Declarations * @@ -12,6 +12,11 @@ #define PCIUTILS_VERSION PCILIB_VERSION +#if !defined(__GNUC__) +#define __attribute__(x) +#define inline +#endif + void __attribute__((noreturn)) die(char *msg, ...); void *xmalloc(unsigned int howmuch); int parse_generic_option(int i, struct pci_access *pacc, char *optarg); -- 2.39.2