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 29int32 api_version = B_CUR_DRIVER_API_VERSION; 30static int32 sOpenMask; 31 32status_t 33init_hardware(void) 34{ 35 dprintf("kdl: init_hardware\n"); 36 return B_OK; 37} 38 39 40status_t 41uninit_hardware(void) 42{ 43 dprintf("kdl: uninit_hardware\n"); 44 return B_OK; 45} 46 47 48status_t 49init_driver(void) 50{ 51 dprintf("kdl: init_driver\n"); 52 return B_OK; 53} 54 55 56void 57uninit_driver(void) 58{ 59 dprintf("kdl: uninit_driver\n"); 60} 61 62 63static status_t 64driver_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 80static status_t 81driver_close(void* cookie) 82{ 83 dprintf("kdl: close enter\n"); 84 dprintf("kdl: close leave\n"); 85 return B_OK; 86} 87 88 89static status_t 90driver_free(void* cookie) 91{ 92 dprintf("kdl: free\n"); 93 atomic_and(&sOpenMask, ~1); 94 return B_OK; 95} 96 97 98static status_t 99driver_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 108static status_t 109driver_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 117static status_t 118driver_control(void *cookie, uint32 op, void *arg, size_t len) 119{ 120 dprintf("kdl: control\n"); 121 return B_ERROR; 122} 123 124 125const char** 126publish_devices(void) 127{ 128 static const char *names[] = {"misc/kdl", NULL}; 129 dprintf("kdl: publish_devices\n"); 130 return names; 131} 132 133 134device_hooks* 135find_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