Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: shmem.c,v 1.2.10.1 2001/09/23 22:24:59 kai Exp $ |
| 2 | * |
| 3 | * Copyright (C) 1996 SpellCaster Telecommunications Inc. |
| 4 | * |
| 5 | * Card functions implementing ISDN4Linux functionality |
| 6 | * |
| 7 | * This software may be used and distributed according to the terms |
| 8 | * of the GNU General Public License, incorporated herein by reference. |
| 9 | * |
| 10 | * For more information, please contact gpl-info@spellcast.com or write: |
| 11 | * |
| 12 | * SpellCaster Telecommunications Inc. |
| 13 | * 5621 Finch Avenue East, Unit #3 |
| 14 | * Scarborough, Ontario Canada |
| 15 | * M1B 2T9 |
| 16 | * +1 (416) 297-8565 |
| 17 | * +1 (416) 297-6433 Facsimile |
| 18 | */ |
| 19 | |
| 20 | #include "includes.h" /* This must be first */ |
| 21 | #include "hardware.h" |
| 22 | #include "card.h" |
| 23 | |
| 24 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * |
| 26 | */ |
| 27 | void memcpy_toshmem(int card, void *dest, const void *src, size_t n) |
| 28 | { |
| 29 | unsigned long flags; |
| 30 | unsigned char ch; |
Jeff Garzik | 9317d43 | 2007-10-23 18:36:39 -0400 | [diff] [blame] | 31 | unsigned long dest_rem = ((unsigned long) dest) % 0x4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Jeff Garzik | 9317d43 | 2007-10-23 18:36:39 -0400 | [diff] [blame] | 33 | if (!IS_VALID_CARD(card)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | pr_debug("Invalid param: %d is not a valid card id\n", card); |
| 35 | return; |
| 36 | } |
| 37 | |
Jeff Garzik | 9317d43 | 2007-10-23 18:36:39 -0400 | [diff] [blame] | 38 | if (n > SRAM_PAGESIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * determine the page to load from the address |
| 43 | */ |
| 44 | ch = (unsigned long) dest / SRAM_PAGESIZE; |
| 45 | pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch); |
| 46 | /* |
| 47 | * Block interrupts and load the page |
| 48 | */ |
| 49 | spin_lock_irqsave(&sc_adapter[card]->lock, flags); |
| 50 | |
| 51 | outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80, |
| 52 | sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]); |
Frank Lichtenheld | 66ba886 | 2007-11-14 15:59:43 -0800 | [diff] [blame] | 53 | memcpy_toio((void __iomem *)(sc_adapter[card]->rambase + dest_rem), src, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 55 | pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename, |
| 56 | ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80); |
Randy Dunlap | 0d5048a | 2009-02-20 00:54:44 -0800 | [diff] [blame] | 57 | pr_debug("%s: copying %zu bytes from %#lx to %#lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | sc_adapter[card]->devicename, n, |
| 59 | (unsigned long) src, |
| 60 | sc_adapter[card]->rambase + ((unsigned long) dest %0x4000)); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Reverse of above |
| 65 | */ |
| 66 | void memcpy_fromshmem(int card, void *dest, const void *src, size_t n) |
| 67 | { |
| 68 | unsigned long flags; |
| 69 | unsigned char ch; |
| 70 | |
| 71 | if(!IS_VALID_CARD(card)) { |
| 72 | pr_debug("Invalid param: %d is not a valid card id\n", card); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if(n > SRAM_PAGESIZE) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * determine the page to load from the address |
| 82 | */ |
| 83 | ch = (unsigned long) src / SRAM_PAGESIZE; |
| 84 | pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch); |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * Block interrupts and load the page |
| 89 | */ |
| 90 | spin_lock_irqsave(&sc_adapter[card]->lock, flags); |
| 91 | |
| 92 | outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80, |
| 93 | sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]); |
| 94 | memcpy_fromio(dest,(void *)(sc_adapter[card]->rambase + |
| 95 | ((unsigned long) src % 0x4000)), n); |
| 96 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 97 | pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename, |
| 98 | ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80); |
| 99 | /* pr_debug("%s: copying %d bytes from %#x to %#x\n", |
| 100 | sc_adapter[card]->devicename, n, |
| 101 | sc_adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */ |
| 102 | } |
| 103 | |
Adrian Bunk | e3ca5e7 | 2005-06-25 14:58:34 -0700 | [diff] [blame] | 104 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | void memset_shmem(int card, void *dest, int c, size_t n) |
| 106 | { |
| 107 | unsigned long flags; |
| 108 | unsigned char ch; |
| 109 | |
| 110 | if(!IS_VALID_CARD(card)) { |
| 111 | pr_debug("Invalid param: %d is not a valid card id\n", card); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | if(n > SRAM_PAGESIZE) { |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * determine the page to load from the address |
| 121 | */ |
| 122 | ch = (unsigned long) dest / SRAM_PAGESIZE; |
| 123 | pr_debug("%s: loaded page %d\n",sc_adapter[card]->devicename,ch); |
| 124 | |
| 125 | /* |
| 126 | * Block interrupts and load the page |
| 127 | */ |
| 128 | spin_lock_irqsave(&sc_adapter[card]->lock, flags); |
| 129 | |
| 130 | outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80, |
| 131 | sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]); |
| 132 | memset_io(sc_adapter[card]->rambase + |
| 133 | ((unsigned long) dest % 0x4000), c, n); |
| 134 | pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename, |
| 135 | ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80); |
| 136 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 137 | } |
Adrian Bunk | e3ca5e7 | 2005-06-25 14:58:34 -0700 | [diff] [blame] | 138 | #endif /* 0 */ |