1 /* $Id: shmem.c,v 1.2.10.1 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * Card functions implementing ISDN4Linux functionality
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
10 * For more information, please contact gpl-info@spellcast.com or write:
12 * SpellCaster Telecommunications Inc.
13 * 5621 Finch Avenue East, Unit #3
14 * Scarborough, Ontario Canada
17 * +1 (416) 297-6433 Facsimile
20 #include "includes.h" /* This must be first */
27 extern board
*sc_adapter
[];
33 void memcpy_toshmem(int card
, void *dest
, const void *src
, size_t n
)
38 if(!IS_VALID_CARD(card
)) {
39 pr_debug("Invalid param: %d is not a valid card id\n", card
);
43 if(n
> SRAM_PAGESIZE
) {
48 * determine the page to load from the address
50 ch
= (unsigned long) dest
/ SRAM_PAGESIZE
;
51 pr_debug("%s: loaded page %d\n", sc_adapter
[card
]->devicename
,ch
);
53 * Block interrupts and load the page
55 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
57 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
58 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
59 memcpy_toio(sc_adapter
[card
]->rambase
+
60 ((unsigned long) dest
% 0x4000), src
, n
);
61 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
62 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
63 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
64 pr_debug("%s: copying %d bytes from %#x to %#x\n",
65 sc_adapter
[card
]->devicename
, n
,
67 sc_adapter
[card
]->rambase
+ ((unsigned long) dest
%0x4000));
73 void memcpy_fromshmem(int card
, void *dest
, const void *src
, size_t n
)
78 if(!IS_VALID_CARD(card
)) {
79 pr_debug("Invalid param: %d is not a valid card id\n", card
);
83 if(n
> SRAM_PAGESIZE
) {
88 * determine the page to load from the address
90 ch
= (unsigned long) src
/ SRAM_PAGESIZE
;
91 pr_debug("%s: loaded page %d\n", sc_adapter
[card
]->devicename
,ch
);
95 * Block interrupts and load the page
97 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
99 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
100 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
101 memcpy_fromio(dest
,(void *)(sc_adapter
[card
]->rambase
+
102 ((unsigned long) src
% 0x4000)), n
);
103 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
104 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
105 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
106 /* pr_debug("%s: copying %d bytes from %#x to %#x\n",
107 sc_adapter[card]->devicename, n,
108 sc_adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
112 void memset_shmem(int card
, void *dest
, int c
, size_t n
)
117 if(!IS_VALID_CARD(card
)) {
118 pr_debug("Invalid param: %d is not a valid card id\n", card
);
122 if(n
> SRAM_PAGESIZE
) {
127 * determine the page to load from the address
129 ch
= (unsigned long) dest
/ SRAM_PAGESIZE
;
130 pr_debug("%s: loaded page %d\n",sc_adapter
[card
]->devicename
,ch
);
133 * Block interrupts and load the page
135 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
137 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
138 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
139 memset_io(sc_adapter
[card
]->rambase
+
140 ((unsigned long) dest
% 0x4000), c
, n
);
141 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
142 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
143 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);