1 /* 2 * Copyright 2009-2010, François Revol, <revol@free.fr>. 3 * Sponsored by TuneTracker Systems. 4 * Based on the Haiku usb_serial driver which is: 5 * 6 * Copyright (c) 2007-2008 by Michael Lotz 7 * Heavily based on the original usb_serial driver which is: 8 * 9 * Copyright (c) 2003 by Siarzhuk Zharski <imker@gmx.li> 10 * Distributed under the terms of the MIT License. 11 */ 12 #ifndef _PC_SERIAL_DRIVER_H_ 13 #define _PC_SERIAL_DRIVER_H_ 14 15 #include <OS.h> 16 #include <KernelExport.h> 17 #include <Drivers.h> 18 #include <ISA.h> 19 #include <PCI.h> 20 #include <string.h> 21 22 #include <lock.h> 23 #include <new> 24 25 #include "Tracing.h" 26 27 extern "C" { 28 #include <tty_module.h> 29 } 30 31 32 // whether we should handle default COM ports 33 #define HANDLE_ISA_COM 34 35 #define DRIVER_NAME "pc_serial" // driver name for debug output 36 #define DEVICES_COUNT 20 // max simultaneously open devices 37 38 // avoid clashing with BeOS zz driver 39 #define DEVFS_BASE "ports/pc_serial" 40 //#define DEVFS_BASE "ports/serial" 41 42 43 // no user serviceable part beyond this point 44 45 // more PCI serial APIs 46 #ifndef PCI_serial_16650 47 #define PCI_serial_16650 0x03 /* 16650-compatible serial controller */ 48 #define PCI_serial_16750 0x04 /* 16750-compatible serial controller */ 49 #define PCI_serial_16850 0x05 /* 16850-compatible serial controller */ 50 #define PCI_serial_16950 0x06 /* 16950-compatible serial controller */ 51 #endif 52 53 54 55 typedef enum { 56 B_ISA_BUS, 57 B_PCI_BUS, 58 B_PCMCIA_BUS, 59 B_UNKNOWN_BUS = 0x80 60 } bus_type; 61 62 63 class SerialDevice; 64 65 struct port_constraints { 66 uint32 minsize; 67 uint32 maxsize; 68 uint32 split; // range to split I/O ports for each device 69 uint8 ignoremask; // bitmask of BARs to ignore when probing 70 uint8 maxports; // max number of ports on the card if > 0 71 uint32 subsystem_id_mask; // if set mask with subsys id and shift to get maxports 72 }; 73 74 #define PCI_INVAL 0xffff 75 76 struct serial_support_descriptor { 77 const bus_type bus; // B_*_BUS 78 const char *name; 79 const uint32 *bauds; 80 // not yet used 81 SerialDevice *(*instanciator)(struct serial_support_descriptor *desc); 82 // I/O port constrains (which ranges to use, how to split them) 83 struct port_constraints constraints; 84 // bus specific stuff here... 85 struct { 86 // for both ISA & PCI 87 uchar class_base; 88 uchar class_sub; 89 uchar class_api; // or PCI_undefined 90 // for PCI: if PCI_INVAL then match class 91 ushort vendor_id; 92 ushort device_id; 93 ushort subsystem_vendor_id; 94 ushort subsystem_device_id; 95 } match; 96 }; 97 typedef struct serial_support_descriptor serial_support_descriptor; 98 99 100 //struct serial_config_descriptor { 101 // bus_type bus; // B_*_BUS 102 // struct serial_support_descriptor *descriptor; 103 // union { 104 // struct pci_info pci; 105 // } d; 106 //}; 107 108 109 /* This one rounds the size to integral count of segs (segments) */ 110 #define ROUNDUP(size, seg) (((size) + (seg) - 1) & ~((seg) - 1)) 111 /* Default device buffer size */ 112 #define DEF_BUFFER_SIZE 0x200 113 114 // XXX: sort up the mess in termios.h on B* ! 115 #define BLAST B230400 116 117 /* line coding defines ... Come from CDC USB specs? */ 118 #define LC_STOP_BIT_1 0 119 #define LC_STOP_BIT_2 2 120 121 #define LC_PARITY_NONE 0 122 #define LC_PARITY_ODD 1 123 #define LC_PARITY_EVEN 2 124 125 /* struct that represents line coding */ 126 typedef struct pc_serial_line_coding_s { 127 uint32 speed; 128 uint8 stopbits; 129 uint8 parity; 130 uint8 databits; 131 } pc_serial_line_coding; 132 133 /* control line states */ 134 #define CLS_LINE_DTR 0x0001 135 #define CLS_LINE_RTS 0x0002 136 137 138 extern isa_module_info *gISAModule; 139 extern pci_module_info *gPCIModule; 140 extern tty_module_info *gTTYModule; 141 extern struct ddomain gSerialDomain; 142 143 extern "C" { 144 145 status_t init_hardware(); 146 void uninit_driver(); 147 148 bool pc_serial_service(struct tty *tty, uint32 op, void *buffer, 149 size_t length); 150 151 int32 pc_serial_interrupt(void *arg); 152 153 status_t pc_serial_open(const char *name, uint32 flags, void **cookie); 154 status_t pc_serial_read(void *cookie, off_t position, void *buffer, size_t *numBytes); 155 status_t pc_serial_write(void *cookie, off_t position, const void *buffer, size_t *numBytes); 156 status_t pc_serial_control(void *cookie, uint32 op, void *arg, size_t length); 157 status_t pc_serial_select(void *cookie, uint8 event, uint32 ref, selectsync *sync); 158 status_t pc_serial_deselect(void *coookie, uint8 event, selectsync *sync); 159 status_t pc_serial_close(void *cookie); 160 status_t pc_serial_free(void *cookie); 161 162 const char **publish_devices(); 163 device_hooks *find_device(const char *name); 164 165 } 166 167 168 169 #endif //_PC_SERIAL_DRIVER_H_ 170