All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@engr.sgi.com>
To: Greg KH <greg@kroah.com>
Cc: linux-kernel@vger.kernel.org, willy@debian.org,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Bjorn Helgaas <bjorn.helgaas@hp.com>
Subject: Re: [PATCH] add legacy resources to sysfs
Date: Tue, 21 Dec 2004 15:42:47 -0800	[thread overview]
Message-ID: <200412211542.47997.jbarnes@engr.sgi.com> (raw)
In-Reply-To: <200412211405.09536.jbarnes@engr.sgi.com>

[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]

On Tuesday, December 21, 2004 2:05 pm, Jesse Barnes wrote:
> On Tuesday, December 21, 2004 1:46 pm, Greg KH wrote:
> > You are passing the wrong things around :)
> >
> > A struct pci_bus is a struct class_device, not a struct device.  I think
> > you need to rethink your goal of putting the files into the pci device
> > directory, or just put the files into the proper /sys/class/pci_bus/*
> > directory as your code assumes is happening.
>
> Something like this then?  I added bin file support to class.c and use that
> instead from probe.c.  I also fixed the container_of stuff in pci-sysfs.c.

Here it is w/o the ia64 stuff.  That way people can buy off on the API and not 
worry about the platform stuff.  I can send that to Tony separately if 
there's agreement on this part.  I'd like to create a symlink 
from /sys/class/pci_bus/<bus>/legacy_* to /sys/devices/pci<foo>/legacy_* too, 
how do I do that?

 drivers/base/class.c    |   16 ++++++++++
 drivers/pci/pci-sysfs.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/probe.c     |   39 ++++++++++++++++++++++++++
 include/linux/pci.h     |    2 +
 4 files changed, 127 insertions(+)

Thanks,
Jesse

[-- Attachment #2: sysfs-legacy-resource-5.patch --]
[-- Type: text/plain, Size: 5932 bytes --]

===== drivers/base/class.c 1.56 vs edited =====
--- 1.56/drivers/base/class.c	2004-11-12 03:45:39 -08:00
+++ edited/drivers/base/class.c	2004-12-21 13:59:00 -08:00
@@ -179,6 +179,22 @@
 		sysfs_remove_file(&class_dev->kobj, &attr->attr);
 }
 
+int class_device_create_bin_file(struct class_device *class_dev,
+				 struct bin_attribute *attr)
+{
+	int error = -EINVAL;
+	if (class_dev)
+		error = sysfs_create_bin_file(&class_dev->kobj, attr);
+	return error;
+}
+
+void class_device_remove_bin_file(struct class_device *class_dev,
+				  struct bin_attribute *attr)
+{
+	if (class_dev)
+		sysfs_remove_bin_file(&class_dev->kobj, attr);
+}
+
 static int class_device_dev_link(struct class_device * class_dev)
 {
 	if (class_dev->dev)
===== drivers/pci/pci-sysfs.c 1.14 vs edited =====
--- 1.14/drivers/pci/pci-sysfs.c	2004-12-21 11:28:57 -08:00
+++ edited/drivers/pci/pci-sysfs.c	2004-12-21 14:03:35 -08:00
@@ -179,6 +179,76 @@
 	return count;
 }
 
+#ifdef HAVE_PCI_LEGACY
+/**
+ * pci_read_legacy_io - read byte(s) from legacy I/O port space
+ * @kobj: kobject corresponding to file to read from
+ * @buf: buffer to store results
+ * @off: offset into legacy I/O port space
+ * @count: number of bytes to read
+ *
+ * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
+ * callback routine (pci_legacy_read).
+ */
+ssize_t
+pci_read_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+        struct pci_bus *bus = to_pci_bus(container_of(kobj,
+                                                      struct class_device,
+						      kobj));
+
+        /* Only support 1, 2 or 4 byte accesses */
+        if (count != 1 && count != 2 && count != 4)
+                return -EINVAL;
+
+        return pci_legacy_read(bus, off, (u32 *)buf, count);
+}
+
+/**
+ * pci_write_legacy_io - write byte(s) to legacy I/O port space
+ * @kobj: kobject corresponding to file to read from
+ * @buf: buffer containing value to be written
+ * @off: offset into legacy I/O port space
+ * @count: number of bytes to write
+ *
+ * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
+ * callback routine (pci_legacy_write).
+ */
+ssize_t
+pci_write_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+        struct pci_bus *bus = to_pci_bus(container_of(kobj,
+						      struct class_device,
+						      kobj));
+        /* Only support 1, 2 or 4 byte accesses */
+        if (count != 1 && count != 2 && count != 4)
+                return -EINVAL;
+
+        return pci_legacy_write(bus, off, *(u32 *)buf, count);
+}
+
+/**
+ * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
+ * @kobj: kobject corresponding to device to be mapped
+ * @attr: struct bin_attribute for this file
+ * @vma: struct vm_area_struct passed to mmap
+ *
+ * Uses an arch specific callback, pci_mmap_legacy_page_range, to mmap
+ * legacy memory space (first meg of bus space) into application virtual
+ * memory space.
+ */
+int
+pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
+                    struct vm_area_struct *vma)
+{
+        struct pci_bus *bus = to_pci_bus(container_of(kobj,
+                                                      struct class_device,
+						      kobj));
+
+        return pci_mmap_legacy_page_range(bus, vma);
+}
+#endif /* HAVE_PCI_LEGACY */
+
 #ifdef HAVE_PCI_MMAP
 /**
  * pci_mmap_resource - map a PCI resource into user memory space
===== drivers/pci/probe.c 1.72 vs edited =====
--- 1.72/drivers/pci/probe.c	2004-11-11 12:53:33 -08:00
+++ edited/drivers/pci/probe.c	2004-12-21 13:58:10 -08:00
@@ -764,6 +764,42 @@
 	return max;
 }
 
+#ifdef HAVE_PCI_LEGACY
+/**
+ * pci_create_legacy_files - create legacy I/O port and memory files
+ * @b: bus to create files under
+ *
+ * Some platforms allow access to legacy I/O port and ISA memory space on
+ * a per-bus basis.  This routine creates the files and ties them into
+ * their associated read, write and mmap files from pci-sysfs.c
+ */
+static void pci_create_legacy_files(struct pci_bus *b)
+{
+	b->legacy_io = kmalloc(sizeof(struct bin_attribute) * 2,
+			       GFP_ATOMIC);
+	if (b->legacy_io) {
+		b->legacy_io->attr.name = "legacy_io";
+		b->legacy_io->size = 0xffff;
+		b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
+		b->legacy_io->attr.owner = THIS_MODULE;
+		b->legacy_io->read = pci_read_legacy_io;
+		b->legacy_io->write = pci_write_legacy_io;
+		class_device_create_bin_file(&b->class_dev, b->legacy_io);
+
+		/* Allocated above after the legacy_io struct */
+		b->legacy_mem = b->legacy_io + 1;
+		b->legacy_mem->attr.name = "legacy_mem";
+		b->legacy_mem->size = 1024*1024;
+		b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
+		b->legacy_mem->attr.owner = THIS_MODULE;
+		b->legacy_mem->mmap = pci_mmap_legacy_mem;
+		class_device_create_bin_file(&b->class_dev, b->legacy_mem);
+	}
+}
+#else /* !HAVE_PCI_LEGACY */
+static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
+#endif /* HAVE_PCI_LEGACY */
+
 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata)
 {
 	int error;
@@ -807,6 +843,9 @@
 	error = class_device_create_file(&b->class_dev, &class_device_attr_cpuaffinity);
 	if (error)
 		goto class_dev_create_file_err;
+
+	/* Create legacy_io and legacy_mem files for this bus */
+	pci_create_legacy_files(b);
 
 	error = sysfs_create_link(&b->class_dev.kobj, &b->bridge->kobj, "bridge");
 	if (error)
===== include/linux/pci.h 1.143 vs edited =====
--- 1.143/include/linux/pci.h	2004-12-21 11:21:50 -08:00
+++ edited/include/linux/pci.h	2004-12-21 12:32:38 -08:00
@@ -594,6 +594,8 @@
 	unsigned short  pad2;
 	struct device		*bridge;
 	struct class_device	class_dev;
+	struct bin_attribute	*legacy_io; /* legacy I/O for this bus */
+	struct bin_attribute	*legacy_mem; /* legacy mem */
 };
 
 #define pci_bus_b(n)	list_entry(n, struct pci_bus, node)

  reply	other threads:[~2004-12-21 23:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-21 20:47 [PATCH] add legacy resources to sysfs Jesse Barnes
2004-12-21 20:47 ` Jesse Barnes
2004-12-21 21:28 ` Matthew Wilcox
2004-12-21 21:28   ` Matthew Wilcox
2004-12-21 21:44   ` Greg KH
2004-12-21 21:44     ` Greg KH
2004-12-21 21:49   ` Jesse Barnes
2004-12-21 21:49     ` Jesse Barnes
2004-12-21 21:46 ` Greg KH
2004-12-21 21:46   ` Greg KH
2004-12-21 22:05   ` Jesse Barnes
2004-12-21 22:05     ` Jesse Barnes
2004-12-21 23:42     ` Jesse Barnes [this message]
2004-12-22  0:05       ` Greg KH
2004-12-22  0:14         ` Jesse Barnes
2004-12-22  0:20           ` Greg KH
2004-12-22  8:38   ` Benjamin Herrenschmidt
2004-12-22  8:38     ` Benjamin Herrenschmidt
2004-12-22 16:09     ` Greg KH
2004-12-22 16:09       ` Greg KH
2004-12-22 16:34       ` Benjamin Herrenschmidt
2004-12-22 16:34         ` Benjamin Herrenschmidt
2004-12-22 16:58         ` Jesse Barnes
2004-12-22 16:58           ` Jesse Barnes
2004-12-22 18:31           ` Jesse Barnes
2004-12-22 18:31             ` Jesse Barnes
2004-12-22 21:07             ` Greg KH
2004-12-22 21:07               ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200412211542.47997.jbarnes@engr.sgi.com \
    --to=jbarnes@engr.sgi.com \
    --cc=benh@kernel.crashing.org \
    --cc=bjorn.helgaas@hp.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.