2002-01-25 18:17:51

by chus Medina

[permalink] [raw]
Subject: PCI #LOCK assertion


Hola,

I need to create module to perform atomic transactions through the PCI bus
between the processor and an IDE hard disk. The PCI bus specifications 2.2
point to the #LOCK signal to perform such a transaction. Is possible to
assert the #LOCK signal of the PCI bus using the Linux Kernel? How? I didnt
see any pointers in include/pci.h or anywhere in the source code.

I will truly appreciate any help/pointers,

Jesus



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


2002-01-25 18:44:43

by Richard B. Johnson

[permalink] [raw]
Subject: Re: PCI #LOCK assertion

On Fri, 25 Jan 2002, chus Medina wrote:

>
> Hola,
>
> I need to create module to perform atomic transactions through the PCI bus
> between the processor and an IDE hard disk. The PCI bus specifications 2.2
> point to the #LOCK signal to perform such a transaction. Is possible to
> assert the #LOCK signal of the PCI bus using the Linux Kernel? How? I didnt
> see any pointers in include/pci.h or anywhere in the source code.
>
> I will truly appreciate any help/pointers,
>
> Jesus
>

On Intel machines, you precede a memory access with the 'lock'
instruction. With CPUs i486, and later, only the accessed page
is locked at that instant. Earlier CPUs locked the whole bus.

The PCI/Bus controller handles the #LOCK signal itself to guarantee
the atomicity of a transaction. You should never have to do this
yourself. If you think you have to, just precede each PCI/Bus
address-space access with the 'lock' instruction. You just make
your own version of the readl/readw/readb/etc macros that are
provided. You may find that this deadlocks, though, and all bets
are off. You may have just locked the PCI/Bus off the bus when
you needed it most!!

If you are finding something 'strange' in your PCI/Bus accesses,
it is probably because you didn't use 'nocache' when you obtained
address-space for your PCI Device, i.e., ioremap_nocache() instead of
ioremap().


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (797.90 BogoMips).

I was going to compile a list of innovations that could be
attributed to Microsoft. Once I realized that Ctrl-Alt-Del
was handled in the BIOS, I found that there aren't any.


2002-01-25 19:38:56

by Gérard Roudier

[permalink] [raw]
Subject: Re: PCI #LOCK assertion



On Fri, 25 Jan 2002, chus Medina wrote:

> Hola,
>
> I need to create module to perform atomic transactions through the PCI bus
> between the processor and an IDE hard disk. The PCI bus specifications 2.2
> point to the #LOCK signal to perform such a transaction. Is possible to
> assert the #LOCK signal of the PCI bus using the Linux Kernel? How? I didnt
> see any pointers in include/pci.h or anywhere in the source code.
>
> I will truly appreciate any help/pointers,

This has nothing to do with the kernel.
This only depends on your CPU and on the PCI-HOST bridge of your system.

For example, some (all?) Intel PCI-HOST bridges will translate a LOCK
prefixed memory READ to PCI into a locked PCI transaction. It is also
possible to perform a locked READ/MODIFY transaction to PCI using the
corresponding LOCK prefixed memory instruction.

I suggest you to download PCI-HOST bridge documents from Intel site and
to look into them, if obviously you are interestested in such hardware.

Just, PCI-to-PCI bridges do not carry the PCI LOCK# protocol. As a result
a subsystem relying on PCI LOCK# will not work (as expected) if PCI agents
are talking through a PCI-to-PCI bridge.

G?rard.

2002-01-27 21:18:31

by H. Peter Anvin

[permalink] [raw]
Subject: Re: PCI #LOCK assertion

Followup to: <[email protected]>
By author: "Richard B. Johnson" <[email protected]>
In newsgroup: linux.dev.kernel
>
> On Intel machines, you precede a memory access with the 'lock'
> instruction. With CPUs i486, and later, only the accessed page
> is locked at that instant. Earlier CPUs locked the whole bus.
>
> The PCI/Bus controller handles the #LOCK signal itself to guarantee
> the atomicity of a transaction. You should never have to do this
> yourself. If you think you have to, just precede each PCI/Bus
> address-space access with the 'lock' instruction. You just make
> your own version of the readl/readw/readb/etc macros that are
> provided. You may find that this deadlocks, though, and all bets
> are off. You may have just locked the PCI/Bus off the bus when
> you needed it most!!
>

LOCK on readl/readw/etc is meaningless (might even be an error). The
*only* case when the lock matters is when transferring
read/modify/write transactions such as "inc", "add", "xchg" (the
latter locks automatically.)

In practice, LOCK# on the PCI bus is so poorly supported that you
can't rely on it anyway (and it causes deadlocks.) A number of
motherboards have been known not even to wire it up. LOCK is still
needed for SMP coherency, however.

-hpa
--
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt <[email protected]>