Skip to content

Commit 8b6d043

Browse files
Alan Coxjbarnes993
authored andcommitted
resource: shared I/O region support
SuperIO devices share regions and use lock/unlock operations to chip select. We therefore need to be able to request a resource and wait for it to be freed by whichever other SuperIO device currently hogs it. Right now you have to poll which is horrible. Add a MUXED field to IO port resources. If the MUXED field is set on the resource and on the request (via request_muxed_region) then we block until the previous owner of the muxed resource releases their region. This allows us to implement proper resource sharing and locking for superio chips using code of the form enable_my_superio_dev() { request_muxed_region(0x44, 0x02, "superio:watchdog"); outb() ..sequence to enable chip } disable_my_superio_dev() { outb() .. sequence of disable chip release_region(0x44, 0x02); } Signed-off-by: Giel van Schijndel <me@mortis.eu> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent d19f61f commit 8b6d043

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎include/linux/ioport.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct resource_list {
5252

5353
#define IORESOURCE_MEM_64 0x00100000
5454
#define IORESOURCE_WINDOW 0x00200000 /* forwarded by bridge */
55+
#define IORESOURCE_MUXED 0x00400000 /* Resource is software muxed */
5556

5657
#define IORESOURCE_EXCLUSIVE 0x08000000 /* Userland may not map this resource */
5758
#define IORESOURCE_DISABLED 0x10000000
@@ -143,7 +144,8 @@ static inline unsigned long resource_type(const struct resource *res)
143144
}
144145

145146
/* Convenience shorthand with allocation */
146-
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
147+
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
148+
#define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
147149
#define __request_mem_region(start,n,name, excl) __request_region(&iomem_resource, (start), (n), (name), excl)
148150
#define request_mem_region(start,n,name) __request_region(&iomem_resource, (start), (n), (name), 0)
149151
#define request_mem_region_exclusive(start,n,name) \

‎kernel/resource.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/spinlock.h>
1616
#include <linux/fs.h>
1717
#include <linux/proc_fs.h>
18+
#include <linux/sched.h>
1819
#include <linux/seq_file.h>
1920
#include <linux/device.h>
2021
#include <linux/pfn.h>
@@ -681,6 +682,8 @@ resource_size_t resource_alignment(struct resource *res)
681682
* release_region releases a matching busy region.
682683
*/
683684

685+
static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait);
686+
684687
/**
685688
* __request_region - create a new busy resource region
686689
* @parent: parent resource descriptor
@@ -693,6 +696,7 @@ struct resource * __request_region(struct resource *parent,
693696
resource_size_t start, resource_size_t n,
694697
const char *name, int flags)
695698
{
699+
DECLARE_WAITQUEUE(wait, current);
696700
struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
697701

698702
if (!res)
@@ -717,7 +721,15 @@ struct resource * __request_region(struct resource *parent,
717721
if (!(conflict->flags & IORESOURCE_BUSY))
718722
continue;
719723
}
720-
724+
if (conflict->flags & flags & IORESOURCE_MUXED) {
725+
add_wait_queue(&muxed_resource_wait, &wait);
726+
write_unlock(&resource_lock);
727+
set_current_state(TASK_UNINTERRUPTIBLE);
728+
schedule();
729+
remove_wait_queue(&muxed_resource_wait, &wait);
730+
write_lock(&resource_lock);
731+
continue;
732+
}
721733
/* Uhhuh, that didn't work out.. */
722734
kfree(res);
723735
res = NULL;
@@ -791,6 +803,8 @@ void __release_region(struct resource *parent, resource_size_t start,
791803
break;
792804
*p = res->sibling;
793805
write_unlock(&resource_lock);
806+
if (res->flags & IORESOURCE_MUXED)
807+
wake_up(&muxed_resource_wait);
794808
kfree(res);
795809
return;
796810
}

0 commit comments

Comments
 (0)