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 init_driver(void) 42 { 43 dprintf("kdl: init_driver\n"); 44 return B_OK; 45 } 46 47 48 void 49 uninit_driver(void) 50 { 51 dprintf("kdl: uninit_driver\n"); 52 } 53 54 55 static status_t 56 driver_open(const char *name, uint32 flags, void** _cookie) 57 { 58 dprintf("kdl: open\n"); 59 60 // TODO: check for proper credencials! (root only ?) 61 62 if (atomic_or(&sOpenMask, 1)) { 63 dprintf("kdl: open, BUSY!\n"); 64 return B_BUSY; 65 } 66 67 dprintf("kdl: open, success\n"); 68 return B_OK; 69 } 70 71 72 static status_t 73 driver_close(void* cookie) 74 { 75 dprintf("kdl: close enter\n"); 76 dprintf("kdl: close leave\n"); 77 return B_OK; 78 } 79 80 81 static status_t 82 driver_free(void* cookie) 83 { 84 dprintf("kdl: free\n"); 85 atomic_and(&sOpenMask, ~1); 86 return B_OK; 87 } 88 89 90 static status_t 91 driver_read(void* cookie, off_t position, void *buf, size_t* num_bytes) 92 { 93 dprintf("kdl: read\n"); 94 panic("requested from kdl driver."); 95 *num_bytes = 0; // nothing to read 96 return B_ERROR; 97 } 98 99 100 static status_t 101 driver_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes) 102 { 103 dprintf("kdl: write\n"); 104 *num_bytes = 1; // pretend 1 byte was written 105 return B_OK; 106 } 107 108 109 static status_t 110 driver_control(void *cookie, uint32 op, void *arg, size_t len) 111 { 112 dprintf("kdl: control\n"); 113 return B_ERROR; 114 } 115 116 117 const char** 118 publish_devices(void) 119 { 120 static const char *names[] = {"misc/kdl", NULL}; 121 dprintf("kdl: publish_devices\n"); 122 return names; 123 } 124 125 126 device_hooks* 127 find_device(const char* name) 128 { 129 static device_hooks hooks = { 130 driver_open, 131 driver_close, 132 driver_free, 133 driver_control, 134 driver_read, 135 driver_write, 136 }; 137 dprintf("kdl: find_device\n"); 138 return &hooks; 139 } 140 141