blob: d24506ceb6e8764b4b19c775c68ead3334fbe18e [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;
Joe Perches475be4d2012-02-19 19:52:38 -080045 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename, ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 /*
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,
Joe Perches475be4d2012-02-19 19:52:38 -080052 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);
Joe Perches475be4d2012-02-19 19:52:38 -080055 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",
Joe Perches475be4d2012-02-19 19:52:38 -080058 sc_adapter[card]->devicename, n,
59 (unsigned long) src,
60 sc_adapter[card]->rambase + ((unsigned long) dest % 0x4000));
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
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
Joe Perches475be4d2012-02-19 19:52:38 -080071 if (!IS_VALID_CARD(card)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 pr_debug("Invalid param: %d is not a valid card id\n", card);
73 return;
74 }
75
Joe Perches475be4d2012-02-19 19:52:38 -080076 if (n > SRAM_PAGESIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return;
78 }
79
80 /*
81 * determine the page to load from the address
82 */
83 ch = (unsigned long) src / SRAM_PAGESIZE;
Joe Perches475be4d2012-02-19 19:52:38 -080084 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename, ch);
85
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /*
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,
Joe Perches475be4d2012-02-19 19:52:38 -080093 sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]);
94 memcpy_fromio(dest, (void *)(sc_adapter[card]->rambase +
95 ((unsigned long) src % 0x4000)), n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
Joe Perches475be4d2012-02-19 19:52:38 -080097 pr_debug("%s: set page to %#x\n", sc_adapter[card]->devicename,
98 ((sc_adapter[card]->shmem_magic + ch * SRAM_PAGESIZE) >> 14) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* pr_debug("%s: copying %d bytes from %#x to %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800100 sc_adapter[card]->devicename, n,
101 sc_adapter[card]->rambase + ((unsigned long) src %0x4000), (unsigned long) dest); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
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
Joe Perches475be4d2012-02-19 19:52:38 -0800110 if (!IS_VALID_CARD(card)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 pr_debug("Invalid param: %d is not a valid card id\n", card);
112 return;
113 }
114
Joe Perches475be4d2012-02-19 19:52:38 -0800115 if (n > SRAM_PAGESIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return;
117 }
118
119 /*
120 * determine the page to load from the address
121 */
122 ch = (unsigned long) dest / SRAM_PAGESIZE;
Joe Perches475be4d2012-02-19 19:52:38 -0800123 pr_debug("%s: loaded page %d\n", sc_adapter[card]->devicename, ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
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,
Joe Perches475be4d2012-02-19 19:52:38 -0800131 sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 memset_io(sc_adapter[card]->rambase +
Joe Perches475be4d2012-02-19 19:52:38 -0800133 ((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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
137}
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700138#endif /* 0 */