1 /* 2 * Copyright (c) 2009 François Revol, <revol@free.fr>. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, 8 * merge, publish, distribute, sublicense, and/or sell copies of 9 * the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 #include <KernelExport.h> 26 #include <Drivers.h> 27 #include <Errors.h> 28 29 int32 api_version = B_CUR_DRIVER_API_VERSION; 30 static int32 sOpenMask; 31 32 status_t 33 init_hardware(void) 34 { 35 dprintf("kdl: init_hardware\n"); 36 return B_OK; 37 } 38 39 40 status_t 41 uninit_hardware(void) 42 { 43 dprintf("kdl: uninit_hardware\n"); 44 return B_OK; 45 } 46 47 48 status_t 49 init_driver(void) 50 { 51 dprintf("kdl: init_driver\n"); 52 return B_OK; 53 } 54 55 56 void 57 uninit_driver(void) 58 { 59 dprintf("kdl: uninit_driver\n"); 60 } 61 62 63 static status_t 64 driver_open(const char *name, uint32 flags, void** _cookie) 65 { 66 dprintf("kdl: open\n"); 67 68 // TODO: check for proper credencials! (root only ?) 69 70 if (atomic_or(&sOpenMask, 1)) { 71 dprintf("kdl: open, BUSY!\n"); 72 return B_BUSY; 73 } 74 75 dprintf("kdl: open, success\n"); 76 return B_OK; 77 } 78 79 80 static status_t 81 driver_close(void* cookie) 82 { 83 dprintf("kdl: close enter\n"); 84 dprintf("kdl: close leave\n"); 85 return B_OK; 86 } 87 88 89 static status_t 90 driver_free(void* cookie) 91 { 92 dprintf("kdl: free\n"); 93 atomic_and(&sOpenMask, ~1); 94 return B_OK; 95 } 96 97 98 static status_t 99 driver_read(void* cookie, off_t position, void *buf, size_t* num_bytes) 100 { 101 dprintf("kdl: read\n"); 102 panic("requested from kdl driver."); 103 *num_bytes = 0; // nothing to read 104 return B_ERROR; 105 } 106 107 108 static status_t 109 driver_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes) 110 { 111 dprintf("kdl: write\n"); 112 *num_bytes = 1; // pretend 1 byte was written 113 return B_OK; 114 } 115 116 117 static status_t 118 driver_control(void *cookie, uint32 op, void *arg, size_t len) 119 { 120 dprintf("kdl: control\n"); 121 return B_ERROR; 122 } 123 124 125 const char** 126 publish_devices(void) 127 { 128 static const char *names[] = {"misc/kdl", NULL}; 129 dprintf("kdl: publish_devices\n"); 130 return names; 131 } 132 133 134 device_hooks* 135 find_device(const char* name) 136 { 137 static device_hooks hooks = { 138 driver_open, 139 driver_close, 140 driver_free, 141 driver_control, 142 driver_read, 143 driver_write, 144 }; 145 dprintf("kdl: find_device\n"); 146 return &hooks; 147 } 148 149