Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shmem.c
Go to the documentation of this file.
1 /* $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 [email protected] 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  *
26  */
27 void memcpy_toshmem(int card, void *dest, const void *src, size_t n)
28 {
29  unsigned long flags;
30  unsigned char ch;
31  unsigned long dest_rem = ((unsigned long) dest) % 0x4000;
32 
33  if (!IS_VALID_CARD(card)) {
34  pr_debug("Invalid param: %d is not a valid card id\n", card);
35  return;
36  }
37 
38  if (n > SRAM_PAGESIZE)
39  return;
40 
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]);
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,
59  (unsigned long) src,
60  sc_adapter[card]->rambase + ((unsigned long) dest % 0x4000));
61 }
62 
63 /*
64  * Reverse of above
65  */
66 void 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 
104 #if 0
105 void 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 }
138 #endif /* 0 */