📄 pci.c
字号:
/* (C) 2002 - library implementation by Nick Kyrshev XFree86 3.3.3 scanpci.c, modified for GATOS/win/gfxdump by 貀vind Aabling. *//* $XConsortium: scanpci.c /main/25 1996/10/27 11:48:40 kaleb $ *//* * name: scanpci.c * * purpose: This program will scan for and print details of * devices on the PCI bus. * author: Robin Cutshaw (robin@xfree86.org) * * supported O/S's: SVR4, UnixWare, SCO, Solaris, * FreeBSD, NetBSD, 386BSD, BSDI BSD/386, * Linux, Mach/386, ISC * DOS (WATCOM 9.5 compiler) * * compiling: [g]cc scanpci.c -o scanpci * for SVR4 (not Solaris), UnixWare use: * [g]cc -DSVR4 scanpci.c -o scanpci * for DOS, watcom 9.5: * wcc386p -zq -omaxet -7 -4s -s -w3 -d2 name.c * and link with PharLap or other dos extender for exe * */ /* $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $ */ /* * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of the above listed copyright holder(s) * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. The above listed * copyright holder(s) make(s) no representations about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. * * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #include "libdha.h"#include <errno.h>#include <string.h>#include <stdio.h>#ifdef __unix__#include <unistd.h>#endif#include "AsmMacros.h"/* OS depended stuff */#if defined (linux)#include "sysdep/pci_linux.c"#elif defined (__FreeBSD__)#include "sysdep/pci_freebsd.c"#elif defined (__386BSD__)#include "sysdep/pci_386bsd.c"#elif defined (__NetBSD__)#include "sysdep/pci_netbsd.c"#elif defined (__OpenBSD__)#include "sysdep/pci_openbsd.c"#elif defined (__bsdi__)#include "sysdep/pci_bsdi.c"#elif defined (Lynx)#include "sysdep/pci_lynx.c"#elif defined (MACH386)#include "sysdep/pci_mach386.c"#elif defined (__SVR4)#if !defined(SVR4)#define SVR4#endif#include "sysdep/pci_svr4.c"#elif defined (SCO)#include "sysdep/pci_sco.c"#elif defined (ISC)#include "sysdep/pci_isc.c"#elif defined (__EMX__)#include "sysdep/pci_os2.c"#elif defined (_WIN32) || defined(__CYGWIN__)#include "sysdep/pci_win32.c"#ifdef __MINGW32__#define ENOTSUP 134 /* Not supported */#endif#endif#if 0#if defined(__SUNPRO_C) || defined(sun) || defined(__sun)#include <sys/psw.h>#else#include <sys/seg.h>#endif#include <sys/v86.h>#endif #if defined(Lynx) && defined(__powerpc__)/* let's mimick the Linux Alpha stuff for LynxOS so we don't have * to change too much code */#include <smem.h> static unsigned char *pciConfBase; static __inline__ unsigned longstatic swapl(unsigned long val){ unsigned char *p = (unsigned char *)&val; return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));} #define BUS(tag) (((tag)>>16)&0xff)#define DFN(tag) (((tag)>>8)&0xff) #define PCIBIOS_DEVICE_NOT_FOUND 0x86#define PCIBIOS_SUCCESSFUL 0x00 int pciconfig_read( unsigned char bus, unsigned char dev, unsigned char offset, int len, /* unused, alway 4 */ unsigned long *val){ unsigned long _val; unsigned long *ptr; dev >>= 3; if (bus || dev >= 16) { *val = 0xFFFFFFFF; return PCIBIOS_DEVICE_NOT_FOUND; } else { ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); _val = swapl(*ptr); } *val = _val; return PCIBIOS_SUCCESSFUL;} int pciconfig_write( unsigned char bus, unsigned char dev, unsigned char offset, int len, /* unused, alway 4 */ unsigned long val){ unsigned long _val; unsigned long *ptr; dev >>= 3; _val = swapl(val); if (bus || dev >= 16) { return PCIBIOS_DEVICE_NOT_FOUND; } else { ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); *ptr = _val; } return PCIBIOS_SUCCESSFUL;}#endif #if !defined(__powerpc__)struct pci_config_reg { /* start of official PCI config space header */ union { unsigned long device_vendor; struct { unsigned short vendor; unsigned short device; } dv; } dv_id;#define _device_vendor dv_id.device_vendor#define _vendor dv_id.dv.vendor#define _device dv_id.dv.device union { unsigned long status_command; struct { unsigned short command; unsigned short status; } sc; } stat_cmd;#define _status_command stat_cmd.status_command#define _command stat_cmd.sc.command#define _status stat_cmd.sc.status union { unsigned long class_revision; struct { unsigned char rev_id; unsigned char prog_if; unsigned char sub_class; unsigned char base_class; } cr; } class_rev;#define _class_revision class_rev.class_revision#define _rev_id class_rev.cr.rev_id#define _prog_if class_rev.cr.prog_if#define _sub_class class_rev.cr.sub_class#define _base_class class_rev.cr.base_class union { unsigned long bist_header_latency_cache; struct { unsigned char cache_line_size; unsigned char latency_timer; unsigned char header_type; unsigned char bist; } bhlc; } bhlc;#define _bist_header_latency_cache bhlc.bist_header_latency_cache#define _cache_line_size bhlc.bhlc.cache_line_size#define _latency_timer bhlc.bhlc.latency_timer#define _header_type bhlc.bhlc.header_type#define _bist bhlc.bhlc.bist union { struct { unsigned long dv_base0; unsigned long dv_base1; unsigned long dv_base2; unsigned long dv_base3; unsigned long dv_base4; unsigned long dv_base5; } dv; struct { unsigned long bg_rsrvd[2]; unsigned char primary_bus_number; unsigned char secondary_bus_number; unsigned char subordinate_bus_number; unsigned char secondary_latency_timer; unsigned char io_base; unsigned char io_limit; unsigned short secondary_status; unsigned short mem_base; unsigned short mem_limit; unsigned short prefetch_mem_base; unsigned short prefetch_mem_limit; } bg; } bc;#define _base0 bc.dv.dv_base0#define _base1 bc.dv.dv_base1#define _base2 bc.dv.dv_base2#define _base3 bc.dv.dv_base3#define _base4 bc.dv.dv_base4#define _base5 bc.dv.dv_base5#define _primary_bus_number bc.bg.primary_bus_number#define _secondary_bus_number bc.bg.secondary_bus_number#define _subordinate_bus_number bc.bg.subordinate_bus_number#define _secondary_latency_timer bc.bg.secondary_latency_timer#define _io_base bc.bg.io_base#define _io_limit bc.bg.io_limit#define _secondary_status bc.bg.secondary_status#define _mem_base bc.bg.mem_base#define _mem_limit bc.bg.mem_limit#define _prefetch_mem_base bc.bg.prefetch_mem_base#define _prefetch_mem_limit bc.bg.prefetch_mem_limit unsigned long rsvd1; unsigned long rsvd2; unsigned long _baserom; unsigned long rsvd3; unsigned long rsvd4; union { unsigned long max_min_ipin_iline; struct { unsigned char int_line; unsigned char int_pin; unsigned char min_gnt; unsigned char max_lat; } mmii; } mmii;#define _max_min_ipin_iline mmii.max_min_ipin_iline#define _int_line mmii.mmii.int_line#define _int_pin mmii.mmii.int_pin#define _min_gnt mmii.mmii.min_gnt#define _max_lat mmii.mmii.max_lat /* I don't know how accurate or standard this is (DHD) */ union { unsigned long user_config; struct { unsigned char user_config_0; unsigned char user_config_1; unsigned char user_config_2; unsigned char user_config_3; } uc; } uc;#define _user_config uc.user_config#define _user_config_0 uc.uc.user_config_0#define _user_config_1 uc.uc.user_config_1#define _user_config_2 uc.uc.user_config_2#define _user_config_3 uc.uc.user_config_3 /* end of official PCI config space header */ unsigned long _pcibusidx; unsigned long _pcinumbus; unsigned long _pcibuses[16]; unsigned short _configtype; /* config type found */ unsigned short _ioaddr; /* config type 1 - private I/O addr */ unsigned long _cardnum; /* config type 2 - private card number */};#else/* ppc is big endian, swapping bytes is not quite enough * to interpret the PCI config registers... */struct pci_config_reg { /* start of official PCI config space header */ union { unsigned long device_vendor; struct { unsigned short device; unsigned short vendor; } dv; } dv_id;#define _device_vendor dv_id.device_vendor#define _vendor dv_id.dv.vendor#define _device dv_id.dv.device union { unsigned long status_command; struct { unsigned short status; unsigned short command; } sc; } stat_cmd;#define _status_command stat_cmd.status_command#define _command stat_cmd.sc.command#define _status stat_cmd.sc.status union { unsigned long class_revision; struct { unsigned char base_class; unsigned char sub_class; unsigned char prog_if; unsigned char rev_id; } cr; } class_rev;#define _class_revision class_rev.class_revision#define _rev_id class_rev.cr.rev_id#define _prog_if class_rev.cr.prog_if#define _sub_class class_rev.cr.sub_class#define _base_class class_rev.cr.base_class union { unsigned long bist_header_latency_cache; struct { unsigned char bist; unsigned char header_type; unsigned char latency_timer; unsigned char cache_line_size; } bhlc; } bhlc;#define _bist_header_latency_cache bhlc.bist_header_latency_cache#define _cache_line_size bhlc.bhlc.cache_line_size#define _latency_timer bhlc.bhlc.latency_timer#define _header_type bhlc.bhlc.header_type#define _bist bhlc.bhlc.bist union { struct { unsigned long dv_base0; unsigned long dv_base1; unsigned long dv_base2; unsigned long dv_base3; unsigned long dv_base4; unsigned long dv_base5; } dv;/* ?? */ struct { unsigned long bg_rsrvd[2];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -