pciconf.c (124031) | pciconf.c (133249) |
---|---|
1/* 2 * Copyright 1996 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 15 unchanged lines hidden (view full) --- 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = | 1/* 2 * Copyright 1996 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 15 unchanged lines hidden (view full) --- 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = |
32 "$FreeBSD: head/usr.sbin/pciconf/pciconf.c 124031 2003-12-31 19:38:29Z rwatson $"; | 32 "$FreeBSD: head/usr.sbin/pciconf/pciconf.c 133249 2004-08-07 04:28:56Z imp $"; |
33#endif /* not lint */ 34 35#include <sys/types.h> 36#include <sys/fcntl.h> 37 38#include <err.h> 39#include <stdlib.h> 40#include <stdio.h> --- 18 unchanged lines hidden (view full) --- 59 TAILQ_ENTRY(pci_vendor_info) link; 60 TAILQ_HEAD(,pci_device_info) devs; 61 int id; 62 char *desc; 63}; 64 65TAILQ_HEAD(,pci_vendor_info) pci_vendors; 66 | 33#endif /* not lint */ 34 35#include <sys/types.h> 36#include <sys/fcntl.h> 37 38#include <err.h> 39#include <stdlib.h> 40#include <stdio.h> --- 18 unchanged lines hidden (view full) --- 59 TAILQ_ENTRY(pci_vendor_info) link; 60 TAILQ_HEAD(,pci_device_info) devs; 61 int id; 62 char *desc; 63}; 64 65TAILQ_HEAD(,pci_vendor_info) pci_vendors; 66 |
67static void dobar(const char *); |
|
67static void list_devs(int vendors); 68static void list_verbose(struct pci_conf *p); 69static char *guess_class(struct pci_conf *p); 70static char *guess_subclass(struct pci_conf *p); 71static int load_vendors(void); 72static void readit(const char *, const char *, int); 73static void writeit(const char *, const char *, const char *, int); 74static void chkattached(const char *, int); --- 10 unchanged lines hidden (view full) --- 85 " pciconf -w [-b | -h] selector addr value"); 86 exit (1); 87} 88 89int 90main(int argc, char **argv) 91{ 92 int c; | 68static void list_devs(int vendors); 69static void list_verbose(struct pci_conf *p); 70static char *guess_class(struct pci_conf *p); 71static char *guess_subclass(struct pci_conf *p); 72static int load_vendors(void); 73static void readit(const char *, const char *, int); 74static void writeit(const char *, const char *, const char *, int); 75static void chkattached(const char *, int); --- 10 unchanged lines hidden (view full) --- 86 " pciconf -w [-b | -h] selector addr value"); 87 exit (1); 88} 89 90int 91main(int argc, char **argv) 92{ 93 int c; |
93 int listmode, readmode, writemode, attachedmode, verbose; | 94 int listmode, readmode, writemode, attachedmode, barmode, verbose; |
94 int byte, isshort; 95 | 95 int byte, isshort; 96 |
96 listmode = readmode = writemode = attachedmode = verbose = byte = isshort = 0; | 97 barmode = listmode = readmode = writemode = attachedmode = verbose = byte = isshort = 0; |
97 | 98 |
98 while ((c = getopt(argc, argv, "alrwbhv")) != -1) { | 99 while ((c = getopt(argc, argv, "aBbhlrwv")) != -1) { |
99 switch(c) { 100 case 'a': 101 attachedmode = 1; 102 break; 103 | 100 switch(c) { 101 case 'a': 102 attachedmode = 1; 103 break; 104 |
105 case 'B': 106 barmode = 1; 107 break; 108 109 case 'b': 110 byte = 1; 111 break; 112 113 case 'h': 114 isshort = 1; 115 break; 116 |
|
104 case 'l': 105 listmode = 1; 106 break; 107 108 case 'r': 109 readmode = 1; 110 break; 111 112 case 'w': 113 writemode = 1; 114 break; 115 | 117 case 'l': 118 listmode = 1; 119 break; 120 121 case 'r': 122 readmode = 1; 123 break; 124 125 case 'w': 126 writemode = 1; 127 break; 128 |
116 case 'b': 117 byte = 1; 118 break; 119 120 case 'h': 121 isshort = 1; 122 break; 123 | |
124 case 'v': 125 verbose = 1; 126 break; 127 128 default: 129 usage(); 130 } 131 } 132 133 if ((listmode && optind != argc) 134 || (writemode && optind + 3 != argc) 135 || (readmode && optind + 2 != argc) | 129 case 'v': 130 verbose = 1; 131 break; 132 133 default: 134 usage(); 135 } 136 } 137 138 if ((listmode && optind != argc) 139 || (writemode && optind + 3 != argc) 140 || (readmode && optind + 2 != argc) |
136 || (attachedmode && optind + 1 != argc)) | 141 || (attachedmode && optind + 1 != argc) 142 || (barmode && optind + 1 != argc) |
137 usage(); 138 139 if (listmode) { 140 list_devs(verbose); 141 } else if (attachedmode) { 142 chkattached(argv[optind], 143 byte ? 1 : isshort ? 2 : 4); 144 } else if (readmode) { 145 readit(argv[optind], argv[optind + 1], 146 byte ? 1 : isshort ? 2 : 4); 147 } else if (writemode) { 148 writeit(argv[optind], argv[optind + 1], argv[optind + 2], 149 byte ? 1 : isshort ? 2 : 4); | 143 usage(); 144 145 if (listmode) { 146 list_devs(verbose); 147 } else if (attachedmode) { 148 chkattached(argv[optind], 149 byte ? 1 : isshort ? 2 : 4); 150 } else if (readmode) { 151 readit(argv[optind], argv[optind + 1], 152 byte ? 1 : isshort ? 2 : 4); 153 } else if (writemode) { 154 writeit(argv[optind], argv[optind + 1], argv[optind + 2], 155 byte ? 1 : isshort ? 2 : 4); |
156 } else if (barmode) { |
|
150 } else { 151 usage(); 152 } 153 154 return exitstatus; 155} 156 157static void --- 309 unchanged lines hidden (view full) --- 467 468 if (ioctl(fd, PCIOCREAD, &pi) < 0) 469 err(1, "ioctl(PCIOCREAD)"); 470 471 printf("%0*x", width*2, pi.pi_data); 472} 473 474static void | 157 } else { 158 usage(); 159 } 160 161 return exitstatus; 162} 163 164static void --- 309 unchanged lines hidden (view full) --- 474 475 if (ioctl(fd, PCIOCREAD, &pi) < 0) 476 err(1, "ioctl(PCIOCREAD)"); 477 478 printf("%0*x", width*2, pi.pi_data); 479} 480 481static void |
482dobar(const char *name) 483{ 484#define NBAR 6 485 long rstart = 0x10; 486 long rend = 0x24; 487 long r; 488 char *end; 489 int i; 490 int fd; 491 uint32_t bars[NBAR]; 492 struct pcisel sel; 493 struct pci_io pi; 494 495 496 fd = open(_PATH_DEVPCI, O_RDWR, 0); 497 if (fd < 0) 498 err(1, "%s", _PATH_DEVPCI); 499 500 /* 501 * Read in the bars 502 */ 503 sel = getsel(name); 504 for (i = 0, r = rstart; r <= rend; i++, r += 4) { 505 pi.pi_sel = sel; 506 pi.pi_reg = r; 507 pi.pi_width = 4; 508 if (ioctl(fd, PCIOCREAD, &pi) < 0) 509 err(1, "ioctl(PCIOCREAD)"); 510 bars[i++] = pi.pi_data; 511 } 512 513 /* 514 * Print the bars 515 */ 516 for (i = 0; i < NBAR; i++) { 517 if (bars[i] == 0) 518 next; 519 if (bars[i] & 1) { 520 /* I/O bar */ 521 } else { 522 /* Memory bar */ 523 } 524 } 525 526 close(fd); 527} 528 529static void |
|
475readit(const char *name, const char *reg, int width) 476{ 477 long rstart; 478 long rend; 479 long r; 480 char *end; 481 int i; 482 int fd; --- 62 unchanged lines hidden --- | 530readit(const char *name, const char *reg, int width) 531{ 532 long rstart; 533 long rend; 534 long r; 535 char *end; 536 int i; 537 int fd; --- 62 unchanged lines hidden --- |