[CRYPTO] cryptomgr: Fix use after free
[linux-drm-fsl-dcu.git] / arch / sh / boards / landisk / io.c
1 /*
2  * arch/sh/boards/landisk/io.c
3  *
4  * Copyright (C) 2001  Ian da Silva, Jeremy Siegel
5  * Based largely on io_se.c.
6  *
7  * I/O routine for I-O Data Device, Inc. LANDISK.
8  *
9  * Initial version only to support LAN access; some
10  * placeholder code from io_landisk.c left in with the
11  * expectation of later SuperIO and PCMCIA access.
12  */
13 /*
14  * modifed by kogiidena
15  * 2005.03.03
16  */
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/pci.h>
20 #include <asm/landisk/iodata_landisk.h>
21 #include <asm/addrspace.h>
22 #include <asm/io.h>
23
24 extern void *area5_io_base;     /* Area 5 I/O Base address */
25 extern void *area6_io_base;     /* Area 6 I/O Base address */
26
27 static inline unsigned long port2adr(unsigned int port)
28 {
29         if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
30                 if (port == 0x3f6)
31                         return ((unsigned long)area5_io_base + 0x2c);
32                 else
33                         return ((unsigned long)area5_io_base + PA_PIDE_OFFSET +
34                                 ((port - 0x1f0) << 1));
35         else if ((0x170 <= port && port < 0x178) || port == 0x376)
36                 if (port == 0x376)
37                         return ((unsigned long)area6_io_base + 0x2c);
38                 else
39                         return ((unsigned long)area6_io_base + PA_SIDE_OFFSET +
40                                 ((port - 0x170) << 1));
41         else
42                 maybebadio((unsigned long)port);
43
44         return port;
45 }
46
47 /*
48  * General outline: remap really low stuff [eventually] to SuperIO,
49  * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
50  * is mapped through the PCI IO window.  Stuff with high bits (PXSEG)
51  * should be way beyond the window, and is used  w/o translation for
52  * compatibility.
53  */
54 u8 landisk_inb(unsigned long port)
55 {
56         if (PXSEG(port))
57                 return ctrl_inb(port);
58         else if (is_pci_ioaddr(port))
59                 return ctrl_inb(pci_ioaddr(port));
60
61         return ctrl_inw(port2adr(port)) & 0xff;
62 }
63
64 u8 landisk_inb_p(unsigned long port)
65 {
66         u8 v;
67
68         if (PXSEG(port))
69                 v = ctrl_inb(port);
70         else if (is_pci_ioaddr(port))
71                 v = ctrl_inb(pci_ioaddr(port));
72         else
73                 v = ctrl_inw(port2adr(port)) & 0xff;
74
75         ctrl_delay();
76
77         return v;
78 }
79
80 u16 landisk_inw(unsigned long port)
81 {
82         if (PXSEG(port))
83                 return ctrl_inw(port);
84         else if (is_pci_ioaddr(port))
85                 return ctrl_inw(pci_ioaddr(port));
86         else
87                 maybebadio(port);
88
89         return 0;
90 }
91
92 u32 landisk_inl(unsigned long port)
93 {
94         if (PXSEG(port))
95                 return ctrl_inl(port);
96         else if (is_pci_ioaddr(port))
97                 return ctrl_inl(pci_ioaddr(port));
98         else
99                 maybebadio(port);
100
101         return 0;
102 }
103
104 void landisk_outb(u8 value, unsigned long port)
105 {
106         if (PXSEG(port))
107                 ctrl_outb(value, port);
108         else if (is_pci_ioaddr(port))
109                 ctrl_outb(value, pci_ioaddr(port));
110         else
111                 ctrl_outw(value, port2adr(port));
112 }
113
114 void landisk_outb_p(u8 value, unsigned long port)
115 {
116         if (PXSEG(port))
117                 ctrl_outb(value, port);
118         else if (is_pci_ioaddr(port))
119                 ctrl_outb(value, pci_ioaddr(port));
120         else
121                 ctrl_outw(value, port2adr(port));
122         ctrl_delay();
123 }
124
125 void landisk_outw(u16 value, unsigned long port)
126 {
127         if (PXSEG(port))
128                 ctrl_outw(value, port);
129         else if (is_pci_ioaddr(port))
130                 ctrl_outw(value, pci_ioaddr(port));
131         else
132                 maybebadio(port);
133 }
134
135 void landisk_outl(u32 value, unsigned long port)
136 {
137         if (PXSEG(port))
138                 ctrl_outl(value, port);
139         else if (is_pci_ioaddr(port))
140                 ctrl_outl(value, pci_ioaddr(port));
141         else
142                 maybebadio(port);
143 }
144
145 void landisk_insb(unsigned long port, void *dst, unsigned long count)
146 {
147         volatile u16 *p;
148         u8 *buf = dst;
149
150         if (PXSEG(port)) {
151                 while (count--)
152                         *buf++ = *(volatile u8 *)port;
153         } else if (is_pci_ioaddr(port)) {
154                 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
155
156                 while (count--)
157                         *buf++ = *bp;
158         } else {
159                 p = (volatile u16 *)port2adr(port);
160                 while (count--)
161                         *buf++ = *p & 0xff;
162         }
163 }
164
165 void landisk_insw(unsigned long port, void *dst, unsigned long count)
166 {
167         volatile u16 *p;
168         u16 *buf = dst;
169
170         if (PXSEG(port))
171                 p = (volatile u16 *)port;
172         else if (is_pci_ioaddr(port))
173                 p = (volatile u16 *)pci_ioaddr(port);
174         else
175                 p = (volatile u16 *)port2adr(port);
176         while (count--)
177                 *buf++ = *p;
178 }
179
180 void landisk_insl(unsigned long port, void *dst, unsigned long count)
181 {
182         u32 *buf = dst;
183
184         if (is_pci_ioaddr(port)) {
185                 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
186
187                 while (count--)
188                         *buf++ = *p;
189         } else
190                 maybebadio(port);
191 }
192
193 void landisk_outsb(unsigned long port, const void *src, unsigned long count)
194 {
195         volatile u16 *p;
196         const u8 *buf = src;
197
198         if (PXSEG(port))
199                 while (count--)
200                         ctrl_outb(*buf++, port);
201         else if (is_pci_ioaddr(port)) {
202                 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
203
204                 while (count--)
205                         *bp = *buf++;
206         } else {
207                 p = (volatile u16 *)port2adr(port);
208                 while (count--)
209                         *p = *buf++;
210         }
211 }
212
213 void landisk_outsw(unsigned long port, const void *src, unsigned long count)
214 {
215         volatile u16 *p;
216         const u16 *buf = src;
217
218         if (PXSEG(port))
219                 p = (volatile u16 *)port;
220         else if (is_pci_ioaddr(port))
221                 p = (volatile u16 *)pci_ioaddr(port);
222         else
223                 p = (volatile u16 *)port2adr(port);
224
225         while (count--)
226                 *p = *buf++;
227 }
228
229 void landisk_outsl(unsigned long port, const void *src, unsigned long count)
230 {
231         const u32 *buf = src;
232
233         if (is_pci_ioaddr(port)) {
234                 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
235
236                 while (count--)
237                         *p = *buf++;
238         } else
239                 maybebadio(port);
240 }
241
242 void __iomem *landisk_ioport_map(unsigned long port, unsigned int size)
243 {
244         if (PXSEG(port))
245                 return (void __iomem *)port;
246         else if (is_pci_ioaddr(port))
247                 return (void __iomem *)pci_ioaddr(port);
248
249         return (void __iomem *)port2adr(port);
250 }