Example of PCI/PCIe based serial/uart devier

Hi, All,

Recently, we implement a hardware, it is:

RS-232 capable function base on a PCIe card.

Therefore, I have to write a device driver for this device which plug into x86 pc pcie slot.

The effect should satisfied by this driver is:
using this pcie based RS-232 card should same as the RS-232 port at a PC backpanel.
Namely, when plug a RS-232 cable between the PC RS-232 port and a RS-232, it should communite.

Any example code for this requirement?

Or any more quickly method, such as use the in box driver serial.sys & serenum.sys, but change some portion of the inf file, or create a new inf, if it is implemented by this way , that’s great, which is time consuming for driver developing and test.

> Hi, All,

Recently, we implement a hardware, it is:

RS-232 capable function base on a PCIe card.

Therefore, I have to write a device driver for this device which plug into
x86 pc pcie slot.

The effect should satisfied by this driver is:
using this pcie based RS-232 card should same as the RS-232 port at a PC
backpanel.
Namely, when plug a RS-232 cable between the PC RS-232 port and a RS-232,
it should communite.

I think you have missed an important piece in this puzzle. The only one
that matters. If you have implemented an RS-232 port on a card, you will
need a driver for it. Specifications of a serial port driver, including
the 40+ IOCTLs you need to implement for it, can be found in the Micosoft
documentation. A serial port driver source code example used to be in the
samples tree. So, to accomplish your goal, you will have to write a
driver that talks upwards using the specified protocols, and talks pcie
downwards. You will probably have to use internal kernel buffering to
handle the characters that come in when there is no pending readfile IRP,
and you have to make sure you do not notify completion when the last
output character is placed in the transmit buffer–you should not signal
completion until it has been sent (cases of apps changing the baud rate in
the middle of a byte transmission were common).

Do all this right and you will see the desired effect.
joe

Any example code for this requirement?

Or any more quickly method, such as use the in box driver serial.sys &
serenum.sys, but change some portion of the inf file, or create a new inf,
if it is implemented by this way , that’s great, which is time consuming
for driver developing and test.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

It is not a small work load I think.

Need to change the sample code in WDK to support PCIe function, at least pnp start, configuration read/write, and data read/write.

If it is rs232 and exposes the same register and interrupt that an ISA version exposes, you can reuse serial.sys as is. All you need to do is create an INF That matches your pci hwid and installs serial.sys

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of workingmailing@163.com
Sent: Wednesday, February 26, 2014 11:59 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Example of PCI/PCIe based serial/uart devier

It is not a small work load I think.

Need to change the sample code in WDK to support PCIe function, at least pnp start, configuration read/write, and data read/write.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

The chance that a PCI or PCIe card will get the same adresses or
interrupts as the legacy COM port is indistinguishable from zero.
joe

If it is rs232 and exposes the same register and interrupt that an ISA
version exposes, you can reuse serial.sys as is. All you need to do is
create an INF That matches your pci hwid and installs serial.sys

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
workingmailing@163.com
Sent: Wednesday, February 26, 2014 11:59 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Example of PCI/PCIe based serial/uart devier

It is not a small work load I think.

Need to change the sample code in WDK to support PCIe function, at least
pnp start, configuration read/write, and data read/write.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I just search a MSDN paper
http://technet.microsoft.com/library/cc767877.aspx#XS
there are following 4 type of modles, whihc should I comply with?

My judgement is:
Serial Device Containing a 16550 UART Inserted in PC Card Slot
But it does not comply with my USB-RS232 or native rs232 port driver stack case.
And I can’t not image a devie like this:

PCMCIA card, ON this card,
there are two UART controller, one connect to the PCMCIA controller
the other connect to toaster device.
the two UART controller is connected.

What a strange device like this?

I check the USB-RS232 device plug intot usb port in my PC:
it have the following drivers: from up to down:

device upper filter: serenum.sys
3rd serial functional driver ch341ser.sys + ch341pt.dll( appendix functions)
usb hub
usb host
pci

For a native rs232 port at PC:
it is:
serenum.sys
serial.sys
isapnp.sys
pci.sys

After glance the sample driver source code for serial in WDK.
I feel that it is a very huge work, can’t not finished between 2 week, do you agree?

I prefer create a INF file, whihc utility the in box driver stack, instead of develop a serial driver again.

Where can I serch this INF sample.
And what rule should the PCIe based RS-232 controller should obey when hardware implementation?

I think Doron meant “exposes the same registers and interrupt behaviour
as a classic 16550”, and then he is (of course) right.

You can even get serial.sys to handle a quad UART such as the Oxford
16954, with an INF file as the one described in the WDK article
“Creating Varying Resource Maps”. BTDTGTT.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff542737(v=vs.85).aspx

The chance that a PCI or PCIe card will get the same adresses or
interrupts as the legacy COM port is indistinguishable from zero.
joe
> If it is rs232 and exposes the same register and interrupt that an ISA
> version exposes, you can reuse serial.sys as is. All you need to do is
> create an INF That matches your pci hwid and installs serial.sys
>
> d

I feel confused:

For native serial port in my pc, its driver stack:
serenum.sys
serial.sys
isapnp.sys
pci.sys

Can I think like this:
the serial port controller is a device, which plug into the isa bus.
Then the serial.sys driver should incorporate the isa device’s function, it is a isa device function driver.

And for USB to RS232 device, because it is a USB device plug into usb bus
so the driver should incorporate the USB device’s function, such as create URB, then send to lower level driver, here usb host driver.
It is a USB device function driver.

And for PCIe to RS232 device, the driver should incorporate PCIe ep function.
It is a PCIe device function driver.

And it seems that if my understand is not wrong:
I can not use the in box driver stack, like this:
serenum.sys
serial.sys (in box driver)
pci.sys

but
serenum.sys
serial.sys (it is a pcie device function driver, change from the serial sample code)
pci.sys

If the card represents a single 16550 UART as a device, the existing
serial.sys works fine. It is PnP and does not go out looking for legacy
hardware.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
workingmailing@163.com
Sent: Thursday, February 27, 2014 5:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Example of PCI/PCIe based serial/uart devier

I feel confused:

For native serial port in my pc, its driver stack:
serenum.sys
serial.sys
isapnp.sys
pci.sys

Can I think like this:
the serial port controller is a device, which plug into the isa bus.
Then the serial.sys driver should incorporate the isa device’s function, it
is a isa device function driver.

And for USB to RS232 device, because it is a USB device plug into usb bus so
the driver should incorporate the USB device’s function, such as create URB,
then send to lower level driver, here usb host driver.
It is a USB device function driver.

And for PCIe to RS232 device, the driver should incorporate PCIe ep
function.
It is a PCIe device function driver.

And it seems that if my understand is not wrong:
I can not use the in box driver stack, like this:
serenum.sys
serial.sys (in box driver)
pci.sys

but
serenum.sys
serial.sys (it is a pcie device function driver, change from the serial
sample code) pci.sys


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

They don’t have to be the same Isa classic values themselves, the hci has to be the same. A chunk of contiguous ports / registers and an interrupt. That’s it

d

Bent from my phone


From: Wilhelm Noekermailto:xxxxx
Sent: ?2/?27/?2014 1:46 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re:[ntdev] Example of PCI/PCIe based serial/uart devier

I think Doron meant “exposes the same registers and interrupt behaviour
as a classic 16550”, and then he is (of course) right.

You can even get serial.sys to handle a quad UART such as the Oxford
16954, with an INF file as the one described in the WDK article
“Creating Varying Resource Maps”. BTDTGTT.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff542737(v=vs.85).aspx

> The chance that a PCI or PCIe card will get the same adresses or
> interrupts as the legacy COM port is indistinguishable from zero.
> joe
>> If it is rs232 and exposes the same register and interrupt that an ISA
>> version exposes, you can reuse serial.sys as is. All you need to do is
>> create an INF That matches your pci hwid and installs serial.sys
>>
>> d


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Isapnp. Is an enumerator, nothing else. Neither isapnp nor pdo provide access to the card once started. Both just get the Io resources assigned to the stack and get out of the way. The in box serial driver doesn’t speak pci or Isa, it speaks rs232 as defined by the original PC hci. USB aerial has to go through the USB abstraction and thus mud swap out the hci with USB urbs

d

Bent from my phone


From: workingmailing@163.commailto:workingmailing
Sent: ?2/?27/?2014 2:23 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Example of PCI/PCIe based serial/uart devier

I feel confused:

For native serial port in my pc, its driver stack:
serenum.sys
serial.sys
isapnp.sys
pci.sys

Can I think like this:
the serial port controller is a device, which plug into the isa bus.
Then the serial.sys driver should incorporate the isa device’s function, it is a isa device function driver.

And for USB to RS232 device, because it is a USB device plug into usb bus
so the driver should incorporate the USB device’s function, such as create URB, then send to lower level driver, here usb host driver.
It is a USB device function driver.

And for PCIe to RS232 device, the driver should incorporate PCIe ep function.
It is a PCIe device function driver.

And it seems that if my understand is not wrong:
I can not use the in box driver stack, like this:
serenum.sys
serial.sys (in box driver)
pci.sys

but
serenum.sys
serial.sys (it is a pcie device function driver, change from the serial sample code)
pci.sys


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:workingmailing>

serial.sys expects the register interface of a standard 16550 uart. What does the register interface of your PCI/PCIe device look like?

If you can provide this interface I can tell you if serial.sys will work as is.

Thank you all.

But I still not very clear about the module.
In pcie based uart controller, at first, pci.sys enumerate pcie ep, then a PDO for pcie ep is created.
For this PDO, how does system known serial.sys driver should be loaded, and create a FDO on the previous FDO.

Does the UART is a specific capability of PCIe/PCI, such as USB host, I have no idea about UART capability of PCI/pcie.

And still the question, on the MSDN:
which module does the PCIe based uart comply with:
http://technet.microsoft.com/library/cc767877.aspx#XS

> serial.sys expects the register interface of a standard 16550 uart

But it will work if 8byte register pool will occur not on 0x3f8, but at some absolutely different address.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

workingmailing@163.com wrote:

But I still not very clear about the module.
In pcie based uart controller, at first, pci.sys enumerate pcie ep, then a PDO for pcie ep is created.
For this PDO, how does system known serial.sys driver should be loaded, and create a FDO on the previous FDO.

The PCI configuration space contains a class code. If there is no
direct match for the vendor ID and device ID, the operating system looks
for a generic match on the class code. For example, the cardbus class
code is 0607, and pcmcia.inf contains a match for PCI\CC_0607.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you Tim.

Recently, I have a interesting question.
I have experience on PCIe EP and USB device driver development.
And take a look of the sample of toaster and serial.

For PCIe and serial, once we get the resource at the PNP start dispatch routine, their process/sending request mode is same, using the no specific IRP down.

But for USB, not only the IRP, but also a URB it needed.
And finially, in xHCI driver, it will convert the URB into TRB or for EHCI (I don’t know how o/uhci done) into TDs.

Why the USB is special?
What’s the original design reason for URB instead of direct IRP?

USB is a shared protocol bus, PCI is not

d

Bent from my phone


From: workingmailing@163.commailto:workingmailing
Sent: ?3/?4/?2014 9:34 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Example of PCI/PCIe based serial/uart devier

Thank you Tim.

Recently, I have a interesting question.
I have experience on PCIe EP and USB device driver development.
And take a look of the sample of toaster and serial.

For PCIe and serial, once we get the resource at the PNP start dispatch routine, their process/sending request mode is same, using the no specific IRP down.

But for USB, not only the IRP, but also a URB it needed.
And finially, in xHCI driver, it will convert the URB into TRB or for EHCI (I don’t know how o/uhci done) into TDs.

Why the USB is special?
What’s the original design reason for URB instead of direct IRP?


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:workingmailing>

workingmailing@163.com wrote:

…But for USB, not only the IRP, but also a URB it needed.
And finially, in xHCI driver, it will convert the URB into TRB or for EHCI (I don’t know how o/uhci done) into TDs.

Why the USB is special?

USB is more like Ethernet than it is like PCI or PCIe. With PCIe, you
are granted direct access to memory and I/O ports. Your driver writes
directly to those ports. With USB (and Ethernet and 1394), there is a
host controller that is managing access to the hardware resources.
There is a specific protocol to be followed, and drivers shouldn’t have
to worry about that. So, you make requests to the host controller,
which then manages the protocol.

What’s the original design reason for URB instead of direct IRP?

That question is easy to answer. There isn’t enough room in a bare IRP
to store the context information you need to do a USB request. You have
to have a structure of some kind to hold the information about the
interfaces and endpoints and buffers and such, and that’s what the URB
is for.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.