blob: 24854826ca4599842fd7165f4de12f548f1f9b45 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $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/*
25 * Main adapter array
26 */
27extern board *sc_adapter[];
28extern int cinst;
29
30/*
31 *
32 */
33void memcpy_toshmem(int card, void *dest, const void *src, size_t n)
34{
35 unsigned long flags;
36 unsigned char ch;
37
38 if(!IS_VALID_CARD(card)) {
39 pr_debug("Invalid param: %d is not a valid card id\n", card);
40 return;
41 }
42
43 if(n > SRAM_PAGESIZE) {
44 return;
45 }
46
47 /*
48 * determine the page to load from the address
49 */
50 ch = (unsigned long) dest / SRAM_PAGESIZE;
51 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch);
52 /*
53 * Block interrupts and load the page
54 */
55 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
56
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,
66 (unsigned long) src,
67 sc_adapter[card]->rambase + ((unsigned long) dest %0x4000));
68}
69
70/*
71 * Reverse of above
72 */
73void memcpy_fromshmem(int card, void *dest, const void *src, size_t n)
74{
75 unsigned long flags;
76 unsigned char ch;
77
78 if(!IS_VALID_CARD(card)) {
79 pr_debug("Invalid param: %d is not a valid card id\n", card);
80 return;
81 }
82
83 if(n > SRAM_PAGESIZE) {
84 return;
85 }
86
87 /*
88 * determine the page to load from the address
89 */
90 ch = (unsigned long) src / SRAM_PAGESIZE;
91 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch);
92
93
94 /*
95 * Block interrupts and load the page
96 */
97 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
98
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); */
109}
110
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700111#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112void memset_shmem(int card, void *dest, int c, size_t n)
113{
114 unsigned long flags;
115 unsigned char ch;
116
117 if(!IS_VALID_CARD(card)) {
118 pr_debug("Invalid param: %d is not a valid card id\n", card);
119 return;
120 }
121
122 if(n > SRAM_PAGESIZE) {
123 return;
124 }
125
126 /*
127 * determine the page to load from the address
128 */
129 ch = (unsigned long) dest / SRAM_PAGESIZE;
130 pr_debug("%s: loaded page %d\n",sc_adapter[card]->devicename,ch);
131
132 /*
133 * Block interrupts and load the page
134 */
135 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
136
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);
144}
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700145#endif /* 0 */