Skip to contentSkip to conversation

superio lock coordinator

lm-sensors Jim Cromie 3 participants 11 messages Jul 15, 2008 – Nov 14, 2008 Kbuild

lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

hi Hans,

thanks for the personal invite to this thread.
I messed up a laptop update last nov, and lost my mail folders (several gig had piled up so the purge was needed anyway)

hi everyone else too,
apologies for being out of it for so long, and for things left half done.

Quoted 9 lines
Quoted 7 lines · David Hubbard

Hi Hans,

I can pick it up again and push it forward. IIRC we wanted to know what was the best way to encode the enter and exit sequences for a SuperIO because the w83627ehf is different than pretty much any other. That was the tricky part.

Quoted 8 lines

If you look at the latest version posted by Jim:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-October/021562.html

You will see that it already has configurable enter / exit sequences. AFAIK the winbond chips are not unique in having differen enter / exit sequences as other superio's have, so having to specify the enter / exit sequence in the driver using the super io coordinator seems correct.

I have recently been revisiting the patches, but havent been entirely happy with them,
and didnt really like them enough to propose again.

This thread certainly ups it from a background muse. Happily, I got my soekris back, and have a box that can actually use 2 superio-client-drivers (ghod this needs a shorter name)

these are on my current todo / partly done

- struct superio_common - stuff thats copied from struct superio-search to struct superio when reservation is taken

- add a u8 flags to struct superio
-- carries bit for tracking enter/exit state -
should support warnings on situations like enter-on-entered,
exit-on-exited
- could carry a toggle bit for a union superio_exit { fnptr;
exit_seq[X] } or somesuch.

-- following another thread - we'd
--- reserve region when reservation taken, after devid is validated,
might help keep other semi-rogue drivers out.

= sort out enter / exit

As David noted in this thread, the ehf driver has an odd exit sequence,

The combined combined superio_exit() function I have coded currently is really quite hideous,
and has me thinking towards David's function-pointer idea.

- the other alternative is that David's driver should include its own custom exit-fn, which
he would use instead of the regular superio_exit(). It could use the superio_enter routine as-is iirc.

my stall points - (fishing for answers;)

- enter / exit should be tracked by superio-locks, in flags bit. (recent idea, seems sound)
- enter / exit should be vaguely discouraged in kernel-doc - due to expectations of isadump etc.

I guess I gotta stop overcomplicating things, and get busy on the patch-set.

Quoted 6 lines

More interesting questions IMHO are:
1) is hwmon the correct subsystem to put the .c file in (somewhat superfical
really, but we need a place to put the lock coordinator (and enable
/ disable
its building).

I put it here for proximity to the center-of-mass of the drivers I found.

Quoted 6 lines

2) non hwmon drivers need to be edited for superio register use too, and then
modified to use the lock coordinator if they touch the superio
registers.
This will also be a good exercise to see if our API is generic enough.

I guess there are drivers I missed ?

Quoted 4 lines

Regards,

Hans

thanks again Hans for pulling me back into this, I'll commit to staying with it now.
Should I infer from your comments that the code at the link incorporates your feedback ?
They seem to have aquired some momentum recently 8-)

Jean, you raised the idea of a sysfs interface.
Does the October patchset look to fit with what youre thinking ?
- the most simple I can think of :
--expose the kzalloced array of superio-fields as readonly attributes. --values go non-zero when superio-port is registered by some user-driver --it would be nice to see client-drivers list on each slot, but that involves more code and mem

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

does anyone think s/superio/sio/g is appropriate ? anything else ?

thanks
Jim

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Hi Jim,

Quoted 12 lines · Jim Cromie

these are on my current todo / partly done

- struct superio_common - stuff thats copied from struct superio-search to struct superio when reservation is taken

- add a u8 flags to struct superio
-- carries bit for tracking enter/exit state -
should support warnings on situations like enter-on-entered,
exit-on-exited
- could carry a toggle bit for a union superio_exit { fnptr;
exit_seq[X] } or somesuch.

Quoted 3 lines

-- following another thread - we'd
--- reserve region when reservation taken, after devid is validated,
might help keep other semi-rogue drivers out.

Actually, _before_ devid is validated. You shouldn't make _any_ I/O access without first requesting the region. You can always release the region afterwards if you didn't find anything interesting.

Quoted 5 lines

= sort out enter / exit

As David noted in this thread, the ehf driver has an odd exit sequence,

Quoted 8 lines

The combined combined superio_exit() function I have coded currently is really quite hideous,
and has me thinking towards David's function-pointer idea.

- the other alternative is that David's driver should include its own custom exit-fn, which
he would use instead of the regular superio_exit(). It could use the superio_enter routine as-is iirc.

Please read my reply to David's concern, and why having a per-chip exit sequence doesn't make that much sense. I would use the same exit function as isadump and sensors-detect have been using for months, as this appears to work fine.

Quoted 6 lines

my stall points - (fishing for answers;)

- enter / exit should be tracked by superio-locks, in flags bit. (recent idea, seems sound)
- enter / exit should be vaguely discouraged in kernel-doc - due to expectations of isadump etc.

Which expectations? User-space should stay away from I/O ports the kernel has requested. There's little point in trying to sort out concurrent accesses which simply shouldn't happen in the first place.

Quoted 5 lines

I guess I gotta stop overcomplicating things, and get busy on the patch-set.

Quoted 8 lines
Quoted 6 lines

More interesting questions IMHO are:
1) is hwmon the correct subsystem to put the .c file in (somewhat superfical
really, but we need a place to put the lock coordinator (and enable
/ disable
its building).

I put it here for proximity to the center-of-mass of the drivers I found.

That's not necessarily a bad initial location. We can have superio live in drivers/hwmon at first, and once all hwmon drivers use it, move it to a neutral ground and convert the other drivers in the kernel tree (mainly watchdog drivers I think.)

Quoted 7 lines
Quoted 6 lines

2) non hwmon drivers need to be edited for superio register use too, and then
modified to use the lock coordinator if they touch the superio
registers.
This will also be a good exercise to see if our API is generic enough.

I guess there are drivers I missed ?

Best way I think is to grep for each super-I/O chip name.

Quoted 8 lines

thanks again Hans for pulling me back into this, I'll commit to staying with it now.
Should I infer from your comments that the code at the link incorporates your feedback ?
They seem to have aquired some momentum recently 8-)

Jean, you raised the idea of a sysfs interface.
Does the October patchset look to fit with what youre thinking ?

I don't think your patch offered a sysfs interface? I'm not really thinking of anything in particular anyway. We just want a way for sensors-detect to identify supported Super-I/O chips without actually accessing the I/O ports if a kernel driver already requested them.

Quoted 5 lines

- the most simple I can think of :
--expose the kzalloced array of superio-fields as readonly attributes. --values go non-zero when superio-port is registered by some user-driver --it would be nice to see client-drivers list on each slot, but that involves more code and mem

What we really need for sensors-detect is simply the value of registers 0x20 and 0x21, and values of registers 0x30, 0x60 and 0x61 for a selected logical device. In what form we export these, needs to be discussed.

Quoted 6 lines

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

does anyone think s/superio/sio/g is appropriate ?

No. This was discussed before and I have always objected to the name "sio". It's too short and could mean about anything (starting with "synchronous I/O", as opposed to "asynchronous I/O" which is very often spelled AIO.)

Quoted 1 line

anything else ?

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Jim Cromie

Hi Jim,

Glad to see you again on lm-sensors!

Quoted 37 lines · Jean Delvare

Hi Jim,

Quoted 12 lines · Jim Cromie

these are on my current todo / partly done

- struct superio_common - stuff thats copied from struct superio-search to struct superio when reservation is taken

- add a u8 flags to struct superio
-- carries bit for tracking enter/exit state -
should support warnings on situations like enter-on-entered,
exit-on-exited
- could carry a toggle bit for a union superio_exit { fnptr;
exit_seq[X] } or somesuch.

Quoted 3 lines

-- following another thread - we'd
--- reserve region when reservation taken, after devid is validated,
might help keep other semi-rogue drivers out.

Actually, _before_ devid is validated. You shouldn't make _any_ I/O access without first requesting the region. You can always release the region afterwards if you didn't find anything interesting.

Quoted 5 lines

= sort out enter / exit

As David noted in this thread, the ehf driver has an odd exit sequence,

Quoted 8 lines

The combined combined superio_exit() function I have coded currently is really quite hideous,
and has me thinking towards David's function-pointer idea.

- the other alternative is that David's driver should include its own custom exit-fn, which
he would use instead of the regular superio_exit(). It could use the superio_enter routine as-is iirc.

Quoted 4 lines

Please read my reply to David's concern, and why having a per-chip exit sequence doesn't make that much sense. I would use the same exit function as isadump and sensors-detect have been using for months, as this appears to work fine.

Here it is:

Quoted 4 lines · Jean Delvare

sensors-detect doesn't pay much attention to custom exist sequences, and neither does isadump:

void superio_reset(int addrreg, int datareg)

Quoted 8 lines
{
       /* Some chips (SMSC, Winbond) want this */
       outb(0xaa, addrreg);

       /* Return to "Wait For Key" state (PNP-ISA spec) */
       outb(0x02, addrreg);
       outb(0x02, datareg);
}

That will certainly work for w83627ehf, so superio-locks would not even need to store the enter and exit sequences. Every hwmon device should work like this.

Quoted 23 lines
Quoted 6 lines

my stall points - (fishing for answers;)

- enter / exit should be tracked by superio-locks, in flags bit. (recent idea, seems sound)
- enter / exit should be vaguely discouraged in kernel-doc - due to expectations of isadump etc.

Which expectations? User-space should stay away from I/O ports the kernel has requested. There's little point in trying to sort out concurrent accesses which simply shouldn't happen in the first place.

Quoted 12 lines

I guess I gotta stop overcomplicating things, and get busy on the patch-set.

Quoted 6 lines

More interesting questions IMHO are:
1) is hwmon the correct subsystem to put the .c file in (somewhat superfical
really, but we need a place to put the lock coordinator (and enable
/ disable
its building).

Quoted 6 lines
Quoted 1 line

I put it here for proximity to the center-of-mass of the drivers I found.

That's not necessarily a bad initial location. We can have superio live in drivers/hwmon at first, and once all hwmon drivers use it, move it to a neutral ground and convert the other drivers in the kernel tree (mainly watchdog drivers I think.)

Sounds like a good plan. drivers/hwmon/superio-locks.

Quoted 30 lines
Quoted 7 lines
Quoted 6 lines

2) non hwmon drivers need to be edited for superio register use too, and then
modified to use the lock coordinator if they touch the superio
registers.
This will also be a good exercise to see if our API is generic enough.

I guess there are drivers I missed ?

Best way I think is to grep for each super-I/O chip name.

Quoted 8 lines

thanks again Hans for pulling me back into this, I'll commit to staying with it now.
Should I infer from your comments that the code at the link incorporates your feedback ?
They seem to have aquired some momentum recently 8-)

Jean, you raised the idea of a sysfs interface.
Does the October patchset look to fit with what youre thinking ?

I don't think your patch offered a sysfs interface? I'm not really thinking of anything in particular anyway. We just want a way for sensors-detect to identify supported Super-I/O chips without actually accessing the I/O ports if a kernel driver already requested them.

Quoted 5 lines

- the most simple I can think of :
--expose the kzalloced array of superio-fields as readonly attributes. --values go non-zero when superio-port is registered by some user-driver --it would be nice to see client-drivers list on each slot, but that involves more code and mem

Quoted 4 lines

What we really need for sensors-detect is simply the value of registers 0x20 and 0x21, and values of registers 0x30, 0x60 and 0x61 for a selected logical device. In what form we export these, needs to be discussed.

Should superio-locks enumerate the available logical device ID's, perhaps as a sysfs interface?

Quoted 4 lines
Quoted 4 lines

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

I think we could just use the same enter and exit sequences for everything, and not make it customizable. Does that sound OK?

Quoted 6 lines
Quoted 1 line

does anyone think s/superio/sio/g is appropriate ?

No. This was discussed before and I have always objected to the name "sio". It's too short and could mean about anything (starting with "synchronous I/O", as opposed to "asynchronous I/O" which is very often spelled AIO.)

David

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#3 lore raw
In reply to Jim Cromie
Quoted 5 lines · Jean Delvare

Hi Jim,

On Tue, 15 Jul 2008 01:56:00 -0600, Jim Cromie wrote:

Quoted 8 lines
Quoted 3 lines

-- following another thread - we'd
--- reserve region when reservation taken, after devid is validated,
might help keep other semi-rogue drivers out.

Actually, _before_ devid is validated. You shouldn't make _any_ I/O
access without first requesting the region. You can always release the region afterwards if you didn't find anything interesting.

ACK.

Quoted 17 lines
Quoted 7 lines

= sort out enter / exit

As David noted in this thread, the ehf driver has an odd exit sequence,

Quoted 8 lines

The combined combined superio_exit() function I have coded currently is really quite hideous,
and has me thinking towards David's function-pointer idea.

- the other alternative is that David's driver should include its own custom exit-fn, which
he would use instead of the regular superio_exit(). It could use the superio_enter routine as-is iirc.

Quoted 4 lines

Please read my reply to David's concern, and why having a per-chip exit
sequence doesn't make that much sense. I would use the same exit function as isadump and sensors-detect have been using for months, as this appears to work fine.

OK, quoting

As I recall, the rationale for the code above is that you do not necessarily recognize a known Super-I/O chip after the init sequence. As different chips have different exit sequences, there are definitely cases where you just don't know what to do. So we need a universal exit sequence, which is the code above. And once you have that and it appears to work with all known chips, there's simply no reason to not use it for all chips even when we know their exit sequence.

I dont understand what you mean by :
"not necessarily recognize a known Super-I/O chip after the init sequence"

recognize =? known device id ?
init sequence =? superio-enter sequence ?

Quoted 9 lines
Quoted 8 lines

my stall points - (fishing for answers;)

- enter / exit should be tracked by superio-locks, in flags bit. (recent idea, seems sound)
- enter / exit should be vaguely discouraged in kernel-doc - due to expectations of isadump etc.

What I meant here was that we should discourage use of superio-exit(), leaving the port enabled for normal operations. ISTM that this is the same effect as the "universal exit sequence" - ie a harmless sequence of bytes that does NOT disable the port, leaving it working for anyone, and not interfering with drivers which resend the superio_enter() sequence.

IOW - if we send enter_sequence when registering port, and never send exit-sequence,
we should get the current working behavior.

Quoted 2 lines

Which expectations?

Mostly that isadump continues to work - if drivers are aggressive with enter/exit sequences, we're more likely to leave the port in a disabled state, and isadump
and friends would need correct enter-sequences to re-enable.

I'll take a peek at coreboot RSN. thanks for that link.

User-space should stay away from I/O ports the

Quoted 10 lines

kernel has requested. There's little point in trying to sort out concurrent accesses which simply shouldn't happen in the first place.

Quoted 8 lines
Quoted 1 line

I put it here for proximity to the center-of-mass of the drivers I found.

That's not necessarily a bad initial location. We can have superio live
in drivers/hwmon at first, and once all hwmon drivers use it, move it to a neutral ground and convert the other drivers in the kernel tree (mainly watchdog drivers I think.)

Good - Ill stick with it for now, and move if/when appropriate.

Quoted 6 lines
Quoted 2 lines

Jean, you raised the idea of a sysfs interface.
Does the October patchset look to fit with what youre thinking ?

I don't think your patch offered a sysfs interface? I'm not really
thinking of anything in particular anyway.

Thats correct - it did not. Im just trying to use the idea as
a probe to see what the patchset might have missed.
Following comments are intended for consideration in an additional patch..

We just want a way for

Quoted 11 lines

sensors-detect to identify supported Super-I/O chips without actually accessing the I/O ports if a kernel driver already requested them.

Quoted 5 lines

- the most simple I can think of :
--expose the kzalloced array of superio-fields as readonly attributes. --values go non-zero when superio-port is registered by some user-driver --it would be nice to see client-drivers list on each slot, but that involves more code and mem

Quoted 5 lines

What we really need for sensors-detect is simply the value of registers
0x20 and 0x21, and values of registers 0x30, 0x60 and 0x61 for a selected logical device. In what form we export these, needs to be discussed.

Ok - those are familiar addys - I'll come up with candidate names for these attrs.

I note you left out DevID, is that an accident ?
ISTM that it would be needed for a user-space sensor-module loader, which would know device ids supported by drivers.

Also, this implies that Locks-Coordinator should actively scan for common superio-ports (based upon superio_locks.scan_on_load=1), an

Quoted 8 lines
Quoted 1 line

does anyone think s/superio/sio/g is appropriate ?

No. This was discussed before and I have always objected to the name
"sio". It's too short and could mean about anything (starting with "synchronous I/O", as opposed to "asynchronous I/O" which is very often spelled AIO.)

ACK. I'll not ask again (I dont recall that I did, but thats irrelevant)

Quoted 3 lines

Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
In reply to Jim Cromie

Hi Jim,

Quoted 16 lines · Jim Cromie
Quoted 4 lines · Jean Delvare

Please read my reply to David's concern, and why having a per-chip exit
sequence doesn't make that much sense. I would use the same exit function as isadump and sensors-detect have been using for months, as this appears to work fine.

OK, quoting

As I recall, the rationale for the code above is that you do not necessarily recognize a known Super-I/O chip after the init sequence. As different chips have different exit sequences, there are definitely cases where you just don't know what to do. So we need a universal exit sequence, which is the code above. And once you have that and it appears to work with all known chips, there's simply no reason to not use it for all chips even when we know their exit sequence.

Quoted 4 lines

I dont understand what you mean by :
"not necessarily recognize a known Super-I/O chip after the init sequence"

recognize =? known device id ?

Yes.

Quoted 1 line

init sequence =? superio-enter sequence ?

Yes.

To take a concrete example: say that you issue the Winbond Super-I/O enter sequence and it works. You know that you probably have some Winbond chip (but you're not even sure). You check the device ID and it doesn't match anything you know. Now you want to issue the exit sequence. You can use the one of the W83627HF, or you can use the one of the W83627EHF. Which one will you use, given that you have no idea what chip you actually have?

This is the reason why sensors-detect etc. don't use per-chip exit sequenced.

Quoted 9 lines

(...)
What I meant here was that we should discourage use of superio-exit(), leaving the port enabled for normal operations. ISTM that this is the same effect as the "universal exit sequence" - ie a harmless sequence of bytes that does NOT disable the port, leaving it working for anyone, and not interfering with drivers which resend the superio_enter() sequence.

IOW - if we send enter_sequence when registering port, and never send exit-sequence, we should get the current working behavior.

That's not OK. For one thing, some chips stop working while in configuration mode. For another (probably related), some chips leave configuration mode on their own after a number of configuration register reads and/or period of time (that's why isadump reissues the enter sequence every 16 reads or so). So you don't want to leave the chip in configuration mode, and in some cases you couldn't even if you wanted to.

In general, I strongly suggest that you look at what sensors-detect and isadump are doing. These tools have been in use for years, we have improved them over time, and I can't remember any problem report related to Super-I/O.

Quoted 6 lines
Quoted 1 line

Which expectations?

Mostly that isadump continues to work - if drivers are aggressive with enter/exit sequences, we're more likely to leave the port in a disabled state, and isadump
and friends would need correct enter-sequences to re-enable.

isadump always had to issue the correct enter-sequence, we have an option for that (-k). There's no reason for this to change (except for the fact that it is considered bad practice to access I/O ports from user-space that have been requested by a kernel driver.)

Quoted 6 lines
Quoted 5 lines

(...)
What we really need for sensors-detect is simply the value of registers
0x20 and 0x21, and values of registers 0x30, 0x60 and 0x61 for a selected logical device. In what form we export these, needs to be discussed.

Quoted 6 lines

Ok - those are familiar addys - I'll come up with candidate names for these attrs.

I note you left out DevID, is that an accident ?
ISTM that it would be needed for a user-space sensor-module loader, which would know device ids supported by drivers.

DevID is 0x20, I didn't leave it out. Or do you mean something else?

Quoted 2 lines

Also, this implies that Locks-Coordinator should actively scan for common superio-ports (based upon superio_locks.scan_on_load=1), an

If we want hwmon drivers to load automatically, it will have to anyway. I would even make it the default.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw
In reply to Jim Cromie

Hi David,

Quoted 8 lines · David Hubbard
Quoted 4 lines · Jean Delvare

What we really need for sensors-detect is simply the value of registers 0x20 and 0x21, and values of registers 0x30, 0x60 and 0x61 for a selected logical device. In what form we export these, needs to be discussed.

Should superio-locks enumerate the available logical device ID's, perhaps as a sysfs interface?

I don't have anything precise in mind, I admit. All I can say is that it needs to be extensible, in case we need to export more register values in the future.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

I think we could just use the same enter and exit sequences for everything, and not make it customizable. Does that sound OK?

No. We can have a universal exit sequence, but enter sequences are per-chip (or actually per chip family). That's even one part of the device identification (lets us differentiate between two chips with the same device ID register value.)

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#6 lore raw
In reply to Jim Cromie

Hi Jim,

Quoted 5 lines · Jean Delvare
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

Quoted 7 lines
Quoted 2 lines

I think we could just use the same enter and exit sequences for everything, and not make it customizable. Does that sound OK?

No. We can have a universal exit sequence, but enter sequences are per-chip (or actually per chip family). That's even one part of the device identification (lets us differentiate between two chips with the same device ID register value.)

I think a fn-ptr would be fine. The function could take as an arg enter/exit/query (0, 1, 2) and a pointer to a byte array with offset, value, offset, value pairs. So I see the function having 3 args:

void (* fn-ptr)(int which, char * sequence, int sequence_max_length);

David

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#7 lore raw
In reply to Jim Cromie
Quoted 16 lines · David Hubbard

Hi Jim,

Quoted 5 lines · Jean Delvare
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

David,
do you have a preference wrt fn-ptr ? and if so, a single fn with 1 arg : 0,1,2 for enter/exit/query ?
do you have any use for a flag bit ? is there generality in it ?

Quoted 7 lines
Quoted 2 lines

I think we could just use the same enter and exit sequences for everything, and not make it customizable. Does that sound OK?

No. We can have a universal exit sequence, but enter sequences are per-chip (or actually per chip family). That's even one part of the device identification (lets us differentiate between two chips with the same device ID register value.)

Quoted 5 lines

I think a fn-ptr would be fine. The function could take as an arg enter/exit/query (0, 1, 2) and a pointer to a byte array with offset, value, offset, value pairs. So I see the function having 3 args:

void (* fn-ptr)(int which, char * sequence, int sequence_max_length);

I'm lost. I thought that we had just agreed that the exit sequence would be universal? Also, what is the "query" sequence supposed to be?

Then I don't get the prototype of the function. Who would be calling it? And who would provide the parameters? The enter sequence is a set of number being written to a port. It is a per-chip thing (or per-family) thing. So there are 2 possibilities:

* For each known chip or family, you store the enter sequence in an array, and the superio driver iterates over it. This is the approach taken in both isadump and sensors-detect.

OR

* For each known chip or family, you store a function, which the superio driver calls. The prototype of such a function would be something like:
void (*enter)(int index_port, int data_port);
This is more flexible, but at this point I have no reason to believe that this is needed.

Hmmm, I thought I had said I would let someone else work on this...

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#8 lore raw
In reply to Jim Cromie

Hi Jean,

Quoted 20 lines · Jean Delvare
Quoted 5 lines

I think a fn-ptr would be fine. The function could take as an arg enter/exit/query (0, 1, 2) and a pointer to a byte array with offset, value, offset, value pairs. So I see the function having 3 args:

void (* fn-ptr)(int which, char * sequence, int sequence_max_length);

I'm lost. I thought that we had just agreed that the exit sequence would be universal? Also, what is the "query" sequence supposed to be?

Then I don't get the prototype of the function. Who would be calling it? And who would provide the parameters? The enter sequence is a set of number being written to a port. It is a per-chip thing (or per-family) thing. So there are 2 possibilities:

* For each known chip or family, you store the enter sequence in an array, and the superio driver iterates over it. This is the approach taken in both isadump and sensors-detect.

OR

Quoted 8 lines

* For each known chip or family, you store a function, which the superio driver calls. The prototype of such a function would be something like:
void (*enter)(int index_port, int data_port);
This is more flexible, but at this point I have no reason to believe that this is needed.

Hmmm, I thought I had said I would let someone else work on this...

Sorry, I'm just being slow. I don't know what the "query" sequence is supposed to be either, but just merged it straight from Jim's email.

I agree, just an enter sequence in an array which the superio driver iterates over - that is all we need.

David

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#9 lore raw
In reply to Jim Cromie

Hi Jim, Jean,

Attached is a patch (I'm renaming it to .txt to get the right mime-type). It's only compile-tested. Main questions I have are:

- the code in superio.c is supposed to lead up to static int __devinit w83627ehf_probe(struct platform_device *pdev)

Did I do that right? Any obvious errors?

- I'm using a fixed-size array devlist[] in superio.c. I would use a LIST_HEAD() but I haven't had time yet.

- It's only compile-tested. Assuming there aren't blatant design mistakes, I might even try running it. ;-)

I appreciate any (brief) review you can afford to do...

Cheers,
David

superio.c +251 -0
diff -Naur old/superio.c new/superio.c
@@ -0,0 +1,251 @@
+/*
+	superio - Driver for Super-I/O chips
+
+	Copyright (C) 2008  David Hubbard <[email protected]>
+
+	This driver is part of lm-sensors. http://www.lm-sensors.org
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/list.h>
+#include <asm/io.h>	/* inb() outb() */
+#include "superio.h"
+
+/* DRVNAME is used in the driver core and sysfs to identify this driver */
+#define DRVNAME "superio"
+
+/* Table of recognized devices */
+struct superio_recognize_device
+{
+	u16		devid, devid_mask;
+	const char *	driver_name;
+};
+
+static struct superio_recognize_device recognize[] = {
+	{ 0x8850, 0xfff0, "w83627ehf" },	/* w83627ehf */
+	{ 0x8860, 0xfff0, "w83627ehf" },	/* w83627ehg */
+	{ 0xa020, 0xfff0, "w83627ehf" },	/* w83627dhg */
+};
+
+
+/* superio I/O port access */
+#define SUPERIO_IOREGION_LENGTH	2
+
+void superio_outb(int ioreg, int reg, int val)
+{
+	outb(reg, ioreg);
+	outb(val, ioreg + 1);
+}
+
+int superio_inb(int ioreg, int reg)
+{
+	outb(reg, ioreg);
+	return inb(ioreg + 1);
+}
+
+void superio_select(int ioreg, int ld)
+{
+	outb(SUPERIO_REG_LDSEL, ioreg);
+	outb(ld, ioreg + 1);
+}
+
+void superio_enter(int ioreg)
+{
+	outb(0x87, ioreg);
+	outb(0x87, ioreg);
+}
+
+void superio_exit(int ioreg)
+{
+	outb(0x02, ioreg);
+	outb(0x02, ioreg + 1);
+}
+
+
+#if 0
+static int __devinit superio_probe(struct platform_device * pdev)
+{
+	/* the driver that knows more about this Super-I/O can now probe() */
+	return 0;
+}
+
+static int __devexit superio_remove(struct platform_device * pdev)
+{
+	return 0;
+}
+#endif
+
+static struct platform_driver superio_driver = {
+	/*.probe	= superio_probe,*/
+	/*.remove	= __devexit_p(superio_remove),*/
+	.driver	= {
+		.name	= DRVNAME,
+		.owner	= THIS_MODULE,
+	},
+};
+
+#define SUPERIO_MAXDEV 2
+static struct platform_device * devlist[SUPERIO_MAXDEV];
+static unsigned devlist_num = 0;
+
+/* module_param force: useful for an unrecognized device, because generic
+ * registers will be available in sysfs for inspection
+ * (e.g. for isadump and sensors-detect) */
+static ushort force;
+module_param(force, ushort, 0);
+MODULE_PARM_DESC(force, "Force to load with unrecognized device ID");
+
+/* module init: request region and see if a Super-I/O device lives here */
+static int __init superio_find_at(int addr)
+{
+	u16 val;
+	struct resource res;
+	struct platform_device * pdev;
+	const char * recognized_name = 0;
+	int err, i;
+
+	if (!request_region(addr, SUPERIO_IOREGION_LENGTH, DRVNAME)) {
+		printk(KERN_ERR DRVNAME ": region request 0x%x-0x%x failed\n",
+			addr, addr + SUPERIO_IOREGION_LENGTH - 1);
+		err = -EBUSY;
+		goto exit;
+	}
+
+	/* see if a Super-I/O device lives here */
+	superio_enter(addr);
+	val = (superio_inb(addr, SUPERIO_REG_DEVID) << 8)
+		| superio_inb(addr, SUPERIO_REG_DEVID + 1);
+
+	for (i = 0; i < ARRAY_SIZE(recognize); i++) {
+		if ((val & recognize[i].devid_mask) == recognize[i].devid) {
+			recognized_name = recognize[i].driver_name;
+			pr_info(DRVNAME ": Found %s\n", recognized_name);
+			break;
+		}
+	}
+
+	superio_exit(addr);
+
+	if (!recognized_name) {
+		if (val != 0xffff) {
+			pr_debug(DRVNAME ": unsupported superio ID: 0x%04x\n",
+				val);
+			if (/*module_param*/ force) recognized_name = DRVNAME;
+		}
+		else pr_info(DRVNAME ": no superio found (ffff)\n");
+
+		if (!recognized_name) {
+			err = -ENODEV;
+			goto exit_release;
+		}
+	}
+
+	if (devlist_num >= SUPERIO_MAXDEV) {
+		printk(KERN_ERR DRVNAME ": too many superio devices (%d)\n",
+			devlist_num + 1);
+		err = -ENOMEM;
+		goto exit_release;
+	}
+
+	/* create/register platform device for the new Super-I/O device */
+	memset(&res, 0, sizeof(res));
+	res.name = recognized_name;
+	res.start = addr;
+	res.end = addr + SUPERIO_IOREGION_LENGTH - 1;
+	res.flags = IORESOURCE_IO;
+	pdev = platform_device_register_simple(recognized_name, addr, &res, 1);
+	if (IS_ERR(pdev)) {
+		printk(KERN_ERR DRVNAME ": device registration failed (%ld)\n",
+			PTR_ERR(pdev));
+		err = (int) (PTR_ERR(pdev));
+		goto exit_release;
+	}
+
+	devlist[devlist_num] = pdev;
+	devlist_num++;
+	return 0;
+
+exit_release:
+	release_region(addr, SUPERIO_IOREGION_LENGTH);
+exit:
+	return err;
+}
+
+/* module init function */
+static int __init superio_module_init(void)
+{
+	int err;
+
+	err = platform_driver_register(&superio_driver);
+	if (err)
+		goto exit;
+
+	/* request region for each of the possible Super-I/O ports, and
+	 * probe the port to see if a Super-I/O device lives there.
+	 * If it fails with -ENODEV, look elsewhere. If it fails with
+	 * -EBUSY, look elsewhere (the region is reserved, that's all). */
+
+	err = superio_find_at(0x2e);
+	if (err != 0 && err != -ENODEV && err != -EBUSY)
+		goto exit_unregister;
+
+	if (err != 0) {
+		err = superio_find_at(0x4e);
+		if (err != 0)
+			goto exit_unregister;
+
+		/* superio_find_at(0x4e) == 0, so we are OK */
+
+	} else {
+		err = superio_find_at(0x4e);
+		if (err != 0 && err != -ENODEV && err != -EBUSY)
+			goto exit_unregister;
+
+		/* superio_find_at(0x2e) == 0, so we are OK */
+
+	}
+
+	return 0;
+
+exit_unregister:
+	platform_driver_unregister(&superio_driver);
+exit:
+	return err;
+}
+
+/* module exit function */
+static void __exit superio_module_exit(void)
+{
+	unsigned i;
+
+	for (i = 0; i < devlist_num; i++) {
+		platform_device_unregister(devlist[i]);
+	}
+
+	platform_driver_unregister(&superio_driver);
+}
+
+MODULE_AUTHOR("David Hubbard <[email protected]>");
+MODULE_DESCRIPTION("Super I/O driver");
+MODULE_LICENSE("GPL");
+
+module_init(superio_module_init);
+module_exit(superio_module_exit);
superio.h +13 -0
diff -Naur old/superio.h new/superio.h
@@ -0,0 +1,13 @@
+/* These superio registers are exported for all superio devices */
+/* The device will have more superio registers that these */
+
+#define SUPERIO_REG_LDSEL	0x07	/* Logical device select */
+#define SUPERIO_REG_DEVID	0x20	/* Device ID (2 bytes) */
+#define SUPERIO_REG_ENABLE	0x30	/* Logical device enable */
+#define SUPERIO_REG_ADDR	0x60	/* Logical device address (2 bytes) */
+
+void superio_outb(int ioreg, int reg, int val);
+int superio_inb(int ioreg, int reg);
+void superio_select(int ioreg, int ld);
+void superio_enter(int ioreg);
+void superio_exit(int ioreg);
w83627ehf.c +121 -149

416 lines not on this page · raw message

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#10 lore raw
In reply to Jim Cromie

Hi Jim, Hans,

Quoted 10 lines

Hi David,

heres my git-log -p for your patch, and several others layering on trivial fixes.

Maybe its useful ( maybe it saves you a tiny bit of time ) Or maybe not.

have fun
-jimc

At last, I think I've made it to a point where I can ask for your help.

Attached is a patch that works (sort of!) on my w83627ehf. (.txt is so the content-type is right.)

I *think* this is what is happening:

Before, w83627ehf would call platform_device_alloc when it probed the superio registers. That's a primitive approach (discussed in Documentation/driver-model/platform.txt).

Well, I've pulled the two steps apart. In superio.c, it looks at superio registers, finds the superio ID, and then creates a platform_device with a driver name that pulls in w83627ehf. There's a device table in superio.c, so Jim can add pc87360 and it should automatically get modprobed also. (I'd be happy to port drivers, but it could take a while.)

The driver core sees the platform device, autoloads w83627ehf.ko and calls the probe() function in it. This part works. :-)

[ 6383.126757] superio: Found w83627ehf (0x8863) at 0x2e
[ 6383.126842] w83627ehf: found a w83627ehg at 0x290
[ 6383.127443] superio: no superio found at 0x4e

So something I'm not too sure about, but I think I did it right, is superio.c:153
platform_device_put(pdev); /* now the device can exist on its own */

In theory, superio.c doesn't store the pdev pointer at all. It releases its hold on it and leaves the rest to the driver core. But when I remove the superio module:

[ 6475.442046] Trying to free nonexistent resource <0290-0291>
[ 6506.698974] superio: region request 0x2e-0x2f failed
[ 6506.698996] superio: no superio found at 0x4e

So Jim, Hans, can you take a look at how I'm doing platform device code and make suggestions?

Jim, I'm fine with your suggestion, if (err) instead of if (err != 0). I chose superio_in2b instead of superio_inw, because it is possible to do a hardware 16-bit read with inw() which could have a different result. After fumbling around a little, I added #ifdef/#define to superio.h and then defined the functions superio_enter / superio_exit etc. with "static inline". That should work OK for now.

Things TODO:
- Add mutexes (the whole point in the first place)
- Don't print out which superio ports had nothing, as long as at least one port has something

Cheers!
David

Makefile +1 -0
diff -Nuar old/Makefile new/Makefile
@@ -73,6 +73,7 @@
 obj-$(CONFIG_SENSORS_VIA686A)	+= via686a.o
 obj-$(CONFIG_SENSORS_VT1211)	+= vt1211.o
 obj-$(CONFIG_SENSORS_VT8231)	+= vt8231.o
+obj-$(CONFIG_SENSORS_W83627EHF)	+= superio.o
 obj-$(CONFIG_SENSORS_W83627EHF)	+= w83627ehf.o
 obj-$(CONFIG_SENSORS_W83L785TS)	+= w83l785ts.o
 obj-$(CONFIG_SENSORS_W83L786NG)	+= w83l786ng.o
superio.c +197 -0

197 lines not on this page · raw message

superio.h +52 -0

52 lines not on this page · raw message

w83627ehf.c +107 -222

450 lines not on this page · raw message

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors