ReactOS 0.4.16-dev-2528-g7139e57
inbvport.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * PURPOSE: Serial Port Boot Driver for Headless Terminal Support
5 * COPYRIGHT: Copyright 2010 ReactOS Portable Systems Group
6 * Copyright 2022-2026 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ntoskrnl.h>
12#include <cportlib/cportlib.h>
13#include <cportlib/uartinfo.h>
14
15/* GLOBALS *******************************************************************/
16
18{
19 {NULL, 0, TRUE},
20 {NULL, 0, TRUE},
21 {NULL, 0, TRUE},
22 {NULL, 0, TRUE}
23};
24
25/* FUNCTIONS *****************************************************************/
26
30 _In_ ULONG PortId)
31{
32 UCHAR Dummy;
33
34 /* Poll a byte from the port */
35 return CpGetByte(&Port[PortId], &Dummy, FALSE, TRUE) == CP_GET_SUCCESS;
36}
37
41 _In_ ULONG PortId,
43{
44 /* Read a byte from the port */
45 return CpGetByte(&Port[PortId], Byte, TRUE, FALSE) == CP_GET_SUCCESS;
46}
47
48VOID
51 _In_ ULONG PortId,
53{
54 /* Send the byte */
55 CpPutByte(&Port[PortId], Byte);
56}
57
58VOID
61 _In_ ULONG PortId,
63{
64 /* Set FIFO as requested */
66}
67
68VOID
71 _In_ ULONG PortId)
72{
73 /* The port is now available */
74 Port[PortId].Address = NULL;
75}
76
80 _In_ ULONG BaudRate,
82 _In_ PUCHAR PortAddress,
83 _Out_ PULONG PortId,
84 _In_ BOOLEAN IsMMIODevice)
85{
86 /* Not yet supported */
87 ASSERT(IsMMIODevice == FALSE);
88
89 /* Set the default baud rate */
90 if (BaudRate == 0)
91 BaudRate = DEFAULT_BAUD_RATE;
92
93 /* Check if the port or address is given */
94 if (PortNumber)
95 {
96 /* Pick correct address for port */
97 if (!PortAddress)
98 {
99 if (PortNumber < 1 || PortNumber > MAX_COM_PORTS)
101 PortAddress = UlongToPtr(BaseArray[PortNumber]);
102 }
103 }
104 else
105 {
106 /* Pick correct port for address */
107#if defined(SARCH_PC98)
108 static const ULONG TestPorts[] = {1, 2};
109#else
110 static const ULONG TestPorts[] = {2, 1};
111#endif
112 PortAddress = UlongToPtr(BaseArray[TestPorts[0]]);
113 if (CpDoesPortExist(PortAddress))
114 {
115 PortNumber = TestPorts[0];
116 }
117 else
118 {
119 PortAddress = UlongToPtr(BaseArray[TestPorts[1]]);
120 if (!CpDoesPortExist(PortAddress))
121 return FALSE;
122 PortNumber = TestPorts[1];
123 }
124 }
125
126 /* Initialize the port unless it's already up and return it */
127 if (Port[PortNumber - 1].Address)
128 return FALSE;
129
130 CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate);
131 *PortId = PortNumber - 1;
132 return TRUE;
133}
134
135/* EOF */
unsigned char BOOLEAN
Definition: actypes.h:127
USHORT NTAPI CpGetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte, _In_ BOOLEAN Wait, _In_ BOOLEAN Poll)
Definition: cport.c:82
#define CP_GET_SUCCESS
Definition: cportlib.h:17
VOID NTAPI CpPutByte(_Inout_ PCPPORT Port, _In_ UCHAR Byte)
Definition: cport.c:93
NTSTATUS NTAPI CpInitialize(_Inout_ PCPPORT Port, _In_ PUCHAR Address, _In_ ULONG BaudRate)
Definition: cport.c:59
BOOLEAN NTAPI CpDoesPortExist(_In_ PUCHAR Address)
Definition: cport.c:33
VOID NTAPI CpEnableFifo(_In_ PUCHAR Address, _In_ BOOLEAN Enable)
Definition: cport.c:41
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned char Byte
Definition: zlib.h:37
#define UlongToPtr(u)
Definition: config.h:106
BOOLEAN NTAPI InbvPortInitialize(_In_ ULONG BaudRate, _In_ ULONG PortNumber, _In_ PUCHAR PortAddress, _Out_ PULONG PortId, _In_ BOOLEAN IsMMIODevice)
Definition: inbvport.c:79
CPPORT Port[4]
Definition: inbvport.c:17
VOID NTAPI InbvPortTerminate(_In_ ULONG PortId)
Definition: inbvport.c:70
BOOLEAN NTAPI InbvPortGetByte(_In_ ULONG PortId, _Out_ PUCHAR Byte)
Definition: inbvport.c:40
VOID NTAPI InbvPortEnableFifo(_In_ ULONG PortId, _In_ BOOLEAN Enable)
Definition: inbvport.c:60
BOOLEAN NTAPI InbvPortPollOnly(_In_ ULONG PortId)
Definition: inbvport.c:29
VOID NTAPI InbvPortPutByte(_In_ ULONG PortId, _In_ UCHAR Byte)
Definition: inbvport.c:50
#define MAX_COM_PORTS
Definition: machpc.c:29
#define ASSERT(a)
Definition: mode.c:44
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
static WCHAR Address[46]
Definition: ping.c:68
ULONG PortNumber
Definition: storport.c:18
PUCHAR Address
Definition: cportlib.h:28
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define DEFAULT_BAUD_RATE
Definition: uartinfo.h:24
unsigned char UCHAR
Definition: xmlstorage.h:181