1 /* 2 * Copyright (c) 2007-2008 by Michael Lotz 3 * Heavily based on the original usb_serial driver which is: 4 * 5 * Copyright (c) 2003 by Siarzhuk Zharski <imker@gmx.li> 6 * Distributed under the terms of the MIT License. 7 */ 8 #ifndef _PC_SERIAL_DRIVER_H_ 9 #define _PC_SERIAL_DRIVER_H_ 10 11 #include <OS.h> 12 #include <KernelExport.h> 13 #include <Drivers.h> 14 #include <ISA.h> 15 #include <PCI.h> 16 #include <config_manager.h> 17 #include <string.h> 18 19 #ifdef __HAIKU__ 20 #include <lock.h> 21 #else 22 #include "BeOSCompatibility.h" 23 #endif 24 #include "kernel_cpp.h" 25 #include "Tracing.h" 26 27 extern "C" { 28 #include <ttylayer.h> 29 } 30 31 32 // whether we should handle default COM ports 33 // not for BeOS, it has a "zz" driver for this. 34 #ifdef __HAIKU__ 35 #define HANDLE_ISA_COM 36 #endif 37 38 #define DRIVER_NAME "pc_serial" // driver name for debug output 39 #define DEVICES_COUNT 20 // max simultaneously open devices 40 41 // avoid clashing with BeOS zz driver 42 #define DEVFS_BASE "ports/pc_serial" 43 //#define DEVFS_BASE "ports/serial" 44 45 46 // no user serviceable part beyond this point 47 48 // more PCI serial APIs 49 #ifndef PCI_serial_16650 50 #define PCI_serial_16650 0x03 /* 16650-compatible serial controller */ 51 #define PCI_serial_16750 0x04 /* 16750-compatible serial controller */ 52 #define PCI_serial_16850 0x05 /* 16850-compatible serial controller */ 53 #define PCI_serial_16950 0x06 /* 16950-compatible serial controller */ 54 #endif 55 56 class SerialDevice; 57 58 struct port_constraints { 59 uint32 minsize; 60 uint32 maxsize; 61 uint32 split; // range to split I/O ports for each device 62 }; 63 64 #define PCI_INVAL 0xffff 65 struct serial_support_descriptor { 66 bus_type bus; // B_*_BUS 67 const char *name; 68 const uint32 *bauds; 69 // not yet used 70 SerialDevice *(*instanciator)(struct serial_support_descriptor *desc); 71 // I/O port constrains (which ranges to use, how to split them) 72 struct port_constraints constraints; 73 // bus specific stuff here... 74 struct { 75 // for both ISA & PCI 76 uchar class_base; 77 uchar class_sub; 78 uchar class_api; // or PCI_undefined 79 // for PCI: if PCI_INVAL then match class 80 ushort vendor_id; 81 ushort device_id; 82 } match; 83 }; 84 typedef struct serial_support_descriptor serial_support_descriptor; 85 86 87 struct serial_config_descriptor { 88 bus_type bus; // B_*_BUS 89 struct serial_support_descriptor *descriptor; 90 union { 91 struct pci_info pci; 92 } d; 93 }; 94 95 96 /* Some usefull helper defines ... */ 97 #define SIZEOF(array) (sizeof(array) / sizeof(array[0])) /* size of array */ 98 /* This one rounds the size to integral count of segs (segments) */ 99 #define ROUNDUP(size, seg) (((size) + (seg) - 1) & ~((seg) - 1)) 100 /* Default device buffer size */ 101 #define DEF_BUFFER_SIZE 0x200 102 103 // XXX: sort up the mess in termios.h on B* ! 104 #define BLAST B230400 105 106 /* line coding defines ... Come from CDC USB specs? */ 107 #define LC_STOP_BIT_1 0 108 #define LC_STOP_BIT_2 2 109 110 #define LC_PARITY_NONE 0 111 #define LC_PARITY_ODD 1 112 #define LC_PARITY_EVEN 2 113 114 /* struct that represents line coding */ 115 typedef struct pc_serial_line_coding_s { 116 uint32 speed; 117 uint8 stopbits; 118 uint8 parity; 119 uint8 databits; 120 } pc_serial_line_coding; 121 122 /* control line states */ 123 #define CLS_LINE_DTR 0x0001 124 #define CLS_LINE_RTS 0x0002 125 126 #ifndef __HAIKU__ 127 128 typedef bool (*beos_tty_service_func)(struct tty *tty, struct ddrover *rover, uint op); 129 130 // this version is compatible with BeOS R5 131 struct tty_module_info_v1_r5 { 132 // not a real bus manager... no rescan() ! 133 module_info mi; 134 status_t (*ttyopen)(struct ttyfile *, struct ddrover *, beos_tty_service_func); 135 status_t (*ttyclose)(struct ttyfile *, struct ddrover *); 136 status_t (*ttyfree)(struct ttyfile *, struct ddrover *); 137 status_t (*ttyread)(struct ttyfile *, struct ddrover *, char *, size_t *); 138 status_t (*ttywrite)(struct ttyfile *, struct ddrover *, const char *, size_t *); 139 status_t (*ttycontrol)(struct ttyfile *, struct ddrover *, ulong, void *, size_t); 140 void (*ttyinit)(struct tty *, bool); 141 void (*ttyilock)(struct tty *, struct ddrover *, bool ); 142 void (*ttyhwsignal)(struct tty *, struct ddrover *, int, bool); 143 int (*ttyin)(struct tty *, struct ddrover *, int); 144 int (*ttyout)(struct tty *, struct ddrover *); 145 struct ddrover *(*ddrstart)(struct ddrover *); 146 void (*ddrdone)(struct ddrover *); 147 void (*ddacquire)(struct ddrover *, struct ddomain *); 148 }; 149 150 // BeOS BONE has a different module with the same version... 151 struct tty_module_info_v1_bone { 152 // not a real bus manager... no rescan() ! 153 module_info mi; 154 status_t (*ttyopen)(struct ttyfile *, struct ddrover *, beos_tty_service_func); 155 status_t (*ttyclose)(struct ttyfile *, struct ddrover *); 156 status_t (*ttyfree)(struct ttyfile *, struct ddrover *); 157 status_t (*ttyread)(struct ttyfile *, struct ddrover *, char *, size_t *); 158 status_t (*ttywrite)(struct ttyfile *, struct ddrover *, const char *, size_t *); 159 status_t (*ttycontrol)(struct ttyfile *, struct ddrover *, ulong, void *, size_t); 160 status_t (*ttyselect)(struct ttyfile *, struct ddrover *, uint8, uint32, selectsync *); 161 status_t (*ttydeselect)(struct ttyfile *, struct ddrover *, uint8, selectsync *); 162 163 void (*ttyinit)(struct tty *, bool); 164 void (*ttyilock)(struct tty *, struct ddrover *, bool ); 165 void (*ttyhwsignal)(struct tty *, struct ddrover *, int, bool); 166 int (*ttyin)(struct tty *, struct ddrover *, int); 167 int (*ttyout)(struct tty *, struct ddrover *); 168 struct ddrover *(*ddrstart)(struct ddrover *); 169 void (*ddrdone)(struct ddrover *); 170 void (*ddacquire)(struct ddrover *, struct ddomain *); 171 }; 172 #endif 173 174 175 176 extern config_manager_for_driver_module_info *gConfigManagerModule; 177 extern isa_module_info *gISAModule; 178 extern pci_module_info *gPCIModule; 179 //extern tty_module_info *gTTYModule; 180 extern tty_module_info_v1_bone *gTTYModule; 181 extern struct ddomain gSerialDomain; 182 183 extern "C" { 184 status_t init_hardware(); 185 void uninit_driver(); 186 187 bool pc_serial_service(struct tty *ptty, struct ddrover *ddr, uint flags); 188 int32 pc_serial_interrupt(void *arg); 189 190 status_t pc_serial_open(const char *name, uint32 flags, void **cookie); 191 status_t pc_serial_read(void *cookie, off_t position, void *buffer, size_t *numBytes); 192 status_t pc_serial_write(void *cookie, off_t position, const void *buffer, size_t *numBytes); 193 status_t pc_serial_control(void *cookie, uint32 op, void *arg, size_t length); 194 status_t pc_serial_select(void *cookie, uint8 event, uint32 ref, selectsync *sync); 195 status_t pc_serial_deselect(void *coookie, uint8 event, selectsync *sync); 196 status_t pc_serial_close(void *cookie); 197 status_t pc_serial_free(void *cookie); 198 199 const char **publish_devices(); 200 device_hooks *find_device(const char *name); 201 } 202 203 204 205 #endif //_PC_SERIAL_DRIVER_H_ 206