Skip to contentSkip to conversation

superio-locks

RFC PATCH Hans de Goede 2 participants 3 messages Jul 8, 2007 – Jul 11, 2007

lore
Share & tools
lore
#0 lore raw

Hi All,

Jim Cromie <jim.cromie at gmail.com> Wrote:

Quoted 10 lines

this patch set

01 - adds superio_locks -

drivers needing superio access register, and get a 'slot'with port-id info and a mutex,
multiple drivers share the same 'slot', and coordinate access with its mutex.

superio_find() - finds and reserves the slot, returned as ptr or

null

Quoted 6 lines

superio_release() - relinguishes the slot (ref-counted)

Once theyve got the reservation in struct superio * gate (as done in patches 2,3,4)
they *may* use

Quoted 8 lines

superio_lock(gate)
superio_inb(gate, addr),
superio_outb(gate, addr, val)

or they can do it themselves with inb/outb, and gate->sioaddr, etc. My objective was to be as

superio_find was chosen to fit the idiom used in hwmon/*.c

I noticed on Mark's kernel todo list that this patch needed someone to review it. But first lets discuss the API for this, I'm hoping for some input from others (Jean, Mark) here, once the API is ok-ed I can review this.

Personally I would like to see the following changes to the API:

1) Make the cmdreg_addrs and device_ids members of the superio_search struct fixed size arrays instead of pointers, using [2] for cmdreg_addrs and [8] for device_ids, stopping at a 0 addr/id or end of array.

This way code like this:

static u16 cmd_addrs[] = { 0x2E, 0x4E, 0 };
static u16 devid_vals[] = { 0xE1, 0xE8, 0xE4, 0xE5, 0xE9, 0 };

static struct superio_search where = {
.cmdreg_addrs = cmd_addrs,
.device_ids = devid_vals,
.devid_addr = SIO_DEVID,
.devid_mask = 0,
.devid_word = 0,
};

Can be changed into:

static struct superio_search where = {
	.cmdreg_addrs = { 0x2E, 0x4E},
	.device_ids   = { 0xE1, 0xE8, 0xE4, 0xE5, 0xE9, 0 },
	.devid_addr   = SIO_DEVID,
	.devid_mask   = 0,
	.devid_word   = 0,
};

Also the superio_search structs in the using drivers should be declared on the stack as they are not needed anymore after the superio_find call.

2) make superio_find return the device_id which was found through a by reference param, this way drivers who support multiple id's do not need to read the device_id registers again, but can use the returned value.

3) move superio_select from the drivers to the superio code.

Quoted 2 lines

CAVEATS
- see 4

Explain?

Quoted 1 line

- Ive not thought much about the 16-bit device-id check

( I need hardware to sharpen this focus )
I can check that on / with the f71882fg

Quoted 1 line

- superio_get() feels clumsy.

It looks fine to me

Quoted 6 lines

- superio_{enter,exit} are no-ops on my natsemi chip, so again the code is {}

the prob is (of course) that every chip does it differently, and superio_locks shouldnt care. Probably best to drop them from superio-locks API, and expect drivers to do them themselves.

I think its fine to leave any additional handshaking to the drivers, besides that, as you say with this locking that won't be necessary anymore.

Quoted 13 lines

- no device knowledge (digression - for later)

its tempting to (create another module) to have a Logical-device table, with strings to describe the LDs, etc. I dont want to dwell on it now, except to avoid foreclosing design options by bad choices now (in superio_locks).

struct sio_logical_device pc87366_units[] = {
       { 8,    "Floppy Disk Controller (FDC)" },
       { 8,    "Parallel Port (PP)" },         /* also 6 more at 0x400 */
       { 8,    "Serial Port 2 with IR (SP2)" },
      ...
Quoted 7 lines

I suspect that a pointer field in struct superio could carry whatever info a notional pc8736x_sio.ko would need, but might pose some reclamation issues.

such a module should support interrogating the LD's config-regs, extracting ISA addresses, etc, and could for example, add a bit more detail for display in /proc/ioports, which currently shows:

Why all this trouble ? Remember most superio devices are already in /proc/ioports with proper descriptions through there resp. drivers, for example floppy, serial, parallel_pc, kbd, etc.

I can see added value in a get superio_get_base_address(gate, logical_device, base_address_no) function, but I think more then that is more trouble then its worth. Its important here to realize that most superio logical devices are being driven by legacy drivers and that those drivers do not care (and should not need to care) wether the legacy device is in an lpc connected superio, or truely on the isa bus.

Regards,

Hans

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

#1 lore raw
Quoted 88 lines · Jim Cromie
Quoted 30 lines · Hans de Goede
Quoted 6 lines · Jim Cromie

Hans de Goede wrote:

Hi Hans,

thanks for stepping up.

Your welcome

Quoted 9 lines
Quoted 5 lines

2) make superio_find return the device_id which was found through a by reference param, this way drivers who support multiple id's do not need to read the device_id registers again, but can use the returned value.

No - devid is available via gate->devid (modulo spelling)
will provide inline wrapper

Ah I missed that because your chip driver patches didn't use it, instead the chip drivers read the devid registers again to get the dev register.

Quoted 5 lines
Quoted 2 lines

3) move superio_select from the drivers to the superio code.

disagreed at 1st, but added ld_addr field to superio_search, and copied it into gate in superio_find.

Quoted 6 lines

Why add a ld_addr there? That address is defined in the lpc spec afaik, then again so is the devid address, yet some devices deviate. I have a good idea, make these both configurable through the search struct, but allow them to be 0, and in case of 0 use the default addresses from the lpc spec (which 90% of all drivers use atm afaik).

I was unaware that its standard. I'll go with your idea 0 -> default.

Quoted 42 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

- Ive not thought much about the 16-bit device-id check

( I need hardware to sharpen this focus )
I can check that on / with the f71882fg

I'll leave that patch to you - as an API clarity test. If the API is confusing to you (non-newbie), then its flawed.

Will do.

Quoted 3 lines

And after I get rev 3 out ( Im calling last one rev2 - postfacto), I'll review your driver. Can you send me the datasheet ?

Thanks for the review offer, however I already have a reviewer :) The datasheet is publicly available, see the link from the devices section on the wiki.

Quoted 16 lines
Quoted 4 lines
Quoted 1 line

- superio_{enter,exit} are no-ops on my natsemi chip, so again the

code

Quoted 2 lines

is {}

Quoted 8 lines
Quoted 3 lines

the prob is (of course) that every chip does it differently, and superio_locks shouldnt care. Probably best to drop them from superio-locks API, and expect drivers to do them themselves.

I think its fine to leave any additional handshaking to the drivers, besides that, as you say with this locking that won't be necessary anymore.

my reasoning as commented in superio_locks.h is questionable. enter/exit is orthogonal to mutex, it gives no protection to drivers that properly use enter/exit.

Quoted 6 lines

drivers could reasonably just enter, never exit (since theres no protection)
mutexs must be used to give transaction guarantees.

Maybe more to say later..

Quoted 6 lines

I cannot follow you here, what exactly do you mean with enter / exit, some kind ahandshaking between different users which can be done through the chip, like testing the highest bit of the index reg? That will only work if you shortly disable any and all taskswitching as you first need to read it and then set it and you cannot do this atomically .

Quoted 5 lines

superio_enter/exit - theyre write sequences that enable/disable the superio-port
(the isa port still works) I guess it protects against random access and wrong drivers ( driver for Y dont know how to unlock chip X)

Ah, you mean the unlock code to "unlock" the superio ports, thats indeed to stop software who accidentally access these ports to wreck havoc, this offers no protection against a gpio versus hwmom driver conflict though, where both drivers know howto unlock.

You could try to integrate this enter / exit stuff into the locking though, but I'm not sure if we want this, we should first take a look to see when drivers open up the io ports by sending the key sequence, and when the close them again by sending the closing key, if this matches with moments when a drivers should call superio_enter and superio_exit, then we can make superio_enter and exit do the sending of the enter and leave codes, this would require adding these codes to the gate structure though,

Regards,

Hans

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

#2 lore raw
In reply to Hans de Goede

Hans de Goede wrote:

Hi Hans,

thanks for stepping up.

Quoted 7 lines

Personally I would like to see the following changes to the API:

1) Make the cmdreg_addrs and device_ids members of the superio_search struct fixed size arrays instead of pointers, using [2] for cmdreg_addrs and [8] for device_ids, stopping at a 0 addr/id or end of array.

Yes - completely sensible - Doing it.

Quoted 4 lines

Also the superio_search structs in the using drivers should be declared on the stack as they are not needed anymore after the superio_find call.

This too - Doing so.

Quoted 5 lines

2) make superio_find return the device_id which was found through a by reference param, this way drivers who support multiple id's do not need to read the device_id registers again, but can use the returned value.

No - devid is available via gate->devid (modulo spelling)
will provide inline wrapper

Quoted 2 lines

3) move superio_select from the drivers to the superio code.

disagreed at 1st, but added ld_addr field to superio_search, and copied it into gate in superio_find.

Quoted 5 lines
Quoted 3 lines

CAVEATS
- see 4

Explain?

Basic hedge since only 1 client driver tested with it. All others compile-tested only, and just barely.

Now have 2nd chip, which has real enter/exit, so next version will be known to work with both.

Other drivers still rather sloppy ATM ..

Quoted 4 lines
Quoted 1 line

- Ive not thought much about the 16-bit device-id check

( I need hardware to sharpen this focus )
I can check that on / with the f71882fg

I'll leave that patch to you - as an API clarity test. If the API is confusing to you (non-newbie), then its flawed.

And after I get rev 3 out ( Im calling last one rev2 - postfacto), I'll review your driver. Can you send me the datasheet ?

Quoted 6 lines
Quoted 1 line

- superio_get() feels clumsy.

It looks fine to me

Quoted 3 lines

- superio_{enter,exit} are no-ops on my natsemi chip, so again the code is {}

Quoted 8 lines
Quoted 3 lines

the prob is (of course) that every chip does it differently, and superio_locks shouldnt care. Probably best to drop them from superio-locks API, and expect drivers to do them themselves.

I think its fine to leave any additional handshaking to the drivers, besides that, as you say with this locking that won't be necessary anymore.

my reasoning as commented in superio_locks.h is questionable. enter/exit is orthogonal to mutex, it gives no protection to drivers that properly use enter/exit.

drivers could reasonably just enter, never exit (since theres no protection) mutexs must be used to give transaction guarantees.

Maybe more to say later..

Quoted 18 lines
Quoted 10 lines

- no device knowledge (digression - for later)

its tempting to (create another module) to have a Logical-device table, with strings to describe the LDs, etc. I dont want to dwell on it now, except to avoid foreclosing design options by bad choices now (in superio_locks).

struct sio_logical_device pc87366_units[] = {
{ 8, "Floppy Disk Controller (FDC)" },
{ 8, "Parallel Port (PP)" }, /* also 6 more at

0x400 */

Quoted 7 lines
       { 8,    "Serial Port 2 with IR (SP2)" },
      ...

I suspect that a pointer field in struct superio could carry whatever info a notional pc8736x_sio.ko would need, but might pose some reclamation issues.

Quoted 8 lines
Quoted 3 lines

such a module should support interrogating the LD's config-regs, extracting ISA addresses, etc, and could for example, add a bit more detail for display in /proc/ioports, which currently shows:

Why all this trouble ? Remember most superio devices are already in /proc/ioports with proper descriptions through there resp. drivers, for example floppy, serial, parallel_pc, kbd, etc.

it would be nice to see the LD-name appended to these lines

6620-662f : pc87360
6640-664f : pc87360

Quoted 3 lines

I can see added value in a get superio_get_base_address(gate, logical_device, base_address_no) function, but I think more then that is more trouble then its worth.

Probably true. ATM I just want to avoid painting myself into a corner.

maybe superio_get_isa_baseaddr is worth adding to superio_locks, subject to what (new) fields such support requires..

<aside> s/then/than/
since English is your 2nd or 3rd language, it might not just be a typo.

Quoted 6 lines

Its important here to realize that most superio logical devices are being driven by legacy drivers and that those drivers do not care (and should not need to care) wether the legacy device is in an lpc connected superio, or truely on the isa bus.

Quoted 7 lines

Regards,

Hans

thanks again.
-jimc

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