ReactOS  0.4.10-dev-234-g15c29d0
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_EXTENSION
PSERIAL_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)
 
NTSTATUS ForwardIrpAndWait (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
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

#define BAUD_CLOCK   1843200

Definition at line 105 of file serial.h.

Referenced by SerialSetBaudRate().

#define CLOCKS_PER_BIT   16

Definition at line 106 of file serial.h.

Referenced by SerialSetBaudRate().

#define COMMPROP_INITIALIZED   0xE73CF52E

Definition at line 18 of file serial.h.

Referenced by SerialGetCommProp().

#define INFINITE   MAXULONG

Definition at line 102 of file serial.h.

Referenced by _cwait(), _pclose(), _read_request_data(), _send_response_and_wait(), _tWinMain(), AcquireEntrypointMutex(), AcsHlpSendCommand(), ANIMATE_DoStop(), apartment_freeunusedlibraries(), apartment_hostobject_in_hostapt(), async_proc(), AtlWaitWithMessageLoop(), AVISplitter_thread_reader(), BackgroundCopyJob_Cancel(), BaseFormatTimeOut(), BaseMemAllocator_GetBuffer(), BasepDoTapeOperation(), cache_container_lock_index(), cache_container_open_index(), cache_lock(), CallSessionThread(), CallSoundThread(), CallUninstall(), cancel_request(), cfgets(), check_dinput_hooks(), check_hook_thread(), check_thread_instance(), child_process_write_pipe(), CKsClockForwarder_ThreadStartup(), cleanReq(), client_start(), ClientRpcChannelBuffer_SendReceive(), clipboard_wnd_proc(), clnt_vc_destroy(), close_async_handle(), close_request(), CloseDevice(), CM_Add_Range(), CM_First_Range(), CM_Free_Range_List(), cmd_start(), CoFreeUnusedLibraries(), ComDBClaimNextFreePort(), ComDBClaimPort(), ComDBGetCurrentPortUsage(), ComDBOpen(), ComDBReleasePort(), ComDBResizeDatabase(), CommandThreadProc(), CommonInstall(), ConsoleEventThread(), COutputPin_SetState(), CoWaitForMultipleHandles(), create_window_thread(), CreateClientProcess(), CreateContext(), CreateRenderingSubsystem(), CreateRenderingWindow(), CreateServers(), CreateServiceThread(), CRYPT_ImportSystemRootCertsToReg(), BtrfsVolPropSheet::DeviceDlgProc(), DeviceInstallThread(), dialog_run_message_loop(), dispatch(), dispatch_rpc(), do_spawnT(), do_test(), doChildren(), doDebugger(), DoEntry(), TMouse::doMouse(), DosStartProcess32(), download_url(), DPL_MSG_ThreadMain(), DSoundRender_BreakConnect(), DSoundRender_Release(), dummy_thread_proc(), end_host_object(), ensurePlayerThread(), EnumJoysticks(), event_client(), Execute(), ExecutePipeline(), exercizeServer(), ExitWindowsWorker(), file_layout_return(), fileTransfer(), free_urlcache(), FreeUrlCacheSpaceW(), get_nt_timeout(), GetNtTimeout(), GetOverlappedResult(), GetPwrDiskSpindownRange(), GetSocketInformation(), TTelnetHandler::Go(), GPNotificationThreadProc(), GUIDisplayStatusMessage(), GuiInit(), GuiInitFrontEnd(), HandleLogoff(), HandleShutdown(), IDirectInputDevice2WImpl_GetDeviceData(), IDirectSoundCaptureBufferImpl_Stop(), ifproxy_get_public_ref(), ifproxy_release_public_refs(), CDesktopThread::Initialize(), InitPropertiesDlg(), InputWait(), install_wine_gecko(), InstallDevice(), InternetReadFile_test(), InternetReadFileExA_test(), BtrfsContextMenu::InvokeCommand(), COutputPin::IoProcessRoutine(), ITERATE_RemoveExistingProducts(), ITextHostImpl_TxGetMaxLength(), launch_exe(), layout_fetch(), LoadScreenSaverParameters(), local_server_thread(), Mutex::Lock(), LockAudioDeviceList(), logMess(), LogToFile(), LookupThreadProc(), MailSlotReader(), main(), MainLoop(), MCI_SendCommandAsync(), MCICDA_Play(), MCICDA_Stop(), MCIQTZ_mciStop(), MCIQTZ_notifyThread(), MediaControl_GetState(), MIDI_mciPlay(), MIDI_mciStop(), midiStreamOpen(), MixerEventThreadRoutine(), MMSYSTEM_MidiStream_PostMessage(), MonitorChildThread(), MouseEventHandler(), MouseGetDataFast(), MouseGetPacket(), msi_dialog_check_messages(), StringTest::mt(), MULTIMEDIA_PlaySound(), NBCmdQueueCancel(), nfs41_delegate_open(), nfs41_delegation_return(), nfs41_delegation_to_open(), nfs41_open_stateid_arg(), nfs41_recover_stateid(), nfs41_recovery_start_or_wait(), nfs41_send_compound(), nfs41_session_get_slot(), NotifyTopLevelWindow(), ole_server(), oob_client(), BtrfsPropSheet::open_as_admin(), open_read_test_request(), open_socket_request(), OpenMidiDevice(), OpenSharedMemory(), OutputDebugStringA(), OutputQueueImpl_ThreadProc(), overlapped_server(), ParseFailureArguments(), Parser_Destroy(), Parser_PullPin_Disconnect(), Parser_Stop(), pattern_join(), BtrfsBalance::PauseBalance(), PdhCloseQuery(), PdhCollectQueryDataEx(), pipeserver(), audio_waveout::playing_procedure(), PlaySound_WaitDone(), ProcessPlayingNotes(), processRequest(), PS2PortQueueRead(), PS2QueuePush(), PullPin_BeginFlush(), PullPin_Disconnect(), PullPin_EndFlush(), PullPin_InitProcessing(), PullPin_PauseProcessing(), PullPin_Release(), PullPin_StartProcessing(), PullPin_StopProcessing(), PullPin_Thread_Main(), QualityControlRender_WaitFor(), queue_get_timeout(), read_pipe(), audio_wavein::recording_procedure(), ReferenceClock_AdvisePeriodic(), ReferenceClock_AdviseTime(), report(), BtrfsVolPropSheet::ResetStats(), RPC_StopLocalServer(), RpcMgmtWaitServerListen(), RpcReadFile(), rpcrt4_conn_np_read(), rpcrt4_conn_np_write(), rpcrt4_conn_release_and_wait(), rpcrt4_protseq_np_wait_for_new_connection(), rpcrt4_protseq_sock_wait_for_new_connection(), rpcrt4_sock_wait_for_recv(), rpcrt4_sock_wait_for_send(), RPCRT4_sync_with_server_thread(), RpcServerUnregisterIf(), SSOThread::Run(), run_cmd(), run_script_file(), runCmd(), RunControlPanelApplet(), runProg(), RunSetupThreadProc(), RunTests(), ScmWaitForLsa(), ScreensaverPreview(), ScreenSaverThreadMain(), scrollkeys(), send_msg_thread_2(), send_socket_request(), SendGetState(), SendMessage_thread_1(), SendMessage_thread_2(), SerialRead(), serv_main(), server_send_reply(), server_thread(), serverThreadMain3(), serverThreadMain5(), service_main(), ServiceExecutionThread(), ServiceMain(), ServiceStart(), SetSocketInformation(), SHCreateThread(), BtrfsVolPropSheet::ShowScrub(), SHWaitForSendMessageThread(), simple_client(), simple_mixed_client(), smresult_thread_proc(), smresult_wndproc(), SoundThreadMain(), SpeakerChange(), start_dummy_thread(), start_host_object2(), START_TEST(), StartApplication(), BtrfsBalance::StartBalance(), StartClients(), StartProcess(), CProgressDialog::StartProgressDialog(), StartScreenSaver(), StartSessionThread(), StartStopEnumEventsThread(), StartTestCORE10188(), CKsClockForwarder::Stop(), stop_dummy_thread(), audio_wavein::stop_recording(), BtrfsBalance::StopBalance(), SvcRegisterStopCallback(), SystemClockAdviseThread(), SystemClockImpl_Release(), task_proc(), tcp_recv(), tcp_send(), telProcessConsole(), TerminateSoundThread(), Test2(), Test3(), test_accept(), test_AcceptEx(), test_activateapp(), test_alertable(), test_async(), test_async_file_errors(), test_async_read(), test_attach_input(), test_bsc_marshaling(), Test_CloseWhileSelectDuplicatedSocket(), Test_CloseWhileSelectSameSocket(), Test_CommandLine(), test_conn_close(), test_connection_cache(), test_connection_closing(), test_CreateProcessWithDesktop(), test_ddeml_server(), test_debug_children(), test_debug_loop(), test_DebuggingFlag(), test_default_ime_window_creation(), test_deletecontext(), test_end_to_end_server(), test_filter_graph(), test_foregroundwindow(), test_gettext(), test_handles(), test_ImmDefaultHwnd(), test_ImmThreads(), test_ImpersonateNamedPipeClient(), test_Input_mouse(), test_interthread_messages(), test_messages(), test_msg_server(), test_mutex(), test_no_content(), test_nonalertable(), test_NtAtom(), test_NtSuspendProcess(), test_open_url_async(), test_overlapped(), test_PdhCollectQueryDataEx(), test_PeekMessage(), test_persistent_connection(), test_query_process_debug_object_handle(), test_query_process_debug_port(), test_reader_info(), Test_recv(), test_redirect(), test_RegisterWaitForSingleObject(), test_RtlRegisterWait(), test_runner(), test_security_flags(), test_select(), test_SetFocus(), test_SetForegroundWindow(), test_SetMaxRunTime_GetMaxRunTime(), test_shell_window(), test_smresult(), test_state_change(), test_successive_HttpSendRequest(), test_thread_handle_close(), test_thread_objects(), test_threads(), test_timers(), test_winevents(), TestProc(), TestRecursiveInterThreadMessages(), TestShellExecuteEx(), testWaitForConsoleInput(), ThemeStartCallback(), ThemeWatchForStart(), thread(), thread1(), thread2(), thread_main1(), thread_main2(), thread_proc(), CDownloadManager::ThreadFunc(), threadFunc1(), TIME_MMSysTimeCallback(), TIME_MMTimeStop(), timeKillEvent(), timer_queue_thread_proc(), UninitializeGPNotifications(), UserpFormatMessages(), UserServerHardError(), VdmShutdown(), VgaUpdateFramebuffer(), VideoRenderer_EndFlush(), VideoRendererInner_Release(), VMR9_SurfaceAllocator_TerminateDevice(), wait_for_completion(), wait_for_thread(), waitforkey(), WaitForLsass(), WaitForMachinePolicyForegroundProcessing(), WaitForSettingsDialog(), WaitForUserPolicyForegroundProcessing(), WatchDirectory(), CIconWatcher::WatcherThread(), wave_in_test_deviceIn(), WAVE_mciPlayWaitDone(), WAVE_mciRecordWaitDone(), WaveThread(), wbem_services_CancelAsyncCall(), wbem_services_Release(), WdmAudCommitWaveBufferByLegacy(), wined3d_cs_wait_event(), winhttp_request_Send(), winhttp_request_WaitForResponse(), WinMain(), WriteFileEx_Remixer(), WsAsyncThread(), WshShell3_Popup(), WSPAccept(), WSPBind(), WSPCloseSocket(), WSPConnect(), WSPEnumNetworkEvents(), WSPEventSelect(), WSPGetPeerName(), WSPGetSockName(), WSPListen(), WSPRecv(), WSPRecvFrom(), WSPSelect(), WSPSend(), WSPSendTo(), WSPShutdown(), WSPSocket(), wWinMain(), xmlMutexLock(), and CThread::~CThread().

#define PST_RS232   1

Definition at line 17 of file serial.h.

Referenced by GetCommConfig(), GetCommProperties(), and SerialGetCommProp().

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

Definition at line 111 of file serial.h.

Referenced by SerialSetBaudRate().

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

Definition at line 119 of file serial.h.

Referenced by SerialSetBaudRate().

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

Definition at line 127 of file serial.h.

Referenced by SerialDetectUartType(), SerialDeviceControl(), and SerialPnpStartDevice().

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

Definition at line 120 of file serial.h.

Referenced by SerialDetectUartType(), and SerialInterruptService().

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

Definition at line 135 of file serial.h.

Referenced by SerialDetectUartType(), SerialSetBaudRate(), and SerialSetLineControl().

#define SER_LSR (   x)    ((PUCHAR)(x)+5) /* Line Status Register */
#define SER_MCR (   x)    ((PUCHAR)(x)+4) /* Modem Control Register */

Definition at line 149 of file serial.h.

Referenced by SerialDetectUartType(), SerialDeviceControl(), and SerialPnpStartDevice().

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

Definition at line 161 of file serial.h.

Referenced by SerialDetectUartType(), SerialInterruptService(), and SerialPnpStartDevice().

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

Definition at line 109 of file serial.h.

Referenced by SerialDetectUartType(), SerialReceiveByte(), and SerialSetLineControl().

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

Definition at line 170 of file serial.h.

Referenced by SerialDetectUartType().

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

Definition at line 110 of file serial.h.

Referenced by SerialSendByte().

#define SI_MSR_RI   SERIAL_RI_STATE /* Ring Indicator */

Definition at line 168 of file serial.h.

Referenced by SerialInterruptService().

#define SR_FCR_14_BYTES   (0xC0 | SR_FCR_ENABLE_FIFO)

Definition at line 134 of file serial.h.

#define SR_FCR_1_BYTE   (0x00 | SR_FCR_ENABLE_FIFO)

Definition at line 131 of file serial.h.

#define SR_FCR_4_BYTES   (0x40 | SR_FCR_ENABLE_FIFO)

Definition at line 132 of file serial.h.

#define SR_FCR_8_BYTES   (0x80 | SR_FCR_ENABLE_FIFO)

Definition at line 133 of file serial.h.

#define SR_FCR_CLEAR_RCVR   (0x02 | SR_FCR_ENABLE_FIFO)

Definition at line 129 of file serial.h.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

#define SR_FCR_CLEAR_XMIT   (0x04 | SR_FCR_ENABLE_FIFO)

Definition at line 130 of file serial.h.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

#define SR_FCR_ENABLE_FIFO   0x01

Definition at line 128 of file serial.h.

Referenced by SerialDetectUartType().

#define SR_IER_DATA_RECEIVED   0x01

Definition at line 113 of file serial.h.

Referenced by SerialPnpStartDevice(), and SerialReceiveByte().

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

Definition at line 118 of file serial.h.

#define SR_IER_LSR_CHANGE   0x04

Definition at line 115 of file serial.h.

Referenced by SerialPnpStartDevice().

#define SR_IER_MSR_CHANGE   0x08

Definition at line 116 of file serial.h.

Referenced by SerialInterruptService(), and SerialPnpStartDevice().

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

Definition at line 117 of file serial.h.

#define SR_IER_THR_EMPTY   0x02

Definition at line 114 of file serial.h.

Referenced by SerialPnpStartDevice(), and SerialSendByte().

#define SR_IIR_DATA_RECEIVED   (SR_IIR_SELF | 4)

Definition at line 125 of file serial.h.

Referenced by SerialInterruptService().

#define SR_IIR_ERROR   (SR_IIR_SELF | 6)

Definition at line 126 of file serial.h.

Referenced by SerialInterruptService().

#define SR_IIR_ID_MASK   0x07

Definition at line 122 of file serial.h.

Referenced by SerialInterruptService().

#define SR_IIR_MSR_CHANGE   SR_IIR_SELF

Definition at line 123 of file serial.h.

Referenced by SerialInterruptService().

#define SR_IIR_SELF   0x00

Definition at line 121 of file serial.h.

Referenced by SerialInterruptService().

#define SR_IIR_THR_EMPTY   (SR_IIR_SELF | 2)

Definition at line 124 of file serial.h.

Referenced by SerialInterruptService().

#define SR_LCR_BRK   0x40

Definition at line 147 of file serial.h.

#define SR_LCR_CS5   0x00

Definition at line 136 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_CS6   0x01

Definition at line 137 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_CS7   0x02

Definition at line 138 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_CS8   0x03

Definition at line 139 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_DLAB   0x80

Definition at line 148 of file serial.h.

Referenced by SerialSetBaudRate().

#define SR_LCR_PEV   0x18

Definition at line 144 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_PMK   0x28

Definition at line 145 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_PNO   0x00

Definition at line 142 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_POD   0x08

Definition at line 143 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_PSP   0x38

Definition at line 146 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_ST1   0x00

Definition at line 140 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LCR_ST2   0x04

Definition at line 141 of file serial.h.

Referenced by SerialSetLineControl().

#define SR_LSR_BREAK_INT   0x10

Definition at line 157 of file serial.h.

Referenced by SerialInterruptService().

#define SR_LSR_DATA_RECEIVED   0x01

Definition at line 153 of file serial.h.

Referenced by SerialReceiveByte().

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

Definition at line 160 of file serial.h.

#define SR_LSR_FRAMING_ERROR   0x08

Definition at line 156 of file serial.h.

Referenced by SerialInterruptService().

#define SR_LSR_OVERRUN_ERROR   0x02

Definition at line 154 of file serial.h.

Referenced by SerialInterruptService().

#define SR_LSR_PARITY_ERROR   0x04

Definition at line 155 of file serial.h.

Referenced by SerialInterruptService().

#define SR_LSR_THR_EMPTY   0x20

Definition at line 158 of file serial.h.

Referenced by SerialSendByte().

#define SR_LSR_TSR_EMPTY   0x40

Definition at line 159 of file serial.h.

#define SR_MCR_DTR   SERIAL_DTR_STATE

Definition at line 150 of file serial.h.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

#define SR_MCR_RTS   SERIAL_RTS_STATE

Definition at line 151 of file serial.h.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

#define SR_MSR_CTS   SERIAL_CTS_STATE /* Clear To Send */

Definition at line 166 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_CTS_CHANGED   0x01

Definition at line 162 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_DCD   SERIAL_DCD_STATE /* Data Carrier Detect */

Definition at line 169 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_DCD_CHANGED   0x08

Definition at line 165 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_DSR   SERIAL_DSR_STATE /* Data Set Ready */

Definition at line 167 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_DSR_CHANGED   0x02

Definition at line 163 of file serial.h.

Referenced by SerialInterruptService().

#define SR_MSR_RI_CHANGED   0x04

Definition at line 164 of file serial.h.

Referenced by SerialInterruptService().

Typedef Documentation

Enumeration Type Documentation

Enumerator
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 

Definition at line 20 of file serial.h.

21 {
22  dsStopped,
23  dsStarted,
24  dsPaused,
25  dsRemoved,
SERIAL_DEVICE_STATE
Definition: serial.h:20
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:29

Function Documentation

NTSTATUS ForwardIrpAndWait ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 32 of file fdo.c.

35 {
36  KEVENT Event;
39  ASSERT(LowerDevice);
40 
43 
45 
46  Status = IoCallDriver(LowerDevice, Irp);
47  if (Status == STATUS_PENDING)
48  {
50  if (NT_SUCCESS(Status))
51  Status = Irp->IoStatus.Status;
52  }
53 
54  return Status;
55 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
ACPI_EFI_EVENT Event
Definition: acefiex.h:633
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_PENDING
Definition: ntstatus.h:82
static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
Definition: fdo.c:17
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
NTSTATUS FreeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 30 of file circularbuffer.c.

Referenced by SerialAddDeviceInternal().

32 {
33  TRACE_(SERIAL, "FreeCircularBuffer(pBuffer %p)\n", pBuffer);
34  ASSERT(pBuffer);
35  if (pBuffer->Buffer != NULL)
37  return STATUS_SUCCESS;
38 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2690
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG GetNumberOfElementsInCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 50 of file circularbuffer.c.

Referenced by SerialInterruptService().

52 {
53  TRACE_(SERIAL, "GetNumberOfElementsInCircularBuffer(pBuffer %p)\n", pBuffer);
54  ASSERT(pBuffer);
55  return (pBuffer->WritePosition + pBuffer->Length - pBuffer->ReadPosition) % pBuffer->Length;
56 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
NTSTATUS IncreaseCircularBufferSize ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  NewBufferSize 
)

Definition at line 91 of file circularbuffer.c.

Referenced by SerialDeviceControl().

94 {
95  PUCHAR NewBuffer;
96 
97  TRACE_(SERIAL, "IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
98  ASSERT(pBuffer);
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 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2690
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSTATUS InitializeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  BufferSize 
)

Definition at line 15 of file circularbuffer.c.

Referenced by SerialAddDeviceInternal().

18 {
19  TRACE_(SERIAL, "InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
20  ASSERT(pBuffer);
22  if (!pBuffer->Buffer)
24  pBuffer->Length = BufferSize;
25  pBuffer->ReadPosition = pBuffer->WritePosition = 0;
26  return STATUS_SUCCESS;
27 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2690
unsigned char * PUCHAR
Definition: retypes.h:3
#define BufferSize
Definition: acefiex.h:377
UINTN * BufferSize
Definition: acefiex.h:370
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOLEAN IsCircularBufferEmpty ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 41 of file circularbuffer.c.

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

43 {
44  TRACE_(SERIAL, "IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
45  ASSERT(pBuffer);
46  return (pBuffer->ReadPosition == pBuffer->WritePosition);
47 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
NTSTATUS PopCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
OUT PUCHAR  Entry 
)

Definition at line 76 of file circularbuffer.c.

Referenced by ReadBytes(), and SerialSendByte().

79 {
80  TRACE_(SERIAL, "PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
81  ASSERT(pBuffer);
82  ASSERT(pBuffer->Length);
85  *Entry = pBuffer->Buffer[pBuffer->ReadPosition];
86  pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
87  return STATUS_SUCCESS;
88 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2690
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:362
base of all file and directory entries
Definition: entries.h:82
NTSTATUS PushCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
IN UCHAR  Entry 
)

Definition at line 59 of file circularbuffer.c.

Referenced by SerialReceiveByte(), and SerialWrite().

62 {
63  ULONG NextPosition;
64  TRACE_(SERIAL, "PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
65  ASSERT(pBuffer);
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 }
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2690
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:52
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
if(!(yy_init))
Definition: macro.lex.yy.c:717
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82
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.

Referenced by SerialAddDevice().

24 {
25  PDEVICE_OBJECT Fdo = NULL;
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);
41  &DeviceName,
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);
82  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
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 
100  if (pFdo)
101  {
102  *pFdo = Fdo;
103  }
104 
105  return STATUS_SUCCESS;
106 
107 ByeBye:
108  if (Fdo)
109  {
110  FreeCircularBuffer(&DeviceExtension->InputBuffer);
111  FreeCircularBuffer(&DeviceExtension->OutputBuffer);
112  IoDeleteDevice(Fdo);
113  }
114  return Status;
115 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
SERIAL_DEVICE_STATE PnpState
Definition: serial.h:52
CIRCULAR_BUFFER OutputBuffer
Definition: serial.h:77
NTSTATUS FreeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer)
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2785
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2690
VOID NTAPI SerialCompleteIrp(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID pIrp, IN PVOID Unused)
Definition: misc.c:145
UNICODE_STRING SerialInterfaceName
Definition: serial.h:80
KSPIN_LOCK InputBufferLock
Definition: serial.h:76
WCHAR DeviceName[]
Definition: adapter.cpp:21
PDEVICE_OBJECT Pdo
Definition: serial.h:50
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
KEVENT InputBufferNotEmpty
Definition: serial.h:74
KSPIN_LOCK OutputBufferLock
Definition: serial.h:78
#define FALSE
Definition: types.h:117
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:779
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1087
VOID NTAPI SerialReceiveByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:70
IO_REMOVE_LOCK RemoveLock
Definition: serial.h:53
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1024
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:959
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS InitializeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
VOID NTAPI SerialSendByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:107
CIRCULAR_BUFFER InputBuffer
Definition: serial.h:75
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:830
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PDEVICE_OBJECT LowerDevice
Definition: serial.h:51
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
#define FILE_DEVICE_SERIAL_PORT
Definition: serial.c:44
#define WARN_(ch,...)
Definition: debug.h:155
UART_TYPE UartType
Definition: serial.h:66
VOID NTAPI SerialCompleteIrp ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  pIrp,
IN PVOID  Unused 
)

Definition at line 145 of file misc.c.

Referenced by SerialAddDeviceInternal().

150 {
152 }
#define IoCompleteRequest
Definition: irp.c:1240
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
UART_TYPE SerialDetectUartType ( IN PUCHAR  ComPortBase)

Definition at line 16 of file legacy.c.

Referenced by SerialPnpStartDevice().

18 {
19  UCHAR Lcr, TestLcr;
20  UCHAR OldScr, Scr5A, ScrA5;
21  BOOLEAN FifoEnabled;
22  UCHAR NewFifoStatus;
23 
25  WRITE_PORT_UCHAR(SER_LCR(BaseAddress), Lcr ^ 0xFF);
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 */
56  FifoEnabled = (READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0x80) != 0;
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 }
#define SER_FCR(x)
Definition: serial.h:127
#define SER_RBR(x)
Definition: serial.h:109
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
#define SER_LCR(x)
Definition: serial.h:135
#define SER_MSR(x)
Definition: serial.h:161
unsigned char BOOLEAN
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define SER_IIR(x)
Definition: serial.h:120
#define SR_FCR_ENABLE_FIFO
Definition: serial.h:128
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SER_SCR(x)
Definition: serial.h:170
#define SER_LSR(x)
Definition: serial.h:152
#define SER_MCR(x)
Definition: serial.h:149
#define SER_IER(x)
Definition: serial.h:112
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
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.

Referenced by SerialPnp().

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;
152  KAFFINITY Affinity = 0;
154  BOOLEAN ShareInterrupt = TRUE;
155  OBJECT_ATTRIBUTES objectAttributes;
156  PUCHAR ComPortBase;
158  HANDLE hKey;
160 
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  {
197  case CmResourceTypePort:
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)
209  InterruptMode = Latched;
210  else
211  InterruptMode = LevelSensitive;
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);
274  Status = IoCreateSymbolicLink(&LinkName, &DeviceName);
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 */
282  Status = IoConnectInterrupt(
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");
299  InitializeObjectAttributes(&objectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
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 STATUS_REVISION_MISMATCH
Definition: ntstatus.h:311
NTSTATUS NTAPI SerialSetLineControl(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN PSERIAL_LINE_CONTROL NewSettings)
Definition: devctrl.c:88
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
SERIAL_DEVICE_STATE PnpState
Definition: serial.h:52
#define TRUE
Definition: types.h:120
#define SER_FCR(x)
Definition: serial.h:127
#define ULongToPtr(ul)
Definition: basetsd.h:92
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:798
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STOP_BIT_1
Definition: ntddser.h:215
#define INFO_(ch,...)
Definition: debug.h:157
#define KEY_SET_VALUE
Definition: nt_native.h:1017
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
return STATUS_SUCCESS
Definition: btrfs.c:2690
#define SR_IER_MSR_CHANGE
Definition: serial.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
SERIAL_LINE_CONTROL SerialLineControl
Definition: serial.h:65
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
KSERVICE_ROUTINE SerialInterruptService
Definition: serial.h:273
#define SR_IER_THR_EMPTY
Definition: serial.h:114
UNICODE_STRING SerialInterfaceName
Definition: serial.h:80
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define SER_MSR(x)
Definition: serial.h:161
static PUCHAR ResourceList[1+IDB_MAX_RESOURCE]
Definition: inbv.c:44
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376 u
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define SR_IER_DATA_RECEIVED
Definition: serial.h:113
#define SR_FCR_CLEAR_XMIT
Definition: serial.h:130
#define FALSE
Definition: types.h:117
#define SR_IER_LSR_CHANGE
Definition: serial.h:115
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:22
#define IER
Definition: serial_port.h:62
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
enum _KINTERRUPT_MODE KINTERRUPT_MODE
#define SR_MCR_RTS
Definition: serial.h:151
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1315
unsigned char BOOLEAN
NTSTATUS NTAPI SerialSetBaudRate(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate)
Definition: devctrl.c:50
LONG NTSTATUS
Definition: precomp.h:26
PUCHAR KdComPortInUse
Definition: usage.c:17
if(!(yy_init))
Definition: macro.lex.yy.c:717
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1087
Status
Definition: gdiplustypes.h:24
PKINTERRUPT Interrupt
Definition: serial.h:60
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@378 Port
#define SR_FCR_CLEAR_RCVR
Definition: serial.h:129
DWORD *typedef HANDLE
Definition: winlogon.h:52
#define NO_PARITY
Definition: serial.c:89
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
#define SER_MCR(x)
Definition: serial.h:149
ULONG_PTR KAFFINITY
Definition: compat.h:75
#define SR_MCR_DTR
Definition: serial.h:150
UART_TYPE SerialDetectUartType(IN PUCHAR BaseAddress)
Definition: legacy.c:16
#define SER_IER(x)
Definition: serial.h:112
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:117
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@379 Interrupt
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define WARN_(ch,...)
Definition: debug.h:155
UART_TYPE UartType
Definition: serial.h:66
#define REG_SZ
Definition: layer.c:22
VOID NTAPI SerialReceiveByte ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  Unused1,
IN PVOID  Unused2 
)

Definition at line 70 of file misc.c.

Referenced by SerialAddDeviceInternal().

75 {
76  PSERIAL_DEVICE_EXTENSION DeviceExtension;
77  PUCHAR ComPortBase;
78  UCHAR Byte;
79  KIRQL Irql;
80  UCHAR IER;
82 
83  DeviceExtension = (PSERIAL_DEVICE_EXTENSION)pDeviceExtension;
84  ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
85 
86  KeAcquireSpinLock(&DeviceExtension->InputBufferLock, &Irql);
87  while (READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_DATA_RECEIVED)
88  {
89  Byte = READ_PORT_UCHAR(SER_RBR(ComPortBase));
90  INFO_(SERIAL, "Byte received on COM%lu: 0x%02x\n",
91  DeviceExtension->ComPort, Byte);
92  Status = PushCircularBufferEntry(&DeviceExtension->InputBuffer, Byte);
93  if (NT_SUCCESS(Status))
94  DeviceExtension->SerialPerfStats.ReceivedCount++;
95  else
96  DeviceExtension->SerialPerfStats.BufferOverrunErrorCount++;
97  }
98  KeSetEvent(&DeviceExtension->InputBufferNotEmpty, 0, FALSE);
99  KeReleaseSpinLock(&DeviceExtension->InputBufferLock, Irql);
100 
101  /* allow new interrupts */
102  IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
103  WRITE_PORT_UCHAR(SER_IER(ComPortBase), IER | SR_IER_DATA_RECEIVED);
104 }
#define ULongToPtr(ul)
Definition: basetsd.h:92
#define INFO_(ch,...)
Definition: debug.h:157
#define SER_RBR(x)
Definition: serial.h:109
unsigned char Byte
Definition: zconf.h:391
ULONG BufferOverrunErrorCount
Definition: ntddser.h:298
unsigned char * PUCHAR
Definition: retypes.h:3
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
KSPIN_LOCK InputBufferLock
Definition: serial.h:76
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
KEVENT InputBufferNotEmpty
Definition: serial.h:74
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define SR_LSR_DATA_RECEIVED
Definition: serial.h:153
#define SR_IER_DATA_RECEIVED
Definition: serial.h:113
#define FALSE
Definition: types.h:117
SERIALPERF_STATS SerialPerfStats
Definition: serial.h:71
#define IER
Definition: serial_port.h:62
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSTATUS PushCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define SER_LSR(x)
Definition: serial.h:152
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
#define SER_IER(x)
Definition: serial.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
CIRCULAR_BUFFER InputBuffer
Definition: serial.h:75
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
ULONG ReceivedCount
Definition: ntddser.h:294
VOID NTAPI SerialSendByte ( IN PKDPC  Dpc,
IN PVOID  pDeviceExtension,
IN PVOID  Unused1,
IN PVOID  Unused2 
)

Definition at line 107 of file misc.c.

Referenced by SerialAddDeviceInternal(), and SerialWrite().

112 {
113  PSERIAL_DEVICE_EXTENSION DeviceExtension;
114  PUCHAR ComPortBase;
115  UCHAR Byte;
116  KIRQL Irql;
117  UCHAR IER;
119 
120  DeviceExtension = (PSERIAL_DEVICE_EXTENSION)pDeviceExtension;
121  ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
122 
123  KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql);
124  while (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer)
125  && READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_THR_EMPTY)
126  {
127  Status = PopCircularBufferEntry(&DeviceExtension->OutputBuffer, &Byte);
128  if (!NT_SUCCESS(Status))
129  break;
130  WRITE_PORT_UCHAR(SER_THR(ComPortBase), Byte);
131  INFO_(SERIAL, "Byte sent to COM%lu: 0x%02x\n",
132  DeviceExtension->ComPort, Byte);
133  DeviceExtension->SerialPerfStats.TransmittedCount++;
134  }
135  if (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer))
136  {
137  /* allow new interrupts */
138  IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
139  WRITE_PORT_UCHAR(SER_IER(ComPortBase), IER | SR_IER_THR_EMPTY);
140  }
141  KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql);
142 }
#define ULongToPtr(ul)
Definition: basetsd.h:92
CIRCULAR_BUFFER OutputBuffer
Definition: serial.h:77
#define INFO_(ch,...)
Definition: debug.h:157
unsigned char Byte
Definition: zconf.h:391
unsigned char * PUCHAR
Definition: retypes.h:3
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
#define SR_IER_THR_EMPTY
Definition: serial.h:114
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
KSPIN_LOCK OutputBufferLock
Definition: serial.h:78
SERIALPERF_STATS SerialPerfStats
Definition: serial.h:71
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
#define IER
Definition: serial_port.h:62
#define SER_THR(x)
Definition: serial.h:110
#define SR_LSR_THR_EMPTY
Definition: serial.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define SER_LSR(x)
Definition: serial.h:152
NTSTATUS PopCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
ULONG TransmittedCount
Definition: ntddser.h:295
#define SER_IER(x)
Definition: serial.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
NTSTATUS NTAPI SerialSetBaudRate ( IN PSERIAL_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  NewBaudRate 
)

Definition at line 50 of file devctrl.c.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

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 ULongToPtr(ul)
Definition: basetsd.h:92
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2690
unsigned char * PUCHAR
Definition: retypes.h:3
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
#define SER_DLM(x)
Definition: serial.h:119
#define SER_LCR(x)
Definition: serial.h:135
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
#define SER_DLL(x)
Definition: serial.h:111
GLuint divisor
Definition: glext.h:6313
#define SR_LCR_DLAB
Definition: serial.h:148
#define TRACE_(x)
Definition: compat.h:66
#define BAUD_CLOCK
Definition: serial.h:105
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
#define CLOCKS_PER_BIT
Definition: serial.h:106
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
#define IoAcquireRemoveLock(RemoveLock, Tag)
NTSTATUS NTAPI SerialSetLineControl ( IN PSERIAL_DEVICE_EXTENSION  DeviceExtension,
IN PSERIAL_LINE_CONTROL  NewSettings 
)

Definition at line 88 of file devctrl.c.

Referenced by SerialDeviceControl(), and SerialPnpStartDevice().

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 ULongToPtr(ul)
Definition: basetsd.h:92
#define MARK_PARITY
Definition: ntddser.h:223
#define STOP_BIT_1
Definition: ntddser.h:215
#define SR_LCR_ST2
Definition: serial.h:141
#define SER_RBR(x)
Definition: serial.h:109
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
#define SER_LCR(x)
Definition: serial.h:135
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
#define SR_LCR_PSP
Definition: serial.h:146
#define SR_LCR_CS8
Definition: serial.h:139
#define ODD_PARITY
Definition: serial.c:90
#define SR_LCR_POD
Definition: serial.h:143
#define TRACE_(x)
Definition: compat.h:66
LONG NTSTATUS
Definition: precomp.h:26
#define STOP_BITS_1_5
Definition: ntddser.h:216
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define SR_LCR_PMK
Definition: serial.h:145
#define STOP_BITS_2
Definition: serial.c:87
#define SR_LCR_PNO
Definition: serial.h:142
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SR_LCR_CS7
Definition: serial.h:138
#define SR_LCR_PEV
Definition: serial.h:144
#define SPACE_PARITY
Definition: ntddser.h:224
#define SR_LCR_CS6
Definition: serial.h:137
Status
Definition: gdiplustypes.h:24
#define NO_PARITY
Definition: serial.c:89
#define EVEN_PARITY
Definition: serial.c:91
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
#define SR_LCR_CS5
Definition: serial.h:136
#define SR_LCR_ST1
Definition: serial.h:140
#define IoAcquireRemoveLock(RemoveLock, Tag)

Variable Documentation

DRIVER_DISPATCH ForwardIrpAndForget

Definition at line 250 of file serial.h.

DRIVER_ADD_DEVICE SerialAddDevice

Definition at line 285 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialCleanup

Definition at line 209 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialClose

Definition at line 213 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialCreate

Definition at line 217 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialDeviceControl

Definition at line 221 of file serial.h.

Referenced by DriverEntry().

KSERVICE_ROUTINE SerialInterruptService

Definition at line 273 of file serial.h.

Referenced by SerialPnpStartDevice().

DRIVER_DISPATCH SerialPnp

Definition at line 293 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialPower

Definition at line 297 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialQueryInformation

Definition at line 235 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialRead

Definition at line 301 of file serial.h.

Referenced by DriverEntry().

DRIVER_DISPATCH SerialWrite

Definition at line 302 of file serial.h.

Referenced by DriverEntry().