Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | /* * Copyright (C) Eicon Technology Corporation, 2000. * * Eicon File Revision : 1.16 * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * */ #define N_DATA #include <linux/config.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/interrupt.h> #include <linux/smp_lock.h> #include <asm/io.h> #include <asm/system.h> #include <linux/slab.h> #include <linux/pci.h> #include <linux/delay.h> #undef N_DATA #include "uxio.h" static int log_on=0; int Divasdevflag = 0; spinlock_t diva_lock = SPIN_LOCK_UNLOCKED; static ux_diva_card_t card_pool[MAX_CARDS]; void UxPause(long int ms) { unsigned long timeout = jiffies + ((ms * HZ) / 1000); while (time_before(jiffies, timeout)); } int UxCardHandleGet(ux_diva_card_t **card, dia_card_t *cfg) { int i; ux_diva_card_t *c; if (cfg->bus_type != DIA_BUS_TYPE_PCI) { DPRINTF(("divas hw: type not PCI (%d)", cfg->bus_type)); return -1; } for (i = 0; (i < DIM(card_pool)) && (card_pool[i].in_use); i++) { ; } if (i == DIM(card_pool)) { DPRINTF(("divas hw: card_pool exhausted")); return -1; } c = *card = &card_pool[i]; switch (cfg->bus_type) { case DIA_BUS_TYPE_PCI: c->pdev = cfg->pdev; c->io_base = cfg->io_base; c->reset_base = cfg->reset_base; c->card_type = cfg->card_type; c->mapped = NULL; c->slot = cfg->slot; c->irq = (int) cfg->irq; c->pDRAM = cfg->memory[DIVAS_RAM_MEMORY]; c->pDEVICES = cfg->memory[DIVAS_REG_MEMORY]; c->pCONFIG = cfg->memory[DIVAS_CFG_MEMORY]; c->pSHARED = cfg->memory[DIVAS_SHARED_MEMORY]; c->pCONTROL = cfg->memory[DIVAS_CTL_MEMORY]; /* c->bus_type = DIA_BUS_TYPE_PCI; c->bus_num = cfg->bus_num & 0x3f; c->slot = cfg->slot; c->irq = (int) cfg->irq; c->int_priority = (int) cfg->int_priority; c->card_type = cfg->card_type; c->io_base = cfg->io_base; c->reset_base = cfg->reset_base; c->pDRAM = cfg->memory[DIVAS_RAM_MEMORY]; c->pDEVICES = cfg->memory[DIVAS_REG_MEMORY]; c->pCONFIG = cfg->memory[DIVAS_CFG_MEMORY]; c->pSHARED = cfg->memory[DIVAS_SHARED_MEMORY]; DPRINTF(("divas hw: pDRAM is 0x%x", c->pDRAM)); DPRINTF(("divas hw: pSHARED is 0x%x", c->pSHARED)); DPRINTF(("divas hw: pCONFIG is 0x%x", c->pCONFIG)); c->cm_key = cm_getbrdkey("Divas", cfg->card_id);*/ break; default: break; } c->in_use = TRUE; return 0; } void UxCardHandleFree(ux_diva_card_t *card) { card->in_use = FALSE; } #define PLX_IOBASE 0 #define DIVAS_IOBASE 1 void *UxCardMemAttach(ux_diva_card_t *card, int id) { if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER) { switch (id) { case DIVAS_SHARED_MEMORY: card->mapped = card->pSHARED; return card->pSHARED; break; case DIVAS_RAM_MEMORY: card->mapped = card->pDRAM; return card->pDRAM; break; case DIVAS_REG_MEMORY: card->mapped = card->pDEVICES; return card->pDEVICES; break; case DIVAS_CFG_MEMORY: card->mapped = card->pCONFIG; return card->pCONFIG; break; default: ASSERT(FALSE); card->mapped = NULL; return (void *) 0; } } else if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER_B) { switch (id) { case PLX_IOBASE: return (void *) card->reset_base; break; case DIVAS_IOBASE: return (void *) card->io_base; break; default: ASSERT(FALSE); return 0; } } else if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER_Q) { switch (id) { case DIVAS_SHARED_MEMORY: card->mapped = card->pSHARED; return card->pSHARED; break; case DIVAS_RAM_MEMORY: card->mapped = card->pDRAM; return card->pDRAM; break; case DIVAS_REG_MEMORY: card->mapped = (void *) card->io_base; return (void *) card->io_base; break; case DIVAS_CTL_MEMORY: card->mapped = card->pCONTROL; return card->pCONTROL; break; default: // ASSERT(FALSE); DPRINTF(("divas: Trying to attach to mem %d", id)); card->mapped = NULL; return (void *) 0; } } else DPRINTF(("divas: Tried to attach to unknown card")); /* Unknown card type */ return NULL; } void UxCardMemDetach(ux_diva_card_t *card, void *address) { return; // Just a place holder. No un-mapping done. } void UxCardLog(int turn_on) { log_on = turn_on; } /* * Control Register I/O Routines to be performed on Attached I/O ports */ void UxCardPortIoOut(ux_diva_card_t *card, void *AttachedBase, int offset, byte the_byte) { word base = (word) (dword) AttachedBase; base += offset; outb(the_byte, base); } void UxCardPortIoOutW(ux_diva_card_t *card, void *AttachedBase, int offset, word the_word) { word base = (word) (dword) AttachedBase; base += offset; outw(the_word, base); } void UxCardPortIoOutD(ux_diva_card_t *card, void *AttachedBase, int offset, dword the_dword) { word base = (word) (dword) AttachedBase; base += offset; outl(the_dword, base); } byte UxCardPortIoIn(ux_diva_card_t *card, void *AttachedBase, int offset) { word base = (word) (dword) AttachedBase; base += offset; return inb(base); } word UxCardPortIoInW(ux_diva_card_t *card, void *AttachedBase, int offset) { word base = (word) (dword) AttachedBase; base += offset; return inw(base); } /* * Memory mapped card I/O functions */ byte UxCardMemIn(ux_diva_card_t *card, void *address) { byte b; volatile byte* t = (byte*)address; b = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%02x from 0x%x (memory mapped)", b & 0xff, a)); } return(b); } word UxCardMemInW(ux_diva_card_t *card, void *address) { word w; volatile word* t = (word*)address; w = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%04x from 0x%x (memory mapped)", w & 0xffff, a)); } return (w); } dword UxCardMemInD(ux_diva_card_t *card, void *address) { dword dw; volatile dword* t = (dword*)address; dw = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%08x from 0x%x (memory mapped)", dw, a)); } return (dw); } void UxCardMemInBuffer(ux_diva_card_t *card, void *address, void *buffer, int length) { volatile byte *pSource = address; byte *pDest = buffer; while (length--) { *pDest++ = *pSource++; } if (log_on) { byte *a = address; a -= (int) card->mapped; pDest = buffer; DPRINTF(("divas hw: read %02x %02x %02x %02x %02x %02x %02x %02x from 0x%x (memory mapped)", pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff, pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff, a)); } return; } void UxCardMemOut(ux_diva_card_t *card, void *address, byte data) { volatile byte* t = (byte*)address; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: wrote 0x%02x to 0x%x (memory mapped)", data & 0xff, a)); } *t = data; return; } void UxCardMemOutW(ux_diva_card_t *card, void *address, word data) { volatile word* t = (word*)address; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: wrote 0x%04x to 0x%x (memory mapped)", data & 0xffff, a)); } *t = data; return; } void UxCardMemOutD(ux_diva_card_t *card, void *address, dword data) { volatile dword* t = (dword*)address; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: wrote 0x%08x to 0x%x (memory mapped)", data, a)); } *t = data; return; } void UxCardMemOutBuffer(ux_diva_card_t *card, void *address, void *buffer, int length) { byte *pSource = buffer; byte *pDest = address; while (length--) { *pDest++ = *pSource++; } if (log_on) { byte *a = address; a -= (int) card->mapped; pDest = buffer; DPRINTF(("divas hw: wrote %02x %02x %02x %02x %02x %02x %02x %02x to 0x%x (memory mapped)", pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff, pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff, a)); } return; } /* * Memory mapped card I/O functions */ byte UxCardIoIn(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address) { byte the_byte; outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); the_byte = inb(card->io_base); if (log_on) { DPRINTF(("divas hw: read 0x%02x from 0x%x (I/O mapped)", the_byte & 0xff, address)); } return the_byte; } word UxCardIoInW(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address) { word the_word; outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); the_word = inw(card->io_base); if (log_on) { DPRINTF(("divas hw: read 0x%04x from 0x%x (I/O mapped)", the_word & 0xffff, address)); } return the_word; } dword UxCardIoInD(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address) { dword the_dword; outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); the_dword = inl(card->io_base); if (log_on) { DPRINTF(("divas hw: read 0x%08x from 0x%x (I/O mapped)", the_dword, address)); } return the_dword; } void UxCardIoInBuffer(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, void *buffer, int length) { byte *pSource = address; byte *pDest = buffer; if ((word) (dword) address & 0x1) { outb(0xFF, card->io_base + 0xC); outw((word) (dword) pSource, card->io_base + 4); *pDest = (byte) inb(card->io_base); pDest++; pSource++; length--; if (!length) { return; } } outb(0xFF, card->io_base + 0xC); outw((word) (dword) pSource, card->io_base + 4); insw(card->io_base, (word *)pDest,length%2 ? (length+1)>>1 : length>>1); if (log_on) { pDest = buffer; DPRINTF(("divas hw: read %02x %02x %02x %02x %02x %02x %02x %02x from 0x%x (I/O mapped)", pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff, pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff, address)); } return; } /* Output */ void UxCardIoOut(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, byte data) { if (log_on) { DPRINTF(("divas hw: wrote 0x%02x to 0x%x (I/O mapped)", data & 0xff, address)); } outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); outb((byte) data & 0xFF, card->io_base); return; } void UxCardIoOutW(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, word data) { if (log_on) { DPRINTF(("divas hw: wrote 0x%04x to 0x%x (I/O mapped)", data & 0xffff, address)); } outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); outw((word) data & 0xFFFF, card->io_base); return; } void UxCardIoOutD(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, dword data) { if (log_on) { DPRINTF(("divas hw: wrote 0x%08x to 0x%x (I/O mapped)", data, address)); } outb(0xFF, card->io_base + 0xC); outw((word) (dword) address, card->io_base + 4); outl((dword) data & 0xFFFFFFFF, card->io_base); return; } void UxCardIoOutBuffer(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, void *buffer, int length) { byte *pSource = buffer; byte *pDest = address; if ((word) (dword) address & 1) { outb(0xFF, card->io_base + 0xC); outw((word) (dword) pDest, card->io_base + 4); outb(*pSource, card->io_base); pSource++; pDest++; length--; if (!length) { return; } } outb(0xFF, card->io_base + 0xC); outw((word) (dword) pDest, card->io_base + 4); outsw(card->io_base, (word *)pSource, length%2 ? (length+1)>>1 : length>>1); if (log_on) { pDest = buffer; DPRINTF(("divas hw: wrote %02x %02x %02x %02x %02x %02x %02x %02x to 0x%x (I/O mapped)", pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff, pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff, address)); } return; } irqreturn_t Divasintr(int arg, void *unused, struct pt_regs *unused_regs) { int i; card_t *card = NULL; ux_diva_card_t *ux_ref = NULL; for (i = 0; i < DivasCardNext; i++) { if (arg == DivasCards[i].cfg.irq) { card = &DivasCards[i]; ux_ref = card->hw; if ((ux_ref) && (card->is_live)) { (*ux_ref->user_isr)(ux_ref->user_isr_arg); } else { DPRINTF(("divas: ISR couldn't locate card")); } } } return IRQ_HANDLED; } int UxIsrInstall(ux_diva_card_t *card, isr_fn_t *isr_fn, void *isr_arg) { int result; card->user_isr = isr_fn; card->user_isr_arg = isr_arg; result = request_irq(card->irq, Divasintr, SA_INTERRUPT | SA_SHIRQ, "Divas", (void *) isr_arg); return result; } void UxIsrRemove(ux_diva_card_t *card, void *dev_id) { free_irq(card->irq, card->user_isr_arg); } void UxPciConfigWrite(ux_diva_card_t *card, int size, int offset, void *value) { switch (size) { case sizeof(byte): pci_write_config_byte(card->pdev, offset, * (byte *) value); break; case sizeof(word): pci_write_config_word(card->pdev, offset, * (word *) value); break; case sizeof(dword): pci_write_config_dword(card->pdev, offset, * (dword *) value); break; default: printk(KERN_WARNING "Divas: Invalid size in UxPciConfigWrite\n"); } } void UxPciConfigRead(ux_diva_card_t *card, int size, int offset, void *value) { switch (size) { case sizeof(byte): pci_read_config_byte(card->pdev, offset, (byte *) value); break; case sizeof(word): pci_read_config_word(card->pdev, offset, (word *) value); break; case sizeof(dword): pci_read_config_dword(card->pdev, offset, (unsigned int *) value); break; default: printk(KERN_WARNING "Divas: Invalid size in UxPciConfigRead\n"); } } void *UxAlloc(unsigned int size) { void *m; m = kmalloc(size, GFP_ATOMIC); return m; } void UxFree(void *ptr) { kfree(ptr); } long UxCardLock(ux_diva_card_t *card) { unsigned long flags; spin_lock_irqsave(&diva_lock, flags); return flags; } void UxCardUnlock(ux_diva_card_t *card, unsigned long ipl) { spin_unlock_irqrestore(&diva_lock, ipl); } dword UxTimeGet(void) { return jiffies; } long UxInterlockedIncrement(ux_diva_card_t *card, long *dst) { register volatile long *p; register long ret; int ipl; p =dst; ipl = UxCardLock(card); *p += 1; ret = *p; UxCardUnlock(card,ipl); return(ret); } long UxInterlockedDecrement(ux_diva_card_t *card, long *dst) { register volatile long *p; register long ret; int ipl; p =dst; ipl = UxCardLock(card); *p -= 1; ret = *p; UxCardUnlock(card,ipl); return(ret); } |