blob: 7f16d75d2d89fa1137cad8651e765eb9b4a512e2 [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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 */
27void memcpy_toshmem(int card, void *dest, const void *src, size_t n)
28{
29 unsigned long flags;
30 unsigned char ch;
Jeff Garzik9317d432007-10-23 18:36:39 -040031 unsigned long dest_rem = ((unsigned long) dest) % 0x4000;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Jeff Garzik9317d432007-10-23 18:36:39 -040033 if (!IS_VALID_CARD(card)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 pr_debug("Invalid param: %d is not a valid card id\n", card);
35 return;
36 }
37
Jeff Garzik9317d432007-10-23 18:36:39 -040038 if (n > SRAM_PAGESIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 /*
42 * determine the page to load from the address
43 */
44 ch = (unsigned long) dest / SRAM_PAGESIZE;
45 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch);
46 /*
47 * Block interrupts and load the page
48 */
49 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
50
51 outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
52 sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]);
Frank Lichtenheld66ba8862007-11-14 15:59:43 -080053 memcpy_toio((void __iomem *)(sc_adapter[card]->rambase + dest_rem), src, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
55 pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename,
56 ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
Randy Dunlap0d5048a2009-02-20 00:54:44 -080057 pr_debug("%s: copying %zu bytes from %#lx to %#lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 sc_adapter[card]->devicename, n,
59 (unsigned long) src,
60 sc_adapter[card]->rambase + ((unsigned long) dest %0x4000));
61}
62
63/*
64 * Reverse of above
65 */
66void memcpy_fromshmem(int card, void *dest, const void *src, size_t n)
67{
68 unsigned long flags;
69 unsigned char ch;
70
71 if(!IS_VALID_CARD(card)) {
72 pr_debug("Invalid param: %d is not a valid card id\n", card);
73 return;
74 }
75
76 if(n > SRAM_PAGESIZE) {
77 return;
78 }
79
80 /*
81 * determine the page to load from the address
82 */
83 ch = (unsigned long) src / SRAM_PAGESIZE;
84 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename,ch);
85
86
87 /*
88 * Block interrupts and load the page
89 */
90 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
91
92 outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
93 sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]);
94 memcpy_fromio(dest,(void *)(sc_adapter[card]->rambase +
95 ((unsigned long) src % 0x4000)), n);
96 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
97 pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename,
98 ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
99/* pr_debug("%s: copying %d bytes from %#x to %#x\n",
100 sc_adapter[card]->devicename, n,
101 sc_adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
102}
103
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700104#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105void memset_shmem(int card, void *dest, int c, size_t n)
106{
107 unsigned long flags;
108 unsigned char ch;
109
110 if(!IS_VALID_CARD(card)) {
111 pr_debug("Invalid param: %d is not a valid card id\n", card);
112 return;
113 }
114
115 if(n > SRAM_PAGESIZE) {
116 return;
117 }
118
119 /*
120 * determine the page to load from the address
121 */
122 ch = (unsigned long) dest / SRAM_PAGESIZE;
123 pr_debug("%s: loaded page %d\n",sc_adapter[card]->devicename,ch);
124
125 /*
126 * Block interrupts and load the page
127 */
128 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
129
130 outb(((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80,
131 sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]);
132 memset_io(sc_adapter[card]->rambase +
133 ((unsigned long) dest % 0x4000), c, n);
134 pr_debug("%s: set page to %#x\n",sc_adapter[card]->devicename,
135 ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE)>>14)|0x80);
136 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
137}
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700138#endif /* 0 */