?? ltmodem.c,v
字號:
if (!pci_read_block(p, 0, d->config, how_much)) die("Unable to read %d bytes of configuration space.", how_much); if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS) { /* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */ if (!pci_read_block(p, 0, d->config+64, 64)) die("Unable to read cardbus bridge extension data."); how_much = 128; } d->config_cnt = how_much; pci_setup_cache(p, d->config, d->config_cnt); pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE); return d;}static voidscan_devices(void){ struct device *d; struct pci_dev *p; pci_scan_bus(pacc); for(p=pacc->devices; p; p=p->next) if (d = scan_device(p)) { d->next = first_dev; first_dev = d; }}static intcheck_root(void){ static int is_root = -1; if (is_root < 0) is_root = !geteuid(); return is_root;}static intconfig_fetch(struct device *d, unsigned int pos, unsigned int len){ if (pos + len < d->config_cnt) return 1; if (pacc->method != PCI_ACCESS_DUMP && !check_root()) return 0; return pci_read_block(d->dev, pos, d->config + pos, len);}/* Config space accesses */static inline byteget_conf_byte(struct device *d, unsigned int pos){ return d->config[pos];}static wordget_conf_word(struct device *d, unsigned int pos){ return d->config[pos] | (d->config[pos+1] << 8);}static u32get_conf_long(struct device *d, unsigned int pos){ return d->config[pos] | (d->config[pos+1] << 8) | (d->config[pos+2] << 16) | (d->config[pos+3] << 24);}/* Sorting */static intcompare_them(const void *A, const void *B){ const struct pci_dev *a = (*(const struct device **)A)->dev; const struct pci_dev *b = (*(const struct device **)B)->dev; if (a->bus < b->bus) return -1; if (a->bus > b->bus) return 1; if (a->dev < b->dev) return -1; if (a->dev > b->dev) return 1; if (a->func < b->func) return -1; if (a->func > b->func) return 1; return 0;}static voidsort_them(void){ struct device **index, **h, **last_dev; int cnt; struct device *d; cnt = 0; for(d=first_dev; d; d=d->next) cnt++; h = index = alloca(sizeof(struct device *) * cnt); for(d=first_dev; d; d=d->next) *h++ = d; qsort(index, cnt, sizeof(struct device *), compare_them); last_dev = &first_dev; h = index; while (cnt--) { *last_dev = *h; last_dev = &(*h)->next; h++; } *last_dev = NULL;}/* Normal output */static voidshow_bases(struct device *d, int cnt){ struct pci_dev *p = d->dev; word cmd = get_conf_word(d, PCI_COMMAND); int i; for(i=0; i<cnt; i++) { pciaddr_t pos = p->base_addr[i]; u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i); if (flg == 0xffffffff) flg = 0; if (!pos && !flg) continue; printf("\tRegion %d: ", i); if (pos && !flg) /* Reported by the OS, but not by the device */ { printf("[virtual] "); flg = pos; } if (flg & PCI_BASE_ADDRESS_SPACE_IO) { pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK; printf("I/O ports at "); if (a) { portbase = (unsigned int) a; printf(IO_FORMAT, a); } else if (flg & PCI_BASE_ADDRESS_IO_MASK) printf("<ignored>"); else printf("<unassigned>"); if (!(cmd & PCI_COMMAND_IO)) printf(" [disabled]"); } else { int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK; pciaddr_t a = pos & PCI_ADDR_MEM_MASK; int done = 0; u32 z = 0; printf("Memory at "); if (t == PCI_BASE_ADDRESS_MEM_TYPE_64) { if (i >= cnt - 1) { printf("<invalid-64bit-slot>\n"); done = 1; } else { i++; z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i); if (buscentric_view) { if (a || z) printf("%08x" ADDR_FORMAT, z, a); else printf("<unassigned>"); done = 1; } } } if (!done) { if (a) printf(ADDR_FORMAT, a); else printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>"); } printf(" (%s, %sprefetchable)", (t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" : (t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" : (t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3", (flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-"); if (!(cmd & PCI_COMMAND_MEMORY)) printf(" [disabled]"); } putchar('\n'); }}static voidshow_htype0(struct device *d){ unsigned long rom = d->dev->rom_base_addr; show_bases(d, htype0_cnt); if (rom & 1) printf("\tExpansion ROM at %08lx%s\n", rom & PCI_ROM_ADDRESS_MASK, (rom & PCI_ROM_ADDRESS_ENABLE) ? "" : " [disabled]"); if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST) { int where = get_conf_byte(d, PCI_CAPABILITY_LIST); while (where) { int id, next, cap; printf("\tCapabilities: "); if (!config_fetch(d, where, 4)) { puts("<available only to root>"); break; } id = get_conf_byte(d, where + PCI_CAP_LIST_ID); next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT); cap = get_conf_word(d, where + PCI_CAP_FLAGS); printf("[%02x] ", where); if (id == 0xff) { printf("<chain broken>\n"); break; } switch (id) { case PCI_CAP_ID_PM: printf("Power Management version %d\n", cap & PCI_PM_CAP_VER_MASK); break; case PCI_CAP_ID_AGP: break; default: printf("#%02x [%04x]", id, cap); } where = next; } }}static struct bus *find_bus(struct bridge *b, unsigned int n){ struct bus *bus; for(bus=b->first_bus; bus; bus=bus->sibling) if (bus->number == n) break; return bus;}static struct bus *new_bus(struct bridge *b, unsigned int n){ struct bus *bus = xmalloc(sizeof(struct bus)); bus = xmalloc(sizeof(struct bus)); bus->number = n; bus->sibling = b->first_bus; bus->first_dev = NULL; bus->last_dev = &bus->first_dev; b->first_bus = bus; return bus;}static voidinsert_dev(struct device *d, struct bridge *b){ struct pci_dev *p = d->dev; struct bus *bus; if (! (bus = find_bus(b, p->bus))) { 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); bus = new_bus(b, p->bus); } /* Simple insertion at the end _does_ guarantee the correct order as the * original device list was sorted by (bus, devfn) lexicographically * and all devices on the new list have the same bus number. */ *bus->last_dev = d; bus->last_dev = &d->next; d->next = NULL;}/* Bus mapping mode */static voiddo_map_bridges(int bus, int min, int max){ struct bus_info *bi = bus_info + bus; struct bus_bridge *b; bi->guestbook = 1; for(b=bi->bridges; b; b=b->next) { if (bus_info[b->first].guestbook) b->bug = 1; else if (b->first < min || b->last > max) b->bug = 2; else { bus_info[b->first].via = b; do_map_bridges(b->first, b->first, b->last); } }}/* Show hexadecimal dump of first 64 bytes of the PCI configuration space (the standard header). Useful for debugging of drivers and lspci itself. */static voidshow_hex_dump(struct device *d){ unsigned int i; printf("Command reg: "); printf(" %02x", get_conf_byte(d, 5)); printf(" %02x", get_conf_byte(d, 4)); putchar('\t'); printf("Status reg: "); printf(" %02x", get_conf_byte(d, 7)); printf(" %02x", get_conf_byte(d, 6)); putchar('\n'); /* Note! the byte order is lsb msb */ printf("Base address regs: "); for(i=0x10; i<0x24; i++){ printf(" %02x", get_conf_byte(d, i)); } putchar('\n');}// Lucent modem specific stuff. void dp_onhook_cmd(void){#if 0 printf( "Should call cell_onhook()\n" ); dp_modem_command(0x13, 0, 0); x_output( 7); x_output(0x0e); x_output(0x14); x_output(0x10); if (byte_59ED2 == 0) { x_output(0x19); x_output( 3); x_output(0x12); } else byte_59ED2 = 0x0a; dp_write_dsp_ram(0xf20, 0x42f8); dp_regwrite(0xd8, 0xff); dp_regwrite(0xb7, 0xff); /* dp_tad_downloaded = dp_fax_downloaded = 0; */ if (byte_59ED4 == 1) { byte_59ED4 = 0; byte_59EB2 = 0; } v8bis_app_reset(); dp_init_local_phone_state(); V34Mode = 0; dp_update_diagnostics(); if (x_status != 0) goto l2D1; x_status = 1; ll_save_diagnostics(); l2D1: if (byte_59ED2 != 0) goto l2E7; if (x_modem_mode == 3) goto l2E7; dp_run_rom(); l2E7: dp_first_call = 0;#endif}voidgo_onhook(void){ dp_onhook_cmd();}void io_init(void){ struct pci_dev *p = modem_dev->dev; bool bMarsChipset; /* Only cards with device ID 044? are mars chipset based. */ bMarsChipset = ((p->device_id & 0xfff0) == 0x0440); // Set up the port IO. port_io_init(io_address[1], io_address[2], bMarsChipset);}@1.3log@Added some changes from Pavel Machek <pavel@@ucw.cz>. Added support for port offset.@text@d2 1a2 1 * $Id: ltmodem.c,v 1.2 1999/07/05 04:04:46 root Exp root $d13 6a18 1#include "portIO.h"d22 1a22 2intmain(int argc, char **argv)d26 3d53 1a53 1 while ((c = getopt(argc, argv, "im" )) != -1) {d59 27d89 4d94 4a97 1 printf( "Usage: ltmodem [-i]\n" );d101 1a101 1 exit:d107 18d162 2a163 4/* Show any found modem. */static voidshow_modem(void)d334 2a335 1 for (j=0; j<io_length[i]; j++)d337 3d443 1a443 1 printf ("Writing %8.8x to I/O port %x + %x.\n", input, io_address[i], offset);d445 1a445 1 WRITE_PORT_ULONG ((io_address[i] + offset), input);d450 1a450 1 printf("Read back value: %8.8x.\n", READ_PORT_ULONG(io_address[i] + offset));d657 4a660 2 if (a) printf(IO_FORMAT, a);d856 66@1.2log@Added monitoring functions to enable user to select I/O or registermonitoring and to set the monitoring interval in milliseconds.@text@d2 1a2 1 * $Id: ltmodem.c,v 0.3 1999/07/05 03:51:18 root Exp root $d7 1d13 1d20 3a22 5 if (argc == 2 && !strcmp(argv[1], "--version")) { puts("ltmodem version " LTMODEM_VERSION); return 0; }d38 7a44 3 if ( find_modem() ) { /* Display summary information. */ show_modem();d46 13a58 10 /* Display main menu and accept commands. */ main_menu(); } else { printf ("***************************************************\n"); printf ("Sorry, no Lucent PCI modem that I know of was found.\n"); printf ("If you have one fitted then please mail me with the details\n"); printf ("at: richard@@close.u-net.com please include an output from\n"); printf ("cat /proc/pci and as much info. on the card as possible.\n"); printf ("***************************************************\n");d60 1d94 1d192 2a193 4 printf (" Monitoring menu\n"); printf (" M - monitor, T - set type, I - set interval Q - Quit\n"); printf ("***************************************************\n"); printf ("Enter command: ");a200 3 case 'T': monitor_type = set_monitoring_type(); break;d202 12d232 2a233 3 // Choose monitoring type: printf ("***************************************************\n"); printf ("Set interval of scan for monitoring activity (in mS): \n");a247 28int set_monitoring_type(void){ // Value input by user. int input = 0; char trash; // Choose monitoring type: printf ("***************************************************\n"); printf ("Set type of monitoring activity: 1 - Reg's 2 - I/O\n"); scanf ("%d%c", &input, &trash); // Display monitoring setting. switch (input) { case 1: { printf ("Monitoring registers.\n"); return 1; } case 2: { printf ("Monitoring I/O ports.\n"); return 2; } default: { printf ("Illegal choice, defaulting to registers.\n"); // Default to registers. return 1; } }}d252 1a252 1 int i;d257 1a257 1 if (monitor_type == 1) { d264 1a264 1 else {d272 1a272 1 printf("I/O ports. ");d274 6a279 6 for (i=1;i<=io_cnt;i++) { printf("%x: %8.8x ", io_address[i], inl(io_address[i])); } putchar('\n'); // Free the ports. iopl(0);d281 2d284 1d305 1a305 5 printf ("***************************************************\n"); printf ("Modem write menu\n"); printf ("Commands: C - control reg, I - I/O, Q - quit\n"); printf ("***************************************************\n"); printf ("Enter command: ");a329 1 printf ("***************************************************\n");d346 1a346 2 printf ("***************************************************\n"); printf ("Set control register. Enter value in hex: ");a347 1 printf ("\n***************************************************\n");d356 1a356 1 int i;d358 2a359 1 int input = 0;a362 1 printf ("***************************************************\n");d368 2a369 1 printf ("Choose a port to write to: ");d371 1d373 1a373 1 /* Allow user to write to selected I/O port. */d375 1a375 2 printf ("***************************************************\n"); printf ("Write to I/O port %x. Enter value in hex: ", io_address[i]);d377 14a390 17 printf ("\n***************************************************\n"); /* Get access to all of I/O space. */ if (iopl(3) < 0) { perror("ltmodem: iopl()"); fprintf(stderr, "This program must be run as root.\n"); } else { printf ("Writing %8.8x to I/O port %x.\n", input, io_address[i]); /* Write value to port. */ outl(input, io_address[i]); /* Delay 10ms. */ usleep(10000); /* Read back the port. */ printf("Read back value: %8.8x.\n", inl(io_address[i])); /* Free the ports. */ iopl(0); }d406 1a406 5 printf ("***************************************************\n"); printf (" Main Menu\n"); printf ("Commands: M - monitor, W - write, Q - quit\n"); printf ("***************************************************\n"); printf ("Enter command: ");@1.1log@Initial revision@text@d2 1a2 1 * $Id: ltmodem.c,v 0.0.3 1999/07/04 22:50:44 rjmc Exp $d94 1a94 1/* Shown any found modem. */d256 1a256 1 // Default to regisiters.@
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -