|
|
1.1.1.3 ! root 1: /* 1.1 root 2: * Mach device server routines (i386at version). 3: * 4: * Copyright (c) 1996 The University of Utah and 5: * the Computer Systems Laboratory at the University of Utah (CSL). 6: * All rights reserved. 7: * 8: * Permission to use, copy, modify and distribute this software is hereby 9: * granted provided that (1) source code retains these copyright, permission, 10: * and disclaimer notices, and (2) redistributions including binaries 11: * reproduce the notices in supporting documentation, and (3) all advertising 12: * materials mentioning features or use of this software display the following 13: * acknowledgement: ``This product includes software developed by the 14: * Computer Systems Laboratory at the University of Utah.'' 15: * 16: * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS 17: * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF 18: * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19: * 20: * CSL requests users of this software to return to [email protected] any 21: * improvements that they make and grant CSL redistribution rights. 22: * 23: * Author: Shantanu Goel, University of Utah CSL 24: */ 25: 26: #include <mach/boolean.h> 27: #include <mach/kern_return.h> 28: #include <mach/mig_errors.h> 29: #include <mach/port.h> 30: #include <mach/notify.h> 31: 32: #include <device/device_types.h> 33: #include <device/device_port.h> 34: #include "device_interface.h" 35: 36: #include <i386at/dev_hdr.h> 37: #include <i386at/device_emul.h> 1.1.1.2 root 38: 39: #ifdef LINUX_DEV 40: #include <i386/linux/device-drivers.h> 41: #endif 1.1 root 42: 43: extern struct device_emulation_ops mach_device_emulation_ops; 44: #ifdef LINUX_DEV 45: extern struct device_emulation_ops linux_block_emulation_ops; 46: #ifdef CONFIG_INET 47: extern struct device_emulation_ops linux_net_emulation_ops; 48: #endif 49: #endif 50: 51: /* List of emulations. */ 52: static struct device_emulation_ops *emulation_list[] = 53: { 54: #ifdef LINUX_DEV 55: &linux_block_emulation_ops, 56: #ifdef CONFIG_INET 57: &linux_net_emulation_ops, 58: #endif 59: #endif 60: &mach_device_emulation_ops, 61: }; 62: 63: #define NUM_EMULATION (sizeof (emulation_list) / sizeof (emulation_list[0])) 64: 65: io_return_t 66: ds_device_open (ipc_port_t open_port, ipc_port_t reply_port, 67: mach_msg_type_name_t reply_port_type, dev_mode_t mode, 68: char *name, device_t *devp) 69: { 70: int i; 71: device_t dev; 72: io_return_t err; 73: 74: /* Open must be called on the master device port. */ 75: if (open_port != master_device_port) 76: return D_INVALID_OPERATION; 77: 78: /* There must be a reply port. */ 79: if (! IP_VALID (reply_port)) 80: { 81: printf ("ds_* invalid reply port\n"); 82: Debugger ("ds_* reply_port"); 83: return MIG_NO_REPLY; 84: } 85: 86: /* Call each emulation's open routine to find the device. */ 87: for (i = 0; i < NUM_EMULATION; i++) 88: { 89: err = (*emulation_list[i]->open) (reply_port, reply_port_type, 90: mode, name, devp); 91: if (err != D_NO_SUCH_DEVICE) 92: break; 93: } 94: 95: return err; 96: } 97: 98: io_return_t 99: ds_device_close (device_t dev) 100: { 101: if (dev == DEVICE_NULL) 102: return D_NO_SUCH_DEVICE; 103: return (dev->emul_ops->close 104: ? (*dev->emul_ops->close) (dev->emul_data) 105: : D_SUCCESS); 106: } 107: 108: io_return_t 109: ds_device_write (device_t dev, ipc_port_t reply_port, 110: mach_msg_type_name_t reply_port_type, dev_mode_t mode, 111: recnum_t recnum, io_buf_ptr_t data, unsigned int count, 112: int *bytes_written) 113: { 114: if (dev == DEVICE_NULL) 115: return D_NO_SUCH_DEVICE; 116: if (! data) 117: return D_INVALID_SIZE; 118: if (! dev->emul_ops->write) 119: return D_INVALID_OPERATION; 120: return (*dev->emul_ops->write) (dev->emul_data, reply_port, 121: reply_port_type, mode, recnum, 122: data, count, bytes_written); 123: } 124: 125: io_return_t 126: ds_device_write_inband (device_t dev, ipc_port_t reply_port, 127: mach_msg_type_name_t reply_port_type, 128: dev_mode_t mode, recnum_t recnum, 129: io_buf_ptr_inband_t data, unsigned count, 130: int *bytes_written) 131: { 132: if (dev == DEVICE_NULL) 133: return D_NO_SUCH_DEVICE; 134: if (! data) 135: return D_INVALID_SIZE; 136: if (! dev->emul_ops->write_inband) 137: return D_INVALID_OPERATION; 138: return (*dev->emul_ops->write_inband) (dev->emul_data, reply_port, 139: reply_port_type, mode, recnum, 140: data, count, bytes_written); 141: } 142: 143: io_return_t 144: ds_device_read (device_t dev, ipc_port_t reply_port, 145: mach_msg_type_name_t reply_port_type, dev_mode_t mode, 146: recnum_t recnum, int count, io_buf_ptr_t *data, 147: unsigned *bytes_read) 148: { 149: if (dev == DEVICE_NULL) 150: return D_NO_SUCH_DEVICE; 151: if (! dev->emul_ops->read) 152: return D_INVALID_OPERATION; 153: return (*dev->emul_ops->read) (dev->emul_data, reply_port, 154: reply_port_type, mode, recnum, 155: count, data, bytes_read); 156: } 157: 158: io_return_t 159: ds_device_read_inband (device_t dev, ipc_port_t reply_port, 160: mach_msg_type_name_t reply_port_type, dev_mode_t mode, 161: recnum_t recnum, int count, char *data, 162: unsigned *bytes_read) 163: { 164: if (dev == DEVICE_NULL) 165: return D_NO_SUCH_DEVICE; 166: if (! dev->emul_ops->read_inband) 167: return D_INVALID_OPERATION; 168: return (*dev->emul_ops->read_inband) (dev->emul_data, reply_port, 169: reply_port_type, mode, recnum, 170: count, data, bytes_read); 171: } 172: 173: io_return_t 174: ds_device_set_status (device_t dev, dev_flavor_t flavor, 175: dev_status_t status, mach_msg_type_number_t status_count) 176: { 177: if (dev == DEVICE_NULL) 178: return D_NO_SUCH_DEVICE; 179: if (! dev->emul_ops->set_status) 180: return D_INVALID_OPERATION; 181: 182: return (*dev->emul_ops->set_status) (dev->emul_data, flavor, status, 183: status_count); 184: } 185: 186: io_return_t 187: ds_device_get_status (device_t dev, dev_flavor_t flavor, dev_status_t status, 188: mach_msg_type_number_t *status_count) 189: { 190: if (dev == DEVICE_NULL) 191: return D_NO_SUCH_DEVICE; 192: if (! dev->emul_ops->get_status) 193: return D_INVALID_OPERATION; 194: 195: return (*dev->emul_ops->get_status) (dev->emul_data, flavor, status, 196: status_count); 197: } 198: 199: io_return_t 200: ds_device_set_filter (device_t dev, ipc_port_t receive_port, int priority, 201: filter_t *filter, unsigned filter_count) 202: { 203: if (dev == DEVICE_NULL) 204: return D_NO_SUCH_DEVICE; 205: if (! dev->emul_ops->set_filter) 206: return D_INVALID_OPERATION; 207: return (*dev->emul_ops->set_filter) (dev->emul_data, receive_port, 208: priority, filter, filter_count); 209: } 210: 211: io_return_t 212: ds_device_map (device_t dev, vm_prot_t prot, vm_offset_t offset, 213: vm_size_t size, ipc_port_t *pager, boolean_t unmap) 214: { 215: if (dev == DEVICE_NULL) 216: return D_NO_SUCH_DEVICE; 217: if (! dev->emul_ops->map) 218: return D_INVALID_OPERATION; 219: return (*dev->emul_ops->map) (dev->emul_data, prot, 220: offset, size, pager, unmap); 221: } 222: 223: boolean_t 224: ds_notify (mach_msg_header_t *msg) 225: { 226: if (msg->msgh_id == MACH_NOTIFY_NO_SENDERS) 227: { 228: device_t dev; 229: mach_no_senders_notification_t *ns; 230: 231: ns = (mach_no_senders_notification_t *) msg; 232: dev = (device_t) ns->not_header.msgh_remote_port; 233: if (dev->emul_ops->no_senders) 234: (*dev->emul_ops->no_senders) (ns); 235: return TRUE; 236: } 237: 238: printf ("ds_notify: strange notification %d\n", msg->msgh_id); 239: return FALSE; 240: } 241: 242: io_return_t 243: ds_device_write_trap (device_t dev, dev_mode_t mode, 244: recnum_t recnum, vm_offset_t data, vm_size_t count) 245: { 246: if (dev == DEVICE_NULL) 247: return D_NO_SUCH_DEVICE; 248: if (! dev->emul_ops->write_trap) 249: return D_INVALID_OPERATION; 250: return (*dev->emul_ops->write_trap) (dev->emul_data, 251: mode, recnum, data, count); 252: } 253: 254: io_return_t 255: ds_device_writev_trap (device_t dev, dev_mode_t mode, 256: recnum_t recnum, io_buf_vec_t *iovec, vm_size_t count) 257: { 258: if (dev == DEVICE_NULL) 259: return D_NO_SUCH_DEVICE; 260: if (! dev->emul_ops->writev_trap) 261: return D_INVALID_OPERATION; 262: return (*dev->emul_ops->writev_trap) (dev->emul_data, 263: mode, recnum, iovec, count); 264: } 265: 266: void 267: device_reference (device_t dev) 268: { 269: if (dev->emul_ops->reference) 270: (*dev->emul_ops->reference) (dev->emul_data); 271: } 272: 273: void 274: device_deallocate (device_t dev) 275: { 1.1.1.3 ! root 276: if (dev == DEVICE_NULL) ! 277: return; 1.1 root 278: if (dev->emul_ops->dealloc) 279: (*dev->emul_ops->dealloc) (dev->emul_data); 280: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.