* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / isdn / sc / shmem.c
blob6ff0812746b28c14d7217122d4816684fb2fab39
1 /*
2 * $Id: shmem.c,v 1.2 1996/11/20 17:49:56 fritz Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * card.c - Card functions implementing ISDN4Linux functionality
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * For more information, please contact gpl-info@spellcast.com or write:
23 * SpellCaster Telecommunications Inc.
24 * 5621 Finch Avenue East, Unit #3
25 * Scarborough, Ontario Canada
26 * M1B 2T9
27 * +1 (416) 297-8565
28 * +1 (416) 297-6433 Facsimile
31 #define __NO_VERSION__
32 #include "includes.h" /* This must be first */
33 #include "hardware.h"
34 #include "card.h"
37 * Main adapter array
39 extern board *adapter[];
40 extern int cinst;
45 void *memcpy_toshmem(int card, void *dest, const void *src, size_t n)
47 unsigned long flags;
48 void *ret;
49 unsigned char ch;
51 if(!IS_VALID_CARD(card)) {
52 pr_debug("Invalid param: %d is not a valid card id\n", card);
53 return NULL;
56 if(n > SRAM_PAGESIZE) {
57 return NULL;
61 * determine the page to load from the address
63 ch = (unsigned long) dest / SRAM_PAGESIZE;
64 pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
66 * Block interrupts and load the page
68 save_flags(flags);
69 cli();
71 outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
72 adapter[card]->ioport[adapter[card]->shmem_pgport]);
73 pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
74 ((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
75 ret = memcpy_toio(adapter[card]->rambase +
76 ((unsigned long) dest % 0x4000), src, n);
77 pr_debug("%s: copying %d bytes from %#x to %#x\n",adapter[card]->devicename, n,
78 (unsigned long) src, adapter[card]->rambase + ((unsigned long) dest %0x4000));
79 restore_flags(flags);
81 return ret;
85 * Reverse of above
87 void *memcpy_fromshmem(int card, void *dest, const void *src, size_t n)
89 unsigned long flags;
90 void *ret;
91 unsigned char ch;
93 if(!IS_VALID_CARD(card)) {
94 pr_debug("Invalid param: %d is not a valid card id\n", card);
95 return NULL;
98 if(n > SRAM_PAGESIZE) {
99 return NULL;
103 * determine the page to load from the address
105 ch = (unsigned long) src / SRAM_PAGESIZE;
106 pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
110 * Block interrupts and load the page
112 save_flags(flags);
113 cli();
115 outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
116 adapter[card]->ioport[adapter[card]->shmem_pgport]);
117 pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
118 ((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
119 ret = memcpy_fromio(dest,(void *)(adapter[card]->rambase +
120 ((unsigned long) src % 0x4000)), n);
121 /* pr_debug("%s: copying %d bytes from %#x to %#x\n",
122 adapter[card]->devicename, n,
123 adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
124 restore_flags(flags);
126 return ret;
129 void *memset_shmem(int card, void *dest, int c, size_t n)
131 unsigned long flags;
132 unsigned char ch;
133 void *ret;
135 if(!IS_VALID_CARD(card)) {
136 pr_debug("Invalid param: %d is not a valid card id\n", card);
137 return NULL;
140 if(n > SRAM_PAGESIZE) {
141 return NULL;
145 * determine the page to load from the address
147 ch = (unsigned long) dest / SRAM_PAGESIZE;
148 pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
151 * Block interrupts and load the page
153 save_flags(flags);
154 cli();
156 outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
157 adapter[card]->ioport[adapter[card]->shmem_pgport]);
158 pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
159 ((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
160 ret = memset_io(adapter[card]->rambase +
161 ((unsigned long) dest % 0x4000), c, n);
162 restore_flags(flags);
164 return ret;