ReactOS 0.4.16-dev-88-ga65b6ae
serial.h File Reference
#include <ntddk.h>
#include <ntddser.h>
Include dependency graph for serial.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _CIRCULAR_BUFFER
 
struct  _SERIAL_DEVICE_EXTENSION
 
struct  _WORKITEM_DATA
 

Macros

#define PST_RS232   1
 
#define COMMPROP_INITIALIZED   0xE73CF52E
 
#define SERIAL_TAG   'lreS'
 
#define INFINITE   MAXULONG
 
#define BAUD_CLOCK   1843200
 
#define CLOCKS_PER_BIT   16
 
#define SER_RBR(x)   ((PUCHAR)(x)+0) /* Receive Register */
 
#define SER_THR(x)   ((PUCHAR)(x)+0) /* Transmit Register */
 
#define SER_DLL(x)   ((PUCHAR)(x)+0) /* Baud Rate Divisor LSB */
 
#define SER_IER(x)   ((PUCHAR)(x)+1) /* Interrupt Enable Register */
 
#define SR_IER_DATA_RECEIVED   0x01
 
#define SR_IER_THR_EMPTY   0x02
 
#define SR_IER_LSR_CHANGE   0x04
 
#define SR_IER_MSR_CHANGE   0x08
 
#define SR_IER_SLEEP_MODE   0x10 /* Uart >= 16750 */
 
#define SR_IER_LOW_POWER   0x20 /* Uart >= 16750 */
 
#define SER_DLM(x)   ((PUCHAR)(x)+1) /* Baud Rate Divisor MSB */
 
#define SER_IIR(x)   ((PUCHAR)(x)+2) /* Interrupt Identification Register */
 
#define SR_IIR_SELF   0x00
 
#define SR_IIR_ID_MASK   0x07
 
#define SR_IIR_MSR_CHANGE   SR_IIR_SELF
 
#define SR_IIR_THR_EMPTY   (SR_IIR_SELF | 2)
 
#define SR_IIR_DATA_RECEIVED   (SR_IIR_SELF | 4)
 
#define SR_IIR_ERROR   (SR_IIR_SELF | 6)
 
#define SER_FCR(x)   ((PUCHAR)(x)+2) /* FIFO Control Register (Uart >= 16550A) */
 
#define SR_FCR_ENABLE_FIFO   0x01
 
#define SR_FCR_CLEAR_RCVR   (0x02 | SR_FCR_ENABLE_FIFO)
 
#define SR_FCR_CLEAR_XMIT   (0x04 | SR_FCR_ENABLE_FIFO)
 
#define SR_FCR_1_BYTE   (0x00 | SR_FCR_ENABLE_FIFO)
 
#define SR_FCR_4_BYTES   (0x40 | SR_FCR_ENABLE_FIFO)
 
#define SR_FCR_8_BYTES   (0x80 | SR_FCR_ENABLE_FIFO)
 
#define SR_FCR_14_BYTES   (0xC0 | SR_FCR_ENABLE_FIFO)
 
#define SER_LCR(x)   ((PUCHAR)(x)+3) /* Line Control Register */
 
#define SR_LCR_CS5   0x00
 
#define SR_LCR_CS6   0x01
 
#define SR_LCR_CS7   0x02
 
#define SR_LCR_CS8   0x03
 
#define SR_LCR_ST1   0x00
 
#define SR_LCR_ST2   0x04
 
#define SR_LCR_PNO   0x00
 
#define SR_LCR_POD   0x08
 
#define SR_LCR_PEV   0x18
 
#define SR_LCR_PMK   0x28
 
#define SR_LCR_PSP   0x38
 
#define SR_LCR_BRK   0x40
 
#define SR_LCR_DLAB   0x80
 
#define SER_MCR(x)   ((PUCHAR)(x)+4) /* Modem Control Register */
 
#define SR_MCR_DTR   SERIAL_DTR_STATE
 
#define SR_MCR_RTS   SERIAL_RTS_STATE
 
#define SER_LSR(x)   ((PUCHAR)(x)+5) /* Line Status Register */
 
#define SR_LSR_DATA_RECEIVED   0x01
 
#define SR_LSR_OVERRUN_ERROR   0x02
 
#define SR_LSR_PARITY_ERROR   0x04
 
#define SR_LSR_FRAMING_ERROR   0x08
 
#define SR_LSR_BREAK_INT   0x10
 
#define SR_LSR_THR_EMPTY   0x20
 
#define SR_LSR_TSR_EMPTY   0x40
 
#define SR_LSR_ERROR_IN_FIFO   0x80 /* Uart >= 16550A */
 
#define SER_MSR(x)   ((PUCHAR)(x)+6) /* Modem Status Register */
 
#define SR_MSR_CTS_CHANGED   0x01
 
#define SR_MSR_DSR_CHANGED   0x02
 
#define SR_MSR_RI_CHANGED   0x04
 
#define SR_MSR_DCD_CHANGED   0x08
 
#define SR_MSR_CTS   SERIAL_CTS_STATE /* Clear To Send */
 
#define SR_MSR_DSR   SERIAL_DSR_STATE /* Data Set Ready */
 
#define SI_MSR_RI   SERIAL_RI_STATE /* Ring Indicator */
 
#define SR_MSR_DCD   SERIAL_DCD_STATE /* Data Carrier Detect */
 
#define SER_SCR(x)   ((PUCHAR)(x)+7) /* Scratch Pad Register, Uart >= Uart16450 */
 

Typedefs

typedef struct _CIRCULAR_BUFFER CIRCULAR_BUFFER
 
typedef struct _CIRCULAR_BUFFERPCIRCULAR_BUFFER
 
typedef struct _SERIAL_DEVICE_EXTENSION SERIAL_DEVICE_EXTENSION
 
typedef struct _SERIAL_DEVICE_EXTENSIONPSERIAL_DEVICE_EXTENSION
 
typedef struct _WORKITEM_DATA WORKITEM_DATA
 
typedef struct _WORKITEM_DATAPWORKITEM_DATA
 

Enumerations

enum  SERIAL_DEVICE_STATE {
  dsStopped , dsStarted , dsPaused , dsRemoved ,
  dsSurpriseRemoved
}
 
enum  UART_TYPE {
  UartUnknown , Uart8250 , Uart16450 , Uart16550 ,
  Uart16550A , Uart16650 , Uart16750
}
 

Functions

NTSTATUS InitializeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
 
NTSTATUS FreeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
BOOLEAN IsCircularBufferEmpty (IN PCIRCULAR_BUFFER pBuffer)
 
ULONG GetNumberOfElementsInCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
NTSTATUS PushCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
 
NTSTATUS PopCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
 
NTSTATUS IncreaseCircularBufferSize (IN PCIRCULAR_BUFFER pBuffer, IN ULONG NewBufferSize)
 
NTSTATUS NTAPI SerialSetBaudRate (IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate)
 
NTSTATUS NTAPI SerialSetLineControl (IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN PSERIAL_LINE_CONTROL NewSettings)
 
UART_TYPE SerialDetectUartType (IN PUCHAR ComPortBase)
 
VOID NTAPI SerialReceiveByte (IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
 
VOID NTAPI SerialSendByte (IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
 
VOID NTAPI SerialCompleteIrp (IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID pIrp, IN PVOID Unused)
 
NTSTATUS NTAPI SerialAddDeviceInternal (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo, IN UART_TYPE UartType, IN PULONG pComPortNumber OPTIONAL, OUT PDEVICE_OBJECT *pFdo OPTIONAL)
 
NTSTATUS NTAPI SerialPnpStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PCM_RESOURCE_LIST ResourceList, IN PCM_RESOURCE_LIST ResourceListTranslated)
 

Variables

DRIVER_DISPATCH SerialCleanup
 
DRIVER_DISPATCH SerialClose
 
DRIVER_DISPATCH SerialCreate
 
DRIVER_DISPATCH SerialDeviceControl
 
DRIVER_DISPATCH SerialQueryInformation
 
DRIVER_DISPATCH ForwardIrpAndForget
 
KSERVICE_ROUTINE SerialInterruptService
 
DRIVER_ADD_DEVICE SerialAddDevice
 
DRIVER_DISPATCH SerialPnp
 
DRIVER_DISPATCH SerialPower
 
DRIVER_DISPATCH SerialRead
 
DRIVER_DISPATCH SerialWrite
 

Macro Definition Documentation

◆ BAUD_CLOCK

#define BAUD_CLOCK   1843200

Definition at line 105 of file serial.h.

◆ CLOCKS_PER_BIT

#define CLOCKS_PER_BIT   16

Definition at line 106 of file serial.h.

◆ COMMPROP_INITIALIZED

#define COMMPROP_INITIALIZED   0xE73CF52E

Definition at line 18 of file serial.h.

◆ INFINITE

#define INFINITE   MAXULONG

Definition at line 102 of file serial.h.

◆ PST_RS232

#define PST_RS232   1

Definition at line 17 of file serial.h.

◆ SER_DLL

#define SER_DLL (   x)    ((PUCHAR)(x)+0) /* Baud Rate Divisor LSB */

Definition at line 111 of file serial.h.

◆ SER_DLM

#define SER_DLM (   x)    ((PUCHAR)(x)+1) /* Baud Rate Divisor MSB */

Definition at line 119 of file serial.h.

◆ SER_FCR

#define SER_FCR (   x)    ((PUCHAR)(x)+2) /* FIFO Control Register (Uart >= 16550A) */

Definition at line 127 of file serial.h.

◆ SER_IER

#define SER_IER (   x)    ((PUCHAR)(x)+1) /* Interrupt Enable Register */

Definition at line 112 of file serial.h.

◆ SER_IIR

#define SER_IIR (   x)    ((PUCHAR)(x)+2) /* Interrupt Identification Register */

Definition at line 120 of file serial.h.

◆ SER_LCR

#define SER_LCR (   x)    ((PUCHAR)(x)+3) /* Line Control Register */

Definition at line 135 of file serial.h.

◆ SER_LSR

#define SER_LSR (   x)    ((PUCHAR)(x)+5) /* Line Status Register */

Definition at line 152 of file serial.h.

◆ SER_MCR

#define SER_MCR (   x)    ((PUCHAR)(x)+4) /* Modem Control Register */

Definition at line 149 of file serial.h.

◆ SER_MSR

#define SER_MSR (   x)    ((PUCHAR)(x)+6) /* Modem Status Register */

Definition at line 161 of file serial.h.

◆ SER_RBR

#define SER_RBR (   x)    ((PUCHAR)(x)+0) /* Receive Register */

Definition at line 109 of file serial.h.

◆ SER_SCR

#define SER_SCR (   x)    ((PUCHAR)(x)+7) /* Scratch Pad Register, Uart >= Uart16450 */

Definition at line 170 of file serial.h.

◆ SER_THR

#define SER_THR (   x)    ((PUCHAR)(x)+0) /* Transmit Register */

Definition at line 110 of file serial.h.

◆ SERIAL_TAG

#define SERIAL_TAG   'lreS'

Definition at line 100 of file serial.h.

◆ SI_MSR_RI

#define SI_MSR_RI   SERIAL_RI_STATE /* Ring Indicator */

Definition at line 168 of file serial.h.

◆ SR_FCR_14_BYTES

#define SR_FCR_14_BYTES   (0xC0 | SR_FCR_ENABLE_FIFO)

Definition at line 134 of file serial.h.

◆ SR_FCR_1_BYTE

#define SR_FCR_1_BYTE   (0x00 | SR_FCR_ENABLE_FIFO)

Definition at line 131 of file serial.h.

◆ SR_FCR_4_BYTES

#define SR_FCR_4_BYTES   (0x40 | SR_FCR_ENABLE_FIFO)

Definition at line 132 of file serial.h.

◆ SR_FCR_8_BYTES

#define SR_FCR_8_BYTES   (0x80 | SR_FCR_ENABLE_FIFO)

Definition at line 133 of file serial.h.

◆ SR_FCR_CLEAR_RCVR

#define SR_FCR_CLEAR_RCVR   (0x02 | SR_FCR_ENABLE_FIFO)

Definition at line 129 of file serial.h.

◆ SR_FCR_CLEAR_XMIT

#define SR_FCR_CLEAR_XMIT   (0x04 | SR_FCR_ENABLE_FIFO)

Definition at line 130 of file serial.h.

◆ SR_FCR_ENABLE_FIFO

#define SR_FCR_ENABLE_FIFO   0x01

Definition at line 128 of file serial.h.

◆ SR_IER_DATA_RECEIVED

#define SR_IER_DATA_RECEIVED   0x01

Definition at line 113 of file serial.h.

◆ SR_IER_LOW_POWER

#define SR_IER_LOW_POWER   0x20 /* Uart >= 16750 */

Definition at line 118 of file serial.h.

◆ SR_IER_LSR_CHANGE

#define SR_IER_LSR_CHANGE   0x04

Definition at line 115 of file serial.h.

◆ SR_IER_MSR_CHANGE

#define SR_IER_MSR_CHANGE   0x08

Definition at line 116 of file serial.h.

◆ SR_IER_SLEEP_MODE

#define SR_IER_SLEEP_MODE   0x10 /* Uart >= 16750 */

Definition at line 117 of file serial.h.

◆ SR_IER_THR_EMPTY

#define SR_IER_THR_EMPTY   0x02

Definition at line 114 of file serial.h.

◆ SR_IIR_DATA_RECEIVED

#define SR_IIR_DATA_RECEIVED   (SR_IIR_SELF | 4)

Definition at line 125 of file serial.h.

◆ SR_IIR_ERROR

#define SR_IIR_ERROR   (SR_IIR_SELF | 6)

Definition at line 126 of file serial.h.

◆ SR_IIR_ID_MASK

#define SR_IIR_ID_MASK   0x07

Definition at line 122 of file serial.h.

◆ SR_IIR_MSR_CHANGE

#define SR_IIR_MSR_CHANGE   SR_IIR_SELF

Definition at line 123 of file serial.h.

◆ SR_IIR_SELF

#define SR_IIR_SELF   0x00

Definition at line 121 of file serial.h.

◆ SR_IIR_THR_EMPTY

#define SR_IIR_THR_EMPTY   (SR_IIR_SELF | 2)

Definition at line 124 of file serial.h.

◆ SR_LCR_BRK

#define SR_LCR_BRK   0x40

Definition at line 147 of file serial.h.

◆ SR_LCR_CS5

#define SR_LCR_CS5   0x00

Definition at line 136 of file serial.h.

◆ SR_LCR_CS6

#define SR_LCR_CS6   0x01

Definition at line 137 of file serial.h.

◆ SR_LCR_CS7

#define SR_LCR_CS7   0x02

Definition at line 138 of file serial.h.

◆ SR_LCR_CS8

#define SR_LCR_CS8   0x03

Definition at line 139 of file serial.h.

◆ SR_LCR_DLAB

#define SR_LCR_DLAB   0x80

Definition at line 148 of file serial.h.

◆ SR_LCR_PEV

#define SR_LCR_PEV   0x18

Definition at line 144 of file serial.h.

◆ SR_LCR_PMK

#define SR_LCR_PMK   0x28

Definition at line 145 of file serial.h.

◆ SR_LCR_PNO

#define SR_LCR_PNO   0x00

Definition at line 142 of file serial.h.

◆ SR_LCR_POD

#define SR_LCR_POD   0x08

Definition at line 143 of file serial.h.

◆ SR_LCR_PSP

#define SR_LCR_PSP   0x38

Definition at line 146 of file serial.h.

◆ SR_LCR_ST1

#define SR_LCR_ST1   0x00

Definition at line 140 of file serial.h.

◆ SR_LCR_ST2

#define SR_LCR_ST2   0x04

Definition at line 141 of file serial.h.

◆ SR_LSR_BREAK_INT

#define SR_LSR_BREAK_INT   0x10

Definition at line 157 of file serial.h.

◆ SR_LSR_DATA_RECEIVED

#define SR_LSR_DATA_RECEIVED   0x01

Definition at line 153 of file serial.h.

◆ SR_LSR_ERROR_IN_FIFO

#define SR_LSR_ERROR_IN_FIFO   0x80 /* Uart >= 16550A */

Definition at line 160 of file serial.h.

◆ SR_LSR_FRAMING_ERROR

#define SR_LSR_FRAMING_ERROR   0x08

Definition at line 156 of file serial.h.

◆ SR_LSR_OVERRUN_ERROR

#define SR_LSR_OVERRUN_ERROR   0x02

Definition at line 154 of file serial.h.

◆ SR_LSR_PARITY_ERROR

#define SR_LSR_PARITY_ERROR   0x04

Definition at line 155 of file serial.h.

◆ SR_LSR_THR_EMPTY

#define SR_LSR_THR_EMPTY   0x20

Definition at line 158 of file serial.h.

◆ SR_LSR_TSR_EMPTY

#define SR_LSR_TSR_EMPTY   0x40

Definition at line 159 of file serial.h.

◆ SR_MCR_DTR

#define SR_MCR_DTR   SERIAL_DTR_STATE

Definition at line 150 of file serial.h.

◆ SR_MCR_RTS

#define SR_MCR_RTS   SERIAL_RTS_STATE

Definition at line 151 of file serial.h.

◆ SR_MSR_CTS

#define SR_MSR_CTS   SERIAL_CTS_STATE /* Clear To Send */

Definition at line 166 of file serial.h.

◆ SR_MSR_CTS_CHANGED

#define SR_MSR_CTS_CHANGED   0x01

Definition at line 162 of file serial.h.

◆ SR_MSR_DCD

#define SR_MSR_DCD   SERIAL_DCD_STATE /* Data Carrier Detect */

Definition at line 169 of file serial.h.

◆ SR_MSR_DCD_CHANGED

#define SR_MSR_DCD_CHANGED   0x08

Definition at line 165 of file serial.h.

◆ SR_MSR_DSR

#define SR_MSR_DSR   SERIAL_DSR_STATE /* Data Set Ready */

Definition at line 167 of file serial.h.

◆ SR_MSR_DSR_CHANGED

#define SR_MSR_DSR_CHANGED   0x02

Definition at line 163 of file serial.h.

◆ SR_MSR_RI_CHANGED

#define SR_MSR_RI_CHANGED   0x04

Definition at line 164 of file serial.h.

Typedef Documentation

◆ CIRCULAR_BUFFER

◆ PCIRCULAR_BUFFER

◆ PSERIAL_DEVICE_EXTENSION

◆ PWORKITEM_DATA

◆ SERIAL_DEVICE_EXTENSION

◆ WORKITEM_DATA

Enumeration Type Documentation

◆ SERIAL_DEVICE_STATE

Enumerator
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 

Definition at line 20 of file serial.h.

21{
SERIAL_DEVICE_STATE
Definition: serial.h:21
@ dsSurpriseRemoved
Definition: serial.h:26
@ dsStopped
Definition: serial.h:22
@ dsPaused
Definition: serial.h:24
@ dsStarted
Definition: serial.h:23
@ dsRemoved
Definition: serial.h:25

◆ UART_TYPE

Enumerator
UartUnknown 
Uart8250 
Uart16450 
Uart16550 
Uart16550A 
Uart16650 
Uart16750 

Definition at line 29 of file serial.h.

30{
32 Uart8250, /* initial version */
33 Uart16450, /* + 38.4 Kbps */
34 Uart16550, /* + 115 Kbps */
35 Uart16550A,/* + FIFO 16 bytes */
36 Uart16650, /* + FIFO 32 bytes, 230 Kbps, power management, auto-flow */
37 Uart16750 /* + FIFO 64 bytes, 460 Kbps */
38} UART_TYPE;
UART_TYPE
Definition: serial.h:30
@ Uart16550
Definition: serial.h:34
@ Uart16550A
Definition: serial.h:35
@ UartUnknown
Definition: serial.h:31
@ Uart16450
Definition: serial.h:33
@ Uart16650
Definition: serial.h:36
@ Uart8250
Definition: serial.h:32
@ Uart16750
Definition: serial.h:37

Function Documentation

◆ FreeCircularBuffer()

NTSTATUS FreeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 30 of file circularbuffer.c.

32{
33 TRACE_(SERIAL, "FreeCircularBuffer(pBuffer %p)\n", pBuffer);
35 if (pBuffer->Buffer != NULL)
37 return STATUS_SUCCESS;
38}
#define NULL
Definition: types.h:112
#define TRACE_(x)
Definition: compat.h:76
#define SERIAL_TAG
Definition: serial.h:100
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
PVOID pBuffer
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by SerialAddDeviceInternal().

◆ GetNumberOfElementsInCircularBuffer()

ULONG GetNumberOfElementsInCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 50 of file circularbuffer.c.

52{
53 TRACE_(SERIAL, "GetNumberOfElementsInCircularBuffer(pBuffer %p)\n", pBuffer);
55 return (pBuffer->WritePosition + pBuffer->Length - pBuffer->ReadPosition) % pBuffer->Length;
56}

Referenced by SerialInterruptService().

◆ IncreaseCircularBufferSize()

NTSTATUS IncreaseCircularBufferSize ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  NewBufferSize 
)

Definition at line 91 of file circularbuffer.c.

94{
95 PUCHAR NewBuffer;
96
97 TRACE_(SERIAL, "IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
99 ASSERT(pBuffer->Length);
100 if (pBuffer->Length > NewBufferSize)
102 else if (pBuffer->Length == NewBufferSize)
103 return STATUS_SUCCESS;
104
105 NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG);
106 if (!NewBuffer)
108 RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR));
110 pBuffer->Buffer = NewBuffer;
111 pBuffer->Length = NewBufferSize;
112 return STATUS_SUCCESS;
113}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by SerialDeviceControl().

◆ InitializeCircularBuffer()

NTSTATUS InitializeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  BufferSize 
)

Definition at line 15 of file circularbuffer.c.

18{
19 TRACE_(SERIAL, "InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
22 if (!pBuffer->Buffer)
24 pBuffer->Length = BufferSize;
25 pBuffer->ReadPosition = pBuffer->WritePosition = 0;
26 return STATUS_SUCCESS;
27}
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by SerialAddDeviceInternal().

◆ IsCircularBufferEmpty()

BOOLEAN IsCircularBufferEmpty ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 41 of file circularbuffer.c.

43{
44 TRACE_(SERIAL, "IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
46 return (pBuffer->ReadPosition == pBuffer->WritePosition);
47}

Referenced by PopCircularBufferEntry(), ReadBytes(), and SerialSendByte().

◆ PopCircularBufferEntry()

NTSTATUS PopCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
OUT PUCHAR  Entry 
)

Definition at line 76 of file circularbuffer.c.

79{
80 TRACE_(SERIAL, "PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
82 ASSERT(pBuffer->Length);
85 *Entry = pBuffer->Buffer[pBuffer->ReadPosition];
86 pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
87 return STATUS_SUCCESS;
88}
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:376
base of all file and directory entries
Definition: entries.h:83

Referenced by ReadBytes(), and SerialSendByte().

◆ PushCircularBufferEntry()

NTSTATUS PushCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
IN UCHAR  Entry 
)

Definition at line 59 of file circularbuffer.c.

62{
63 ULONG NextPosition;
64 TRACE_(SERIAL, "PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
66 ASSERT(pBuffer->Length);
67 NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
68 if (NextPosition == pBuffer->ReadPosition)
70 pBuffer->Buffer[pBuffer->WritePosition] = Entry;
71 pBuffer->WritePosition = NextPosition;
72 return STATUS_SUCCESS;
73}
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG
Definition: typedefs.h:59

Referenced by SerialReceiveByte(), and SerialWrite().

◆ SerialAddDeviceInternal()

NTSTATUS NTAPI SerialAddDeviceInternal ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo,
IN UART_TYPE  UartType,
IN PULONG pComPortNumber  OPTIONAL,
OUT PDEVICE_OBJECT *pFdo  OPTIONAL 
)

Definition at line 18 of file pnp.c.

24{
26 PSERIAL_DEVICE_EXTENSION DeviceExtension = NULL;
28 WCHAR DeviceNameBuffer[32];
30
31 TRACE_(SERIAL, "SerialAddDeviceInternal()\n");
32
34 ASSERT(Pdo);
35
36 /* Create new device object */
37 swprintf(DeviceNameBuffer, L"\\Device\\Serial%lu", IoGetConfigurationInformation()->SerialCount);
38 RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
44 FALSE,
45 &Fdo);
46 if (!NT_SUCCESS(Status))
47 {
48 WARN_(SERIAL, "IoCreateDevice() failed with status 0x%08x\n", Status);
49 Fdo = NULL;
50 goto ByeBye;
51 }
52 DeviceExtension = (PSERIAL_DEVICE_EXTENSION)Fdo->DeviceExtension;
53 RtlZeroMemory(DeviceExtension, sizeof(SERIAL_DEVICE_EXTENSION));
54
55 /* Register device interface */
56 Status = IoRegisterDeviceInterface(Pdo, &GUID_DEVINTERFACE_COMPORT, NULL, &DeviceExtension->SerialInterfaceName);
57 if (!NT_SUCCESS(Status))
58 {
59 WARN_(SERIAL, "IoRegisterDeviceInterface() failed with status 0x%08x\n", Status);
60 goto ByeBye;
61 }
62
64 if (pComPortNumber == NULL)
65 DeviceExtension->ComPort = DeviceExtension->SerialPortNumber + 1;
66 else
67 DeviceExtension->ComPort = *pComPortNumber;
68 DeviceExtension->Pdo = Pdo;
69 DeviceExtension->PnpState = dsStopped;
70 DeviceExtension->UartType = UartType;
71 Status = InitializeCircularBuffer(&DeviceExtension->InputBuffer, 16);
72 if (!NT_SUCCESS(Status)) goto ByeBye;
73 Status = InitializeCircularBuffer(&DeviceExtension->OutputBuffer, 16);
74 if (!NT_SUCCESS(Status)) goto ByeBye;
75 IoInitializeRemoveLock(&DeviceExtension->RemoveLock, SERIAL_TAG, 0, 0);
76 KeInitializeSpinLock(&DeviceExtension->InputBufferLock);
77 KeInitializeSpinLock(&DeviceExtension->OutputBufferLock);
79 KeInitializeDpc(&DeviceExtension->ReceivedByteDpc, SerialReceiveByte, DeviceExtension);
80 KeInitializeDpc(&DeviceExtension->SendByteDpc, SerialSendByte, DeviceExtension);
81 KeInitializeDpc(&DeviceExtension->CompleteIrpDpc, SerialCompleteIrp, DeviceExtension);
83 if (!NT_SUCCESS(Status))
84 {
85 WARN_(SERIAL, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08x\n", Status);
86 goto ByeBye;
87 }
88 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
89 Fdo->Flags |= DO_POWER_PAGABLE;
90 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
91 Fdo->Flags |= DO_BUFFERED_IO;
92 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
93 Fdo->Flags |= DO_DIRECT_IO;
94
95 /* Choose default strategy */
96 if ((Fdo->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO)) == 0)
97 Fdo->Flags |= DO_BUFFERED_IO;
98
99 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
100 if (pFdo)
101 {
102 *pFdo = Fdo;
103 }
104
105 return STATUS_SUCCESS;
106
107ByeBye:
108 if (Fdo)
109 {
110 FreeCircularBuffer(&DeviceExtension->InputBuffer);
111 FreeCircularBuffer(&DeviceExtension->OutputBuffer);
113 }
114 return Status;
115}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
NTSTATUS InitializeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
NTSTATUS FreeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer)
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define swprintf
Definition: precomp.h:40
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
VOID NTAPI SerialReceiveByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:30
VOID NTAPI SerialSendByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:67
VOID NTAPI SerialCompleteIrp(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID pIrp, IN PVOID Unused)
Definition: misc.c:105
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
FxDevice * pFdo
Status
Definition: gdiplustypes.h:25
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Returns a pointer to the I/O manager's global configuration information structure.
Definition: iorsrce.c:998
@ dsStopped
Definition: isapnp.h:30
#define FILE_DEVICE_SERIAL_PORT
Definition: serial.c:44
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ NotificationEvent
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define L(x)
Definition: ntvdm.h:50
#define WARN_(ch,...)
Definition: debug.h:157
PDEVICE_OBJECT LowerDevice
Definition: serial.h:51
KSPIN_LOCK OutputBufferLock
Definition: serial.h:78
UART_TYPE UartType
Definition: serial.h:66
KSPIN_LOCK InputBufferLock
Definition: serial.h:76
IO_REMOVE_LOCK RemoveLock
Definition: serial.h:53
KEVENT InputBufferNotEmpty
Definition: serial.h:74
UNICODE_STRING SerialInterfaceName
Definition: serial.h:80
CIRCULAR_BUFFER InputBuffer
Definition: serial.h:75
SERIAL_DEVICE_STATE PnpState
Definition: serial.h:52
CIRCULAR_BUFFER OutputBuffer
Definition: serial.h:77
PDEVICE_OBJECT Pdo
Definition: serial.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833
#define DO_POWER_PAGABLE
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SerialAddDevice().

◆ SerialCompleteIrp()

VOID NTAPI SerialCompleteIrp ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  pIrp,
IN PVOID  Unused 
)

Definition at line 105 of file misc.c.

110{
112}
FxIrp * pIrp
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by SerialAddDeviceInternal().

◆ SerialDetectUartType()

UART_TYPE SerialDetectUartType ( IN PUCHAR  ComPortBase)

Definition at line 16 of file legacy.c.

18{
19 UCHAR Lcr, TestLcr;
20 UCHAR OldScr, Scr5A, ScrA5;
22 UCHAR NewFifoStatus;
23
26 TestLcr = READ_PORT_UCHAR(SER_LCR(BaseAddress)) ^ 0xFF;
28
29 /* Accessing the LCR must work for a usable serial port */
30 if (TestLcr != Lcr)
31 return UartUnknown;
32
33 /* Ensure that all following accesses are done as required */
42
43 /* Test scratch pad */
50
51 /* When non-functional, we have a 8250 */
52 if (Scr5A != 0x5A || ScrA5 != 0xA5)
53 return Uart8250;
54
55 /* Test FIFO type */
58 NewFifoStatus = READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0xC0;
59 if (!FifoEnabled)
61 switch (NewFifoStatus)
62 {
63 case 0x00:
64 return Uart16450;
65 case 0x40:
66 case 0x80:
67 /* Not sure about this but the documentation says that 0x40
68 * indicates an unusable FIFO but my tests only worked
69 * with 0x80 */
70 return Uart16550;
71 }
72
73 /* FIFO is only functional for 16550A+ */
74 return Uart16550A;
75}
unsigned char BOOLEAN
BOOLEAN FifoEnabled
Definition: cport_pc98.c:29
#define SER_SCR(x)
Definition: serial.h:170
#define SER_MSR(x)
Definition: serial.h:161
#define SR_FCR_ENABLE_FIFO
Definition: serial.h:128
#define SER_IIR(x)
Definition: serial.h:120
#define SER_FCR(x)
Definition: serial.h:127
#define SER_IER(x)
Definition: serial.h:112
#define SER_RBR(x)
Definition: serial.h:109
#define SER_MCR(x)
Definition: serial.h:149
#define SER_LCR(x)
Definition: serial.h:135
#define SER_LSR(x)
Definition: serial.h:152
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

Referenced by SerialPnpStartDevice().

◆ SerialPnpStartDevice()

NTSTATUS NTAPI SerialPnpStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PCM_RESOURCE_LIST  ResourceList,
IN PCM_RESOURCE_LIST  ResourceListTranslated 
)

Definition at line 136 of file pnp.c.

140{
141 PSERIAL_DEVICE_EXTENSION DeviceExtension;
142 WCHAR DeviceNameBuffer[32];
144 WCHAR LinkNameBuffer[32];
145 UNICODE_STRING LinkName;
146 WCHAR ComPortBuffer[32];
147 UNICODE_STRING ComPort;
148 ULONG Vector = 0;
149 ULONG i;
150 UCHAR IER;
151 KIRQL Dirql;
154 BOOLEAN ShareInterrupt = TRUE;
155 OBJECT_ATTRIBUTES objectAttributes;
156 PUCHAR ComPortBase;
158 HANDLE hKey;
160
161 DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
162
163 ASSERT(DeviceExtension);
164
165 if (!ResourceList)
166 {
167 WARN_(SERIAL, "No allocated resources sent to driver\n");
169 }
170 if (ResourceList->Count != 1)
171 {
172 WARN_(SERIAL, "Wrong number of allocated resources sent to driver\n");
174 }
175 if (ResourceList->List[0].PartialResourceList.Version != 1
176 || ResourceList->List[0].PartialResourceList.Revision != 1
177 || ResourceListTranslated->List[0].PartialResourceList.Version != 1
178 || ResourceListTranslated->List[0].PartialResourceList.Revision != 1)
179 {
180 WARN_(SERIAL, "Revision mismatch: %u.%u != 1.1 or %u.%u != 1.1\n",
181 ResourceList->List[0].PartialResourceList.Version,
182 ResourceList->List[0].PartialResourceList.Revision,
183 ResourceListTranslated->List[0].PartialResourceList.Version,
184 ResourceListTranslated->List[0].PartialResourceList.Revision);
186 }
187
188 DeviceExtension->BaudRate = 19200;
189 DeviceExtension->BaseAddress = 0;
190 Dirql = 0;
191 for (i = 0; i < ResourceList->List[0].PartialResourceList.Count; i++)
192 {
193 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
194 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptorTranslated = &ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[i];
195 switch (PartialDescriptor->Type)
196 {
198 if (PartialDescriptor->u.Port.Length < 7)
200 if (DeviceExtension->BaseAddress != 0)
201 return STATUS_UNSUCCESSFUL;
202 DeviceExtension->BaseAddress = PartialDescriptor->u.Port.Start.u.LowPart;
203 break;
205 Dirql = (KIRQL)PartialDescriptorTranslated->u.Interrupt.Level;
206 Vector = PartialDescriptorTranslated->u.Interrupt.Vector;
207 Affinity = PartialDescriptorTranslated->u.Interrupt.Affinity;
208 if (PartialDescriptorTranslated->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
210 else
212 ShareInterrupt = (PartialDescriptorTranslated->ShareDisposition == CmResourceShareShared);
213 break;
214 }
215 }
216 INFO_(SERIAL, "New COM port. Base = 0x%lx, Irql = %u\n",
217 DeviceExtension->BaseAddress, Dirql);
218 if (!DeviceExtension->BaseAddress)
220 if (!Dirql)
222 ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
223
224 /* Test if we are trying to start the serial port used for debugging */
225 INFO_(SERIAL, "Comparing addresses: KdComPortInUse: %p, ComPortBase: %p\n", KdComPortInUse, ComPortBase);
226 if (KdComPortInUse == ComPortBase)
227 {
228 INFO_(SERIAL, "Failing IRP_MN_START_DEVICE as this serial port is used for debugging\n");
230 }
231
232 if (DeviceExtension->UartType == UartUnknown)
233 DeviceExtension->UartType = SerialDetectUartType(ComPortBase);
234
235 /* Get current settings */
236 DeviceExtension->MCR = READ_PORT_UCHAR(SER_MCR(ComPortBase));
237 DeviceExtension->MSR = READ_PORT_UCHAR(SER_MSR(ComPortBase));
238 DeviceExtension->WaitMask = 0;
239
240 /* Set baud rate */
241 Status = SerialSetBaudRate(DeviceExtension, DeviceExtension->BaudRate);
242 if (!NT_SUCCESS(Status))
243 {
244 WARN_(SERIAL, "SerialSetBaudRate() failed with status 0x%08x\n", Status);
245 return Status;
246 }
247
248 /* Set line control */
249 DeviceExtension->SerialLineControl.StopBits = STOP_BIT_1;
250 DeviceExtension->SerialLineControl.Parity = NO_PARITY;
251 DeviceExtension->SerialLineControl.WordLength = 8;
252 Status = SerialSetLineControl(DeviceExtension, &DeviceExtension->SerialLineControl);
253 if (!NT_SUCCESS(Status))
254 {
255 WARN_(SERIAL, "SerialSetLineControl() failed with status 0x%08x\n", Status);
256 return Status;
257 }
258
259 /* Clear receive/transmit buffers */
260 if (DeviceExtension->UartType >= Uart16550A)
261 {
262 /* 16550 UARTs also have FIFO queues, but they are unusable due to a bug */
263 WRITE_PORT_UCHAR(SER_FCR(ComPortBase),
265 }
266
267 /* Create link \DosDevices\COMX -> \Device\SerialX */
268 swprintf(DeviceNameBuffer, L"\\Device\\Serial%lu", DeviceExtension->SerialPortNumber);
269 swprintf(LinkNameBuffer, L"\\DosDevices\\COM%lu", DeviceExtension->ComPort);
270 swprintf(ComPortBuffer, L"COM%lu", DeviceExtension->ComPort);
271 RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
272 RtlInitUnicodeString(&LinkName, LinkNameBuffer);
273 RtlInitUnicodeString(&ComPort, ComPortBuffer);
275 if (!NT_SUCCESS(Status))
276 {
277 WARN_(SERIAL, "IoCreateSymbolicLink() failed with status 0x%08x\n", Status);
278 return Status;
279 }
280
281 /* Connect interrupt and enable them */
283 &DeviceExtension->Interrupt, SerialInterruptService,
285 Vector, Dirql, Dirql,
286 InterruptMode, ShareInterrupt,
287 Affinity, FALSE);
288 if (!NT_SUCCESS(Status))
289 {
290 WARN_(SERIAL, "IoConnectInterrupt() failed with status 0x%08x\n", Status);
292 IoDeleteSymbolicLink(&LinkName);
293 return Status;
294 }
295
296 /* Write an entry value under HKLM\HARDWARE\DeviceMap\SERIALCOMM */
297 /* This step is not mandatory, so don't exit in case of error */
298 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\HARDWARE\\DeviceMap\\SERIALCOMM");
300 Status = ZwCreateKey(&hKey, KEY_SET_VALUE, &objectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
301 if (NT_SUCCESS(Status))
302 {
303 /* Key = \Device\Serialx, Value = COMx */
304 ZwSetValueKey(hKey, &DeviceName, 0, REG_SZ, ComPortBuffer, ComPort.Length + sizeof(WCHAR));
305 ZwClose(hKey);
306 }
307
308 DeviceExtension->PnpState = dsStarted;
309
310 /* Activate interrupt modes */
311 IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
313 WRITE_PORT_UCHAR(SER_IER(ComPortBase), IER);
314
315 /* Activate DTR, RTS */
316 DeviceExtension->MCR |= SR_MCR_DTR | SR_MCR_RTS;
317 WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
318
319 /* Activate serial interface */
321 /* We don't really care if the call succeeded or not... */
322
323 return STATUS_SUCCESS;
324}
#define ULongToPtr(ul)
Definition: basetsd.h:92
#define TRUE
Definition: types.h:120
ULONG_PTR KAFFINITY
Definition: compat.h:85
UART_TYPE SerialDetectUartType(IN PUCHAR BaseAddress)
Definition: legacy.c:16
#define SR_MCR_DTR
Definition: serial.h:150
#define SR_IER_LSR_CHANGE
Definition: serial.h:115
#define SR_IER_THR_EMPTY
Definition: serial.h:114
#define SR_FCR_CLEAR_RCVR
Definition: serial.h:129
#define SR_FCR_CLEAR_XMIT
Definition: serial.h:130
#define SR_MCR_RTS
Definition: serial.h:151
#define SR_IER_DATA_RECEIVED
Definition: serial.h:113
KSERVICE_ROUTINE SerialInterruptService
Definition: serial.h:268
#define SR_IER_MSR_CHANGE
Definition: serial.h:116
UCHAR KIRQL
Definition: env_spec_w32.h:591
FxAutoRegKey hKey
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PUCHAR KdComPortInUse
Definition: usage.c:17
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
@ dsStarted
Definition: isapnp.h:31
#define REG_SZ
Definition: layer.c:22
#define NO_PARITY
Definition: serial.c:89
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define STOP_BIT_1
Definition: ntddser.h:215
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:23
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:325
@ Latched
Definition: miniport.h:81
@ LevelSensitive
Definition: miniport.h:80
enum _KINTERRUPT_MODE KINTERRUPT_MODE
#define INFO_(ch,...)
Definition: debug.h:159
NTSTATUS NTAPI SerialSetBaudRate(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate)
Definition: devctrl.c:50
NTSTATUS NTAPI SerialSetLineControl(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN PSERIAL_LINE_CONTROL NewSettings)
Definition: devctrl.c:88
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@393 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@394 Interrupt
SERIAL_LINE_CONTROL SerialLineControl
Definition: serial.h:65
PKINTERRUPT Interrupt
Definition: serial.h:60
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
@ CmResourceShareShared
Definition: cmtypes.h:243
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:174
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:806

Referenced by SerialPnp().

◆ SerialReceiveByte()

VOID NTAPI SerialReceiveByte ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  Unused1,
IN PVOID  Unused2 
)

Definition at line 30 of file misc.c.

35{
36 PSERIAL_DEVICE_EXTENSION DeviceExtension;
37 PUCHAR ComPortBase;
38 UCHAR Byte;
39 KIRQL Irql;
40 UCHAR IER;
42
43 DeviceExtension = (PSERIAL_DEVICE_EXTENSION)pDeviceExtension;
44 ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
45
46 KeAcquireSpinLock(&DeviceExtension->InputBufferLock, &Irql);
47 while (READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_DATA_RECEIVED)
48 {
49 Byte = READ_PORT_UCHAR(SER_RBR(ComPortBase));
50 INFO_(SERIAL, "Byte received on COM%lu: 0x%02x\n",
51 DeviceExtension->ComPort, Byte);
52 Status = PushCircularBufferEntry(&DeviceExtension->InputBuffer, Byte);
53 if (NT_SUCCESS(Status))
54 DeviceExtension->SerialPerfStats.ReceivedCount++;
55 else
57 }
58 KeSetEvent(&DeviceExtension->InputBufferNotEmpty, 0, FALSE);
59 KeReleaseSpinLock(&DeviceExtension->InputBufferLock, Irql);
60
61 /* allow new interrupts */
62 IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
64}
NTSTATUS PushCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
_Out_ PKIRQL Irql
Definition: csq.h:179
unsigned char Byte
Definition: zlib.h:37
#define SR_LSR_DATA_RECEIVED
Definition: serial.h:153
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ULONG ReceivedCount
Definition: ntddser.h:294
ULONG BufferOverrunErrorCount
Definition: ntddser.h:298
SERIALPERF_STATS SerialPerfStats
Definition: serial.h:71

Referenced by SerialAddDeviceInternal().

◆ SerialSendByte()

VOID NTAPI SerialSendByte ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  Unused1,
IN PVOID  Unused2 
)

Definition at line 67 of file misc.c.

72{
73 PSERIAL_DEVICE_EXTENSION DeviceExtension;
74 PUCHAR ComPortBase;
75 UCHAR Byte;
76 KIRQL Irql;
77 UCHAR IER;
79
80 DeviceExtension = (PSERIAL_DEVICE_EXTENSION)pDeviceExtension;
81 ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
82
83 KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql);
84 while (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer)
85 && READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_THR_EMPTY)
86 {
87 Status = PopCircularBufferEntry(&DeviceExtension->OutputBuffer, &Byte);
88 if (!NT_SUCCESS(Status))
89 break;
90 WRITE_PORT_UCHAR(SER_THR(ComPortBase), Byte);
91 INFO_(SERIAL, "Byte sent to COM%lu: 0x%02x\n",
92 DeviceExtension->ComPort, Byte);
93 DeviceExtension->SerialPerfStats.TransmittedCount++;
94 }
95 if (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer))
96 {
97 /* allow new interrupts */
98 IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
99 WRITE_PORT_UCHAR(SER_IER(ComPortBase), IER | SR_IER_THR_EMPTY);
100 }
101 KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql);
102}
NTSTATUS PopCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
#define SR_LSR_THR_EMPTY
Definition: serial.h:158
#define SER_THR(x)
Definition: serial.h:110
ULONG TransmittedCount
Definition: ntddser.h:295

Referenced by SerialAddDeviceInternal(), and SerialWrite().

◆ SerialSetBaudRate()

NTSTATUS NTAPI SerialSetBaudRate ( IN PSERIAL_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  NewBaudRate 
)

Definition at line 50 of file devctrl.c.

53{
54 ULONG BaudRate;
56 PUCHAR ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
58
59 if (NewBaudRate == 0)
61
62 divisor = (USHORT)(BAUD_CLOCK / (CLOCKS_PER_BIT * NewBaudRate));
63 BaudRate = BAUD_CLOCK / (CLOCKS_PER_BIT * divisor);
64
65 Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort));
66 if (NT_SUCCESS(Status))
67 {
68 UCHAR Lcr;
69 TRACE_(SERIAL, "SerialSetBaudRate(COM%lu, %lu Bauds)\n", DeviceExtension->ComPort, BaudRate);
70 /* Set Bit 7 of LCR to expose baud registers */
71 Lcr = READ_PORT_UCHAR(SER_LCR(ComPortBase));
72 WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr | SR_LCR_DLAB);
73 /* Write the baud rate */
74 WRITE_PORT_UCHAR(SER_DLL(ComPortBase), divisor & 0xff);
75 WRITE_PORT_UCHAR(SER_DLM(ComPortBase), divisor >> 8);
76 /* Switch back to normal registers */
77 WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr);
78
79 IoReleaseRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort));
80 }
81
82 if (NT_SUCCESS(Status))
83 DeviceExtension->BaudRate = BaudRate;
84 return Status;
85}
#define BAUD_CLOCK
Definition: serial.h:105
#define SR_LCR_DLAB
Definition: serial.h:148
#define CLOCKS_PER_BIT
Definition: serial.h:106
#define SER_DLL(x)
Definition: serial.h:111
#define SER_DLM(x)
Definition: serial.h:119
GLuint divisor
Definition: glext.h:6313
unsigned short USHORT
Definition: pedump.c:61
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

◆ SerialSetLineControl()

NTSTATUS NTAPI SerialSetLineControl ( IN PSERIAL_DEVICE_EXTENSION  DeviceExtension,
IN PSERIAL_LINE_CONTROL  NewSettings 
)

Definition at line 88 of file devctrl.c.

91{
92 PUCHAR ComPortBase;
93 UCHAR Lcr = 0;
95
96 ASSERT(DeviceExtension);
97 ASSERT(NewSettings);
98
99 TRACE_(SERIAL, "SerialSetLineControl(COM%lu, Settings { %lu %lu %lu })\n",
100 DeviceExtension->ComPort, NewSettings->StopBits, NewSettings->Parity, NewSettings->WordLength);
101
102 /* Verify parameters */
103 switch (NewSettings->WordLength)
104 {
105 case 5: Lcr |= SR_LCR_CS5; break;
106 case 6: Lcr |= SR_LCR_CS6; break;
107 case 7: Lcr |= SR_LCR_CS7; break;
108 case 8: Lcr |= SR_LCR_CS8; break;
109 default: return STATUS_INVALID_PARAMETER;
110 }
111
112 if (NewSettings->WordLength < 5 || NewSettings->WordLength > 8)
114
115 switch (NewSettings->Parity)
116 {
117 case NO_PARITY: Lcr |= SR_LCR_PNO; break;
118 case ODD_PARITY: Lcr |= SR_LCR_POD; break;
119 case EVEN_PARITY: Lcr |= SR_LCR_PEV; break;
120 case MARK_PARITY: Lcr |= SR_LCR_PMK; break;
121 case SPACE_PARITY: Lcr |= SR_LCR_PSP; break;
122 default: return STATUS_INVALID_PARAMETER;
123 }
124
125 switch (NewSettings->StopBits)
126 {
127 case STOP_BIT_1:
128 Lcr |= SR_LCR_ST1;
129 break;
130 case STOP_BITS_1_5:
131 if (NewSettings->WordLength != 5)
133 Lcr |= SR_LCR_ST2;
134 break;
135 case STOP_BITS_2:
136 if (NewSettings->WordLength < 6 || NewSettings->WordLength > 8)
138 Lcr |= SR_LCR_ST2;
139 break;
140 default:
142 }
143
144 /* Update current parameters */
145 ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
146 Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort));
147 if (!NT_SUCCESS(Status))
148 return Status;
149 WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr);
150
151 /* Read junk out of RBR */
152 READ_PORT_UCHAR(SER_RBR(ComPortBase));
153 IoReleaseRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort));
154
155 if (NT_SUCCESS(Status))
156 DeviceExtension->SerialLineControl = *NewSettings;
157
158 return Status;
159}
#define SR_LCR_ST2
Definition: serial.h:141
#define SR_LCR_PMK
Definition: serial.h:145
#define SR_LCR_PSP
Definition: serial.h:146
#define SR_LCR_CS8
Definition: serial.h:139
#define SR_LCR_ST1
Definition: serial.h:140
#define SR_LCR_CS6
Definition: serial.h:137
#define SR_LCR_CS7
Definition: serial.h:138
#define SR_LCR_PNO
Definition: serial.h:142
#define SR_LCR_CS5
Definition: serial.h:136
#define SR_LCR_POD
Definition: serial.h:143
#define SR_LCR_PEV
Definition: serial.h:144
#define STOP_BITS_2
Definition: serial.c:87
#define EVEN_PARITY
Definition: serial.c:91
#define ODD_PARITY
Definition: serial.c:90
#define MARK_PARITY
Definition: ntddser.h:223
#define SPACE_PARITY
Definition: ntddser.h:224
#define STOP_BITS_1_5
Definition: ntddser.h:216

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

Variable Documentation

◆ ForwardIrpAndForget

DRIVER_DISPATCH ForwardIrpAndForget

Definition at line 245 of file serial.h.

◆ SerialAddDevice

DRIVER_ADD_DEVICE SerialAddDevice

Definition at line 280 of file serial.h.

Referenced by DriverEntry().

◆ SerialCleanup

DRIVER_DISPATCH SerialCleanup

Definition at line 209 of file serial.h.

Referenced by DriverEntry().

◆ SerialClose

DRIVER_DISPATCH SerialClose

Definition at line 213 of file serial.h.

Referenced by DriverEntry().

◆ SerialCreate

DRIVER_DISPATCH SerialCreate

Definition at line 217 of file serial.h.

Referenced by DriverEntry().

◆ SerialDeviceControl

DRIVER_DISPATCH SerialDeviceControl

Definition at line 221 of file serial.h.

Referenced by DriverEntry().

◆ SerialInterruptService

KSERVICE_ROUTINE SerialInterruptService

Definition at line 268 of file serial.h.

Referenced by SerialPnpStartDevice().

◆ SerialPnp

DRIVER_DISPATCH SerialPnp

Definition at line 288 of file serial.h.

Referenced by DriverEntry().

◆ SerialPower

DRIVER_DISPATCH SerialPower

Definition at line 292 of file serial.h.

Referenced by DriverEntry().

◆ SerialQueryInformation

DRIVER_DISPATCH SerialQueryInformation

Definition at line 235 of file serial.h.

Referenced by DriverEntry().

◆ SerialRead

DRIVER_DISPATCH SerialRead

Definition at line 296 of file serial.h.

Referenced by DriverEntry().

◆ SerialWrite

DRIVER_DISPATCH SerialWrite

Definition at line 297 of file serial.h.

Referenced by DriverEntry().