How to access PCI device memory registers before PCI bus driver loads?

Hello!
Following Ken Johnson’s advice, I blamed the idea with debug hooking and now I am trying to modify the registers of my pci card. However, the register I try modifying already gets triggered read-only by the time the register space is mapped by MmMapIoSpace in target miniport driver. I know the register is writable during computer startup, but I cannot get it written because I don’t know how to reach it. So I decided to write a boot bus extender driver and to reach the specified memory registers from it. The question is - should I use HalXxx functions and MmMapIoSpace to get the driver register map or I should use the IO ports directly to enumerate and probe the device? I suppose I can use neither IRP_MN_QUERY_INTERFACE nor IRP_MN_READ_CONFIG because the PDO is not created yet.

Basil

Please note that page protection applies on per-page basis. In order to make memory-mapped register non- writable, one has to mark at least 4K range as RO in PTE, which seems to be unlikely scenario
for memory-mapped device In fact, it is so unlikely that MmMapIoSpace() does not even consider
taking page protection flag as an argument, and assumes RW access . I don’t know what your problem is all about, but I can assure you that it has absolutely nothing to do with MmMapIoSpace()…

Anton Bassov

Anton,

thanks for reply, and I know for sure the neighbour registers are writable, so the page protection flag is unset. Also I know that setting the lowest bit of the register I am going to modify permits writing till the device restart. But the question was HOW is it the best to reach the register map if my driver is loaded before PCI bus driver.

Basil

> I know for sure the neighbour registers are writable,

How can something like that be possibly be true, unless device registers are mapped into IO space, rather than memory, and are supposed to get accessed by port IO instructions, rather than memory access ones??? The fact that you mention MmMapIOSpace() strongly suggests that you are speaking about
memory-mapped registers…

But the question was HOW is it the best to reach the register map if my driver is loaded before
PCI bus driver.

Address map is available from PCI configuration space at the offset 0x10. First of all, check Bit 0 of you target register - if it is hardwired to 1, then it is mapped to IO space, rather than memory . At this point
you will know whether your problem is real or just imaginary one that results from your improper interpretation of a situation …

Anton Bassov

wrote in message news:xxxxx@ntdev…
>
>> I know for sure the neighbour registers are writable,
>
> How can something like that be possibly be true, unless device registers
> are mapped into IO space, rather than memory, and are supposed to get
> accessed by port IO instructions, rather than memory access ones??? The
> fact that you mention MmMapIOSpace() strongly suggests that you are
> speaking about
> memory-mapped registers…

It looks like this device has some write-once register that is designed to
be initialized
early (by BIOS or OS bus driver) and then protected from any writes.
The OP wants to workaround this protection ( difficult by design )

–pa

Pavel, you are absolutely right! That is a write-once strap, and I am writing a driver to reprogram it before it is triggered. Simply I thought that it is not so important whether the reg is write-once or not (I am working with a bunch of regs there, but the one is the first I need to change), but if it is important, how can I do that? I understand that if it is triggered in BIOS, I cannot do anything,can I? But if not…how should I organise my driver to do that?

Basil

> It looks like this device has some write-once register that is designed to be initialized early

(by BIOS or OS bus driver) and then protected from any writes.

Actually, after having checked his earlier post, I got a suspicion that the OP just tries to play around with resources that he does not own (not so long ago he was speaking about playing around with debug registers and kernel tracing). If this is the case, apparently he just gets into a conflict with the legitimate owner of device resources…

Anton Bassov

wrote in message news:xxxxx@ntdev…
> Pavel, you are absolutely right! That is a write-once strap, and I am
> writing a driver to reprogram it before it is triggered. Simply I thought
> that it is not so important whether the reg is write-once or not (I am
> working with a bunch of regs there, but the one is the first I need to
> change), but if it is important, how can I do that? I understand that if
> it is triggered in BIOS, I cannot do anything,can I? But if not…how
> should I organise my driver to do that?
>
> Basil
>

Two options:
a. Find some PCI viewer for DOS. Check that the register is not protected
yet.
If it is not, you can try to hack the Windows loader.

b. Find a PCI or ISA netcard that has a boot ROM extension socket.
Write a boot ROM extension and check in it, that the register is not
protected yet.
If it is already triggered, you’re out of luck.

–pa

> That is a write-once strap, and I am writing a driver to reprogram it before it is triggered.

Exactly what I thought (I should have checked your earlier post first) - you just made your post while I was typing mine.

I understand that if it is triggered in BIOS, I cannot do anything,can I?

Judging from what you are saying, someone who writes to this register has an intimate knowledge
of all device specifics. Unless you are speaking about on-board controller BIOS is not going to have any idea about device’s registers. PCI bus driver has no idea of them either - the only thing it knows is where the are mapped (and can possibly change this), but it has no idea about how they have to be programmed. Therefore, loading your driver before PCI.SYS does is not going to help you here. The only one who knows all the details is a driver for this device…

how should I organise my driver to do that?

It depends on what you are actually trying to do. There is a good chance that you should just give it up right on the spot…

Anton Bassov

> Write a boot ROM extension and check in it, that the register is not protected yet. If it is already

triggered, you’re out of luck.

As long as your task is simply to check the target register’s state at the boot time, all you have to do is to write a tiny bootloader that checks the register state and outputs the result to the screen before reading the boot sector and transferring control to it ( you can burn this bootloader on the CD and boot from it).

This part is just painless. What he is going to do with this info is already a different story…

Anton Bassov

Thanks for the answers guys! I hope I will be able to check this values from DOS,otherwise I will make a bootloader to do all the job (this will be even better in my case cause it’d be possible to use it not only with Windows;)).

Basil

>my driver is loaded before PCI bus driver.

Why is this?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Maxim.
that is because I planned to start it as Boot Bus Extender with tag 1

Basil