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
)
31 unsigned long dest_rem
= ((unsigned long) dest
) % 0x4000;
33 if (!IS_VALID_CARD(card
)) {
34 pr_debug("Invalid param: %d is not a valid card id\n", card
);
38 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((void __iomem
*)(sc_adapter
[card
]->rambase
+ dest_rem
), src
, n
);
54 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);
57 pr_debug("%s: copying %zu bytes from %#lx to %#lx\n",
58 sc_adapter
[card
]->devicename
, n
,
60 sc_adapter
[card
]->rambase
+ ((unsigned long) dest
%0x4000));
66 void memcpy_fromshmem(int card
, void *dest
, const void *src
, size_t n
)
71 if(!IS_VALID_CARD(card
)) {
72 pr_debug("Invalid param: %d is not a valid card id\n", card
);
76 if(n
> SRAM_PAGESIZE
) {
81 * determine the page to load from the address
83 ch
= (unsigned long) src
/ SRAM_PAGESIZE
;
84 pr_debug("%s: loaded page %d\n", sc_adapter
[card
]->devicename
,ch
);
88 * Block interrupts and load the page
90 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
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); */
105 void memset_shmem(int card
, void *dest
, int c
, size_t n
)
110 if(!IS_VALID_CARD(card
)) {
111 pr_debug("Invalid param: %d is not a valid card id\n", card
);
115 if(n
> SRAM_PAGESIZE
) {
120 * determine the page to load from the address
122 ch
= (unsigned long) dest
/ SRAM_PAGESIZE
;
123 pr_debug("%s: loaded page %d\n",sc_adapter
[card
]->devicename
,ch
);
126 * Block interrupts and load the page
128 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
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
);