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 void memcpy_toshmem(int card
, void *dest
, const void *src
, size_t n
)
32 if(!IS_VALID_CARD(card
)) {
33 pr_debug("Invalid param: %d is not a valid card id\n", card
);
37 if(n
> SRAM_PAGESIZE
) {
42 * determine the page to load from the address
44 ch
= (unsigned long) dest
/ SRAM_PAGESIZE
;
45 pr_debug("%s: loaded page %d\n", sc_adapter
[card
]->devicename
,ch
);
47 * Block interrupts and load the page
49 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
51 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
52 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
53 memcpy_toio(sc_adapter
[card
]->rambase
+
54 ((unsigned long) dest
% 0x4000), src
, n
);
55 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
56 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
57 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
58 pr_debug("%s: copying %d bytes from %#lx to %#lx\n",
59 sc_adapter
[card
]->devicename
, n
,
61 sc_adapter
[card
]->rambase
+ ((unsigned long) dest
%0x4000));
67 void memcpy_fromshmem(int card
, void *dest
, const void *src
, size_t n
)
72 if(!IS_VALID_CARD(card
)) {
73 pr_debug("Invalid param: %d is not a valid card id\n", card
);
77 if(n
> SRAM_PAGESIZE
) {
82 * determine the page to load from the address
84 ch
= (unsigned long) src
/ SRAM_PAGESIZE
;
85 pr_debug("%s: loaded page %d\n", sc_adapter
[card
]->devicename
,ch
);
89 * Block interrupts and load the page
91 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
93 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
94 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
95 memcpy_fromio(dest
,(void *)(sc_adapter
[card
]->rambase
+
96 ((unsigned long) src
% 0x4000)), n
);
97 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
98 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
99 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
100 /* pr_debug("%s: copying %d bytes from %#x to %#x\n",
101 sc_adapter[card]->devicename, n,
102 sc_adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
106 void memset_shmem(int card
, void *dest
, int c
, size_t n
)
111 if(!IS_VALID_CARD(card
)) {
112 pr_debug("Invalid param: %d is not a valid card id\n", card
);
116 if(n
> SRAM_PAGESIZE
) {
121 * determine the page to load from the address
123 ch
= (unsigned long) dest
/ SRAM_PAGESIZE
;
124 pr_debug("%s: loaded page %d\n",sc_adapter
[card
]->devicename
,ch
);
127 * Block interrupts and load the page
129 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
131 outb(((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
) >> 14) | 0x80,
132 sc_adapter
[card
]->ioport
[sc_adapter
[card
]->shmem_pgport
]);
133 memset_io(sc_adapter
[card
]->rambase
+
134 ((unsigned long) dest
% 0x4000), c
, n
);
135 pr_debug("%s: set page to %#x\n",sc_adapter
[card
]->devicename
,
136 ((sc_adapter
[card
]->shmem_magic
+ ch
* SRAM_PAGESIZE
)>>14)|0x80);
137 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);