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