]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/arm/ioperm.c
1 /* Copyright (C) 1998-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Phil Blundell, based on the Alpha version by
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
20 /* I/O port access on the ARM is something of a fiction. What we do is to
21 map an appropriate area of /dev/mem into user space so that a program
22 can blast away at the hardware in such a way as to generate I/O cycles
23 on the bus. To insulate user code from dependencies on particular
24 hardware we don't allow calls to inb() and friends to be inlined, but
25 force them to come through code in here every time. Performance-critical
26 registers tend to be memory mapped these days so this should be no big
29 /* Once upon a time this file used mprotect to enable and disable
30 access to particular areas of I/O space. Unfortunately the
31 mprotect syscall also has the side effect of enabling caching for
32 the area affected (this is a kernel limitation). So we now just
33 enable all the ports all of the time. */
42 #include <sys/types.h>
45 #include <sys/sysctl.h>
47 #define MAX_PORT 0x10000
50 unsigned long int base
;
51 unsigned long int io_base
;
53 unsigned int initdone
; /* since all the above could be 0 */
56 #define IO_ADDR(port) (io.base + ((port) << io.shift))
59 * Initialize I/O system. The io_bae and port_shift values are fetched
60 * using sysctl (CTL_BUS, CTL_BUS_ISA, ISA_*).
66 static int iobase_name
[] = { CTL_BUS
, CTL_BUS_ISA
, BUS_ISA_PORT_BASE
};
67 static int ioshift_name
[] = { CTL_BUS
, CTL_BUS_ISA
, BUS_ISA_PORT_SHIFT
};
68 size_t len
= sizeof(io
.base
);
70 if (! __sysctl (iobase_name
, 3, &io
.io_base
, &len
, NULL
, 0)
71 && ! __sysctl (ioshift_name
, 3, &io
.shift
, &len
, NULL
, 0))
77 /* sysctl has failed... */
83 _ioperm (unsigned long int from
, unsigned long int num
, int turn_on
)
85 if (! io
.initdone
&& init_iosys () < 0)
88 /* this test isn't as silly as it may look like; consider overflows! */
89 if (from
>= MAX_PORT
|| from
+ num
> MAX_PORT
)
101 fd
= __open ("/dev/mem", O_RDWR
);
106 (unsigned long int) __mmap (0, MAX_PORT
<< io
.shift
,
107 PROT_READ
| PROT_WRITE
,
108 MAP_SHARED
, fd
, io
.io_base
);
110 if ((long) io
.base
== -1)
120 _iopl (unsigned int level
)
124 __set_errno (EINVAL
);
129 return _ioperm (0, MAX_PORT
, 1);
136 _outb (unsigned char b
, unsigned long int port
)
138 *((volatile unsigned char *)(IO_ADDR (port
))) = b
;
143 _outw (unsigned short b
, unsigned long int port
)
145 *((volatile unsigned short *)(IO_ADDR (port
))) = b
;
150 _outl (unsigned int b
, unsigned long int port
)
152 *((volatile unsigned long *)(IO_ADDR (port
))) = b
;
157 _inb (unsigned long int port
)
159 return *((volatile unsigned char *)(IO_ADDR (port
)));
164 _inw (unsigned long int port
)
166 return *((volatile unsigned short *)(IO_ADDR (port
)));
171 _inl (unsigned long int port
)
173 return *((volatile unsigned long *)(IO_ADDR (port
)));
176 weak_alias (_ioperm
, ioperm
);
177 weak_alias (_iopl
, iopl
);
178 weak_alias (_inb
, inb
);
179 weak_alias (_inw
, inw
);
180 weak_alias (_inl
, inl
);
181 weak_alias (_outb
, outb
);
182 weak_alias (_outw
, outw
);
183 weak_alias (_outl
, outl
);