1 /* $Id: shmem.c,v 1.1.4.1 2001/11/20 14:19:37 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 #define __NO_VERSION__
21 #include "includes.h"		/* This must be first */
22 #include "hardware.h"
23 #include "card.h"
24 
25 /*
26  * Main adapter array
27  */
28 extern board *adapter[];
29 extern int cinst;
30 
31 /*
32  *
33  */
memcpy_toshmem(int card,void * dest,const void * src,size_t n)34 void *memcpy_toshmem(int card, void *dest, const void *src, size_t n)
35 {
36 	unsigned long flags;
37 	void *ret;
38 	unsigned char ch;
39 
40 	if(!IS_VALID_CARD(card)) {
41 		pr_debug("Invalid param: %d is not a valid card id\n", card);
42 		return NULL;
43 	}
44 
45 	if(n > SRAM_PAGESIZE) {
46 		return NULL;
47 	}
48 
49 	/*
50 	 * determine the page to load from the address
51 	 */
52 	ch = (unsigned long) dest / SRAM_PAGESIZE;
53 	pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
54 	/*
55 	 * Block interrupts and load the page
56 	 */
57 	save_flags(flags);
58 	cli();
59 
60 	outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
61 		adapter[card]->ioport[adapter[card]->shmem_pgport]);
62 	pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
63 		((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
64 	ret = memcpy_toio(adapter[card]->rambase +
65 		((unsigned long) dest % 0x4000), src, n);
66 	pr_debug("%s: copying %d bytes from %#x to %#x\n",adapter[card]->devicename, n,
67 		 (unsigned long) src, adapter[card]->rambase + ((unsigned long) dest %0x4000));
68 	restore_flags(flags);
69 
70 	return ret;
71 }
72 
73 /*
74  * Reverse of above
75  */
memcpy_fromshmem(int card,void * dest,const void * src,size_t n)76 void *memcpy_fromshmem(int card, void *dest, const void *src, size_t n)
77 {
78 	unsigned long flags;
79 	void *ret;
80 	unsigned char ch;
81 
82 	if(!IS_VALID_CARD(card)) {
83 		pr_debug("Invalid param: %d is not a valid card id\n", card);
84 		return NULL;
85 	}
86 
87 	if(n > SRAM_PAGESIZE) {
88 		return NULL;
89 	}
90 
91 	/*
92 	 * determine the page to load from the address
93 	 */
94 	ch = (unsigned long) src / SRAM_PAGESIZE;
95 	pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
96 
97 
98 	/*
99 	 * Block interrupts and load the page
100 	 */
101 	save_flags(flags);
102 	cli();
103 
104 	outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
105 		adapter[card]->ioport[adapter[card]->shmem_pgport]);
106 	pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
107 		((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
108 	ret = memcpy_fromio(dest,(void *)(adapter[card]->rambase +
109 		((unsigned long) src % 0x4000)), n);
110 /*	pr_debug("%s: copying %d bytes from %#x to %#x\n",
111 		adapter[card]->devicename, n,
112 		adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
113 	restore_flags(flags);
114 
115 	return ret;
116 }
117 
memset_shmem(int card,void * dest,int c,size_t n)118 void *memset_shmem(int card, void *dest, int c, size_t n)
119 {
120 	unsigned long flags;
121 	unsigned char ch;
122 	void *ret;
123 
124 	if(!IS_VALID_CARD(card)) {
125 		pr_debug("Invalid param: %d is not a valid card id\n", card);
126 		return NULL;
127 	}
128 
129 	if(n > SRAM_PAGESIZE) {
130 		return NULL;
131 	}
132 
133 	/*
134 	 * determine the page to load from the address
135 	 */
136 	ch = (unsigned long) dest / SRAM_PAGESIZE;
137 	pr_debug("%s: loaded page %d\n",adapter[card]->devicename,ch);
138 
139 	/*
140 	 * Block interrupts and load the page
141 	 */
142 	save_flags(flags);
143 	cli();
144 
145 	outb(((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
146 		adapter[card]->ioport[adapter[card]->shmem_pgport]);
147 	pr_debug("%s: set page to %#x\n",adapter[card]->devicename,
148 		((adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
149 	ret = memset_io(adapter[card]->rambase +
150 		((unsigned long) dest % 0x4000), c, n);
151 	restore_flags(flags);
152 
153 	return ret;
154 }
155