diff options
author | Marcel Moolenaar <marcel@FreeBSD.org> | 2010-01-11 18:10:13 +0000 |
---|---|---|
committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2010-01-11 18:10:13 +0000 |
commit | 409a390c3341fb4f162cd7de1fd595a323ebbfd8 (patch) | |
tree | 834b257443dad54b930e9a553da6a313a6b0093e | |
parent | 5f5bb1d11ad3752c74a6e1db9c9d0aa3c2fd39ea (diff) |
Notes
-rw-r--r-- | sys/amd64/amd64/io.c | 9 | ||||
-rw-r--r-- | sys/amd64/include/iodev.h | 1 | ||||
-rw-r--r-- | sys/conf/files.ia64 | 2 | ||||
-rw-r--r-- | sys/dev/io/iodev.c | 3 | ||||
-rw-r--r-- | sys/i386/i386/io.c | 9 | ||||
-rw-r--r-- | sys/i386/include/iodev.h | 1 | ||||
-rw-r--r-- | sys/ia64/conf/DEFAULTS | 1 | ||||
-rw-r--r-- | sys/ia64/ia64/iodev_machdep.c | 160 | ||||
-rw-r--r-- | sys/ia64/ia64/sys_machdep.c | 63 | ||||
-rw-r--r-- | sys/ia64/include/iodev.h | 51 | ||||
-rw-r--r-- | sys/ia64/include/sysarch.h | 9 |
11 files changed, 235 insertions, 74 deletions
diff --git a/sys/amd64/amd64/io.c b/sys/amd64/amd64/io.c index 02d9c8dab230..09d6e8965822 100644 --- a/sys/amd64/amd64/io.c +++ b/sys/amd64/amd64/io.c @@ -76,3 +76,12 @@ ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused, return (0); } + +/* ARGSUSED */ +int +ioioctl(struct cdev *dev __unused, u_long cmd __unused, caddr_t data __unused, + int fflag __unused, struct thread *td __unused) +{ + + return (ENXIO); +} diff --git a/sys/amd64/include/iodev.h b/sys/amd64/include/iodev.h index 4b35d8b03fa2..1a0a17a9561e 100644 --- a/sys/amd64/include/iodev.h +++ b/sys/amd64/include/iodev.h @@ -28,3 +28,4 @@ d_open_t ioopen; d_close_t ioclose; +d_ioctl_t ioioctl; diff --git a/sys/conf/files.ia64 b/sys/conf/files.ia64 index e56faae6cc62..4c0c9dd8fc2b 100644 --- a/sys/conf/files.ia64 +++ b/sys/conf/files.ia64 @@ -54,6 +54,7 @@ dev/atkbdc/psm.c optional psm atkbdc dev/fb/fb.c optional fb | vga dev/fb/vga.c optional vga dev/hwpmc/hwpmc_ia64.c optional hwpmc +dev/io/iodev.c optional io dev/kbd/kbd.c optional atkbd | sc | ukbd | usb2_input_kbd dev/syscons/scterm-teken.c optional sc dev/syscons/scvgarndr.c optional sc vga @@ -86,6 +87,7 @@ ia64/ia64/gdb_machdep.c optional gdb ia64/ia64/highfp.c standard ia64/ia64/in_cksum.c optional inet ia64/ia64/interrupt.c standard +ia64/ia64/iodev_machdep.c optional io ia64/ia64/locore.S standard no-obj ia64/ia64/machdep.c standard ia64/ia64/mca.c standard diff --git a/sys/dev/io/iodev.c b/sys/dev/io/iodev.c index 8c2cebdf364a..b142a39c6107 100644 --- a/sys/dev/io/iodev.c +++ b/sys/dev/io/iodev.c @@ -41,8 +41,6 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/uio.h> -#include <machine/specialreg.h> - #include <vm/vm.h> #include <vm/pmap.h> @@ -54,6 +52,7 @@ static struct cdevsw io_cdevsw = { .d_version = D_VERSION, .d_open = ioopen, .d_close = ioclose, + .d_ioctl = ioioctl, .d_name = "io", }; diff --git a/sys/i386/i386/io.c b/sys/i386/i386/io.c index eb0deb67c5f4..c392af5f38da 100644 --- a/sys/i386/i386/io.c +++ b/sys/i386/i386/io.c @@ -76,3 +76,12 @@ ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused, return (0); } + +/* ARGSUSED */ +int +ioioctl(struct cdev *dev __unused, u_long cmd __unused, caddr_t data __unused, + int fflag __unused, struct thread *td __unused) +{ + + return (ENXIO); +} diff --git a/sys/i386/include/iodev.h b/sys/i386/include/iodev.h index 4b35d8b03fa2..1a0a17a9561e 100644 --- a/sys/i386/include/iodev.h +++ b/sys/i386/include/iodev.h @@ -28,3 +28,4 @@ d_open_t ioopen; d_close_t ioclose; +d_ioctl_t ioioctl; diff --git a/sys/ia64/conf/DEFAULTS b/sys/ia64/conf/DEFAULTS index 625ff90955cc..2cb2330054bb 100644 --- a/sys/ia64/conf/DEFAULTS +++ b/sys/ia64/conf/DEFAULTS @@ -9,6 +9,7 @@ machine ia64 device acpi # ACPI support # Pseudo devices. +device io # I/O & EFI runtime device device mem # Memory and kernel memory devices # UART chips on this platform diff --git a/sys/ia64/ia64/iodev_machdep.c b/sys/ia64/ia64/iodev_machdep.c new file mode 100644 index 000000000000..498a042cfce0 --- /dev/null +++ b/sys/ia64/ia64/iodev_machdep.c @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 2010 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/conf.h> +#include <sys/fcntl.h> +#include <sys/ioccom.h> +#include <sys/priv.h> +#include <sys/proc.h> +#include <sys/systm.h> + +#include <machine/bus.h> +#include <machine/iodev.h> + +static int iodev_pio_read(struct iodev_pio_req *req); +static int iodev_pio_write(struct iodev_pio_req *req); + +/* ARGSUSED */ +int +ioopen(struct cdev *dev __unused, int flags __unused, int fmt __unused, + struct thread *td) +{ + int error; + + error = priv_check(td, PRIV_IO); + if (error == 0) + error = securelevel_gt(td->td_ucred, 0); + + return (error); +} + +/* ARGSUSED */ +int +ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused, + struct thread *td __unused) +{ + + return (0); +} + +/* ARGSUSED */ +int +ioioctl(struct cdev *dev __unused, u_long cmd, caddr_t data, + int fflag __unused, struct thread *td __unused) +{ + struct iodev_pio_req *pio_req; + int error; + + error = ENOIOCTL; + switch (cmd) { + case IODEV_PIO: + pio_req = (struct iodev_pio_req *)data; + switch (pio_req->access) { + case IODEV_PIO_READ: + error = iodev_pio_read(pio_req); + break; + case IODEV_PIO_WRITE: + error = iodev_pio_write(pio_req); + break; + default: + error = EINVAL; + break; + } + break; + } + + return (error); +} + +static int +iodev_pio_read(struct iodev_pio_req *req) +{ + + switch (req->width) { + case 1: + req->val = bus_space_read_io_1(req->port); + break; + case 2: + if (req->port & 1) { + req->val = bus_space_read_io_1(req->port); + req->val |= bus_space_read_io_1(req->port + 1) << 8; + } else + req->val = bus_space_read_io_2(req->port); + break; + case 4: + if (req->port & 1) { + req->val = bus_space_read_io_1(req->port); + req->val |= bus_space_read_io_2(req->port + 1) << 8; + req->val |= bus_space_read_io_1(req->port + 3) << 24; + } else if (req->port & 2) { + req->val = bus_space_read_io_2(req->port); + req->val |= bus_space_read_io_2(req->port + 2) << 16; + } else + req->val = bus_space_read_io_4(req->port); + break; + default: + return (EINVAL); + } + + return (0); +} + +static int +iodev_pio_write(struct iodev_pio_req *req) +{ + + switch (req->width) { + case 1: + bus_space_write_io_1(req->port, req->val); + break; + case 2: + if (req->port & 1) { + bus_space_write_io_1(req->port, req->val); + bus_space_write_io_1(req->port + 1, req->val >> 8); + } else + bus_space_write_io_2(req->port, req->val); + break; + case 4: + if (req->port & 1) { + bus_space_write_io_1(req->port, req->val); + bus_space_write_io_2(req->port + 1, req->val >> 8); + bus_space_write_io_1(req->port + 3, req->val >> 24); + } else if (req->port & 2) { + bus_space_write_io_2(req->port, req->val); + bus_space_write_io_2(req->port + 2, req->val >> 16); + } else + bus_space_write_io_4(req->port, req->val); + break; + default: + return (EINVAL); + } + + return (0); +} diff --git a/sys/ia64/ia64/sys_machdep.c b/sys/ia64/ia64/sys_machdep.c index e39cbab621e6..764df2ea0276 100644 --- a/sys/ia64/ia64/sys_machdep.c +++ b/sys/ia64/ia64/sys_machdep.c @@ -49,72 +49,9 @@ struct sysarch_args { int sysarch(struct thread *td, struct sysarch_args *uap) { - struct ia64_iodesc iod; int error; - error = 0; switch(uap->op) { - case IA64_IORD: - copyin(uap->parms, &iod, sizeof(iod)); - switch (iod.width) { - case 1: - iod.val = inb(iod.port); - break; - case 2: - if (iod.port & 1) { - iod.val = inb(iod.port); - iod.val |= inb(iod.port + 1) << 8; - } else - iod.val = inw(iod.port); - break; - case 4: - if (iod.port & 3) { - if (iod.port & 1) { - iod.val = inb(iod.port); - iod.val |= inw(iod.port + 1) << 8; - iod.val |= inb(iod.port + 3) << 24; - } else { - iod.val = inw(iod.port); - iod.val |= inw(iod.port + 2) << 16; - } - } else - iod.val = inl(iod.port); - break; - default: - error = EINVAL; - } - copyout(&iod, uap->parms, sizeof(iod)); - break; - case IA64_IOWR: - copyin(uap->parms, &iod, sizeof(iod)); - switch (iod.width) { - case 1: - outb(iod.port, iod.val); - break; - case 2: - if (iod.port & 1) { - outb(iod.port, iod.val); - outb(iod.port + 1, iod.val >> 8); - } else - outw(iod.port, iod.val); - break; - case 4: - if (iod.port & 3) { - if (iod.port & 1) { - outb(iod.port, iod.val); - outw(iod.port + 1, iod.val >> 8); - outb(iod.port + 3, iod.val >> 24); - } else { - outw(iod.port, iod.val); - outw(iod.port + 2, iod.val >> 16); - } - } else - outl(iod.port, iod.val); - break; - default: - error = EINVAL; - } - break; default: error = EINVAL; break; diff --git a/sys/ia64/include/iodev.h b/sys/ia64/include/iodev.h new file mode 100644 index 000000000000..11d05fc1c21d --- /dev/null +++ b/sys/ia64/include/iodev.h @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2010 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_IODEV_H_ +#define _MACHINE_IODEV_H_ + +struct iodev_pio_req { + u_int access; +#define IODEV_PIO_READ 0 +#define IODEV_PIO_WRITE 1 + u_int port; + u_int width; + u_int val; +}; + +#define IODEV_PIO _IOWR('I', 0, struct iodev_pio_req) + +#ifdef _KERNEL + +d_open_t ioopen; +d_close_t ioclose; +d_ioctl_t ioioctl; + +#endif + +#endif /* _MACHINE_IODEV_H_ */ diff --git a/sys/ia64/include/sysarch.h b/sys/ia64/include/sysarch.h index a7f39de2ffe8..c46d100beea5 100644 --- a/sys/ia64/include/sysarch.h +++ b/sys/ia64/include/sysarch.h @@ -32,15 +32,6 @@ #ifndef _MACHINE_SYSARCH_H_ #define _MACHINE_SYSARCH_H_ -#define IA64_IORD 0 -#define IA64_IOWR 1 - -struct ia64_iodesc { - int port; - int width; - unsigned long val; -}; - #ifndef _KERNEL #include <sys/cdefs.h> |