iodev_machdep.c (202273) | iodev_machdep.c (207329) |
---|---|
1/*- 2 * Copyright (c) 2010 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2010 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/ia64/ia64/iodev_machdep.c 202273 2010-01-14 02:48:39Z marcel $"); | 28__FBSDID("$FreeBSD: head/sys/ia64/ia64/iodev_machdep.c 207329 2010-04-28 15:38:01Z attilio $"); |
29 30#include <sys/param.h> 31#include <sys/conf.h> 32#include <sys/fcntl.h> 33#include <sys/ioccom.h> 34#include <sys/malloc.h> 35#include <sys/priv.h> 36#include <sys/proc.h> 37#include <sys/systm.h> 38 39#include <machine/bus.h> 40#include <machine/efi.h> 41#include <machine/iodev.h> 42 | 29 30#include <sys/param.h> 31#include <sys/conf.h> 32#include <sys/fcntl.h> 33#include <sys/ioccom.h> 34#include <sys/malloc.h> 35#include <sys/priv.h> 36#include <sys/proc.h> 37#include <sys/systm.h> 38 39#include <machine/bus.h> 40#include <machine/efi.h> 41#include <machine/iodev.h> 42 |
43static int iodev_pio_read(struct iodev_pio_req *req); 44static int iodev_pio_write(struct iodev_pio_req *req); 45 | |
46static int iodev_efivar_getvar(struct iodev_efivar_req *req); 47static int iodev_efivar_nextname(struct iodev_efivar_req *req); 48static int iodev_efivar_setvar(struct iodev_efivar_req *req); 49 50/* ARGSUSED */ 51int | 43static int iodev_efivar_getvar(struct iodev_efivar_req *req); 44static int iodev_efivar_nextname(struct iodev_efivar_req *req); 45static int iodev_efivar_setvar(struct iodev_efivar_req *req); 46 47/* ARGSUSED */ 48int |
52ioopen(struct cdev *dev __unused, int flags __unused, int fmt __unused, 53 struct thread *td) | 49iodev_open(struct thread *td __unused) |
54{ | 50{ |
55 int error; | |
56 | 51 |
57 error = priv_check(td, PRIV_IO); 58 if (error == 0) 59 error = securelevel_gt(td->td_ucred, 0); 60 61 return (error); | 52 return (0); |
62} 63 64/* ARGSUSED */ 65int | 53} 54 55/* ARGSUSED */ 56int |
66ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused, 67 struct thread *td __unused) | 57iodev_close(struct thread *td __unused) |
68{ 69 70 return (0); 71} 72 | 58{ 59 60 return (0); 61} 62 |
73/* ARGSUSED */ | |
74int | 63int |
75ioioctl(struct cdev *dev __unused, u_long cmd, caddr_t data, 76 int fflag __unused, struct thread *td __unused) | 64iodev_ioctl(u_long cmd, caddr_t data) |
77{ 78 struct iodev_efivar_req *efivar_req; | 65{ 66 struct iodev_efivar_req *efivar_req; |
79 struct iodev_pio_req *pio_req; | |
80 int error; 81 | 67 int error; 68 |
82 error = ENOIOCTL; | |
83 switch (cmd) { | 69 switch (cmd) { |
84 case IODEV_PIO: 85 pio_req = (struct iodev_pio_req *)data; 86 switch (pio_req->access) { 87 case IODEV_PIO_READ: 88 error = iodev_pio_read(pio_req); 89 break; 90 case IODEV_PIO_WRITE: 91 error = iodev_pio_write(pio_req); 92 break; 93 default: 94 error = EINVAL; 95 break; 96 } 97 break; | |
98 case IODEV_EFIVAR: 99 efivar_req = (struct iodev_efivar_req *)data; 100 efivar_req->result = 0; /* So it's well-defined */ 101 switch (efivar_req->access) { 102 case IODEV_EFIVAR_GETVAR: 103 error = iodev_efivar_getvar(efivar_req); 104 break; 105 case IODEV_EFIVAR_NEXTNAME: 106 error = iodev_efivar_nextname(efivar_req); 107 break; 108 case IODEV_EFIVAR_SETVAR: 109 error = iodev_efivar_setvar(efivar_req); 110 break; 111 default: 112 error = EINVAL; 113 break; 114 } 115 break; | 70 case IODEV_EFIVAR: 71 efivar_req = (struct iodev_efivar_req *)data; 72 efivar_req->result = 0; /* So it's well-defined */ 73 switch (efivar_req->access) { 74 case IODEV_EFIVAR_GETVAR: 75 error = iodev_efivar_getvar(efivar_req); 76 break; 77 case IODEV_EFIVAR_NEXTNAME: 78 error = iodev_efivar_nextname(efivar_req); 79 break; 80 case IODEV_EFIVAR_SETVAR: 81 error = iodev_efivar_setvar(efivar_req); 82 break; 83 default: 84 error = EINVAL; 85 break; 86 } 87 break; |
88 default: 89 error = ENOIOCTL; |
|
116 } 117 118 return (error); 119} 120 121static int | 90 } 91 92 return (error); 93} 94 95static int |
122iodev_pio_read(struct iodev_pio_req *req) 123{ 124 125 switch (req->width) { 126 case 1: 127 req->val = bus_space_read_io_1(req->port); 128 break; 129 case 2: 130 if (req->port & 1) { 131 req->val = bus_space_read_io_1(req->port); 132 req->val |= bus_space_read_io_1(req->port + 1) << 8; 133 } else 134 req->val = bus_space_read_io_2(req->port); 135 break; 136 case 4: 137 if (req->port & 1) { 138 req->val = bus_space_read_io_1(req->port); 139 req->val |= bus_space_read_io_2(req->port + 1) << 8; 140 req->val |= bus_space_read_io_1(req->port + 3) << 24; 141 } else if (req->port & 2) { 142 req->val = bus_space_read_io_2(req->port); 143 req->val |= bus_space_read_io_2(req->port + 2) << 16; 144 } else 145 req->val = bus_space_read_io_4(req->port); 146 break; 147 default: 148 return (EINVAL); 149 } 150 151 return (0); 152} 153 154static int 155iodev_pio_write(struct iodev_pio_req *req) 156{ 157 158 switch (req->width) { 159 case 1: 160 bus_space_write_io_1(req->port, req->val); 161 break; 162 case 2: 163 if (req->port & 1) { 164 bus_space_write_io_1(req->port, req->val); 165 bus_space_write_io_1(req->port + 1, req->val >> 8); 166 } else 167 bus_space_write_io_2(req->port, req->val); 168 break; 169 case 4: 170 if (req->port & 1) { 171 bus_space_write_io_1(req->port, req->val); 172 bus_space_write_io_2(req->port + 1, req->val >> 8); 173 bus_space_write_io_1(req->port + 3, req->val >> 24); 174 } else if (req->port & 2) { 175 bus_space_write_io_2(req->port, req->val); 176 bus_space_write_io_2(req->port + 2, req->val >> 16); 177 } else 178 bus_space_write_io_4(req->port, req->val); 179 break; 180 default: 181 return (EINVAL); 182 } 183 184 return (0); 185} 186 187static int | |
188iodev_efivar_getvar(struct iodev_efivar_req *req) 189{ 190 void *data; 191 efi_char *name; 192 int error; 193 194 if ((req->namesize & 1) != 0 || req->namesize < 4) 195 return (EINVAL); --- 105 unchanged lines hidden --- | 96iodev_efivar_getvar(struct iodev_efivar_req *req) 97{ 98 void *data; 99 efi_char *name; 100 int error; 101 102 if ((req->namesize & 1) != 0 || req->namesize < 4) 103 return (EINVAL); --- 105 unchanged lines hidden --- |