Skip to contentSkip to conversation

powerpc: Add legacy PCI access via sysfs

PATCH In review Benjamin Herrenschmidt 2 participants 5 messages Oct 3, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 powerpc: Add legacy PCI access via sysfs

This patch adds support for legacy_io and legacy_mem files in bus class directories in sysfs for powerpc

---

Unfortunately, I didn't have a chance to properly test it yet. I was hoping to use an old VGA card to muck around with but the card seems fried. I'll do some more tests next wee, but at least it appears to be mmap'ing the right physical address.

 arch/powerpc/include/asm/pci.h   |   11 +++
 arch/powerpc/kernel/pci-common.c |  140 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 149 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/pci.h +11 -0
@@ -123,6 +123,16 @@ int pci_mmap_page_range(struct pci_dev *
 /* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */
 #define HAVE_PCI_MMAP	1
 
+extern int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val,
+			   size_t count);
+extern int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val,
+			   size_t count);
+extern int pci_mmap_legacy_page_range(struct pci_bus *bus,
+				      struct vm_area_struct *vma,
+				      enum pci_mmap_state mmap_state);
+
+#define HAVE_PCI_LEGACY	1
+
 #if defined(CONFIG_PPC64) || defined(CONFIG_NOT_COHERENT_CACHE)
 /*
  * For 64-bit kernels, pci_unmap_{single,page} is not a nop.
@@ -226,5 +236,6 @@ extern void pci_resource_to_user(const s
 extern void pcibios_do_bus_setup(struct pci_bus *bus);
 extern void pcibios_fixup_of_probed_bus(struct pci_bus *bus);
 
+
 #endif	/* __KERNEL__ */
 #endif /* __ASM_POWERPC_PCI_H */
arch/powerpc/kernel/pci-common.c +138 -2

158 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
arch/powerpc/kernel/pci-common.c +11 -0
+	/* WARNING: The generic code is idiotic. It gets passed a pointer
+	 * to what can be a 1, 2 or 4 byte quantity and always reads that
+	 * as a u32, which means that we have to correct the location of
+	 * the data read within those 32 bits for size 1 and 2
+	 */
+	switch(size) {
+	case 1:
+		out_8(addr, val >> 24);
+		return 1;
+	case 2:
+		if (port & 1)

arch/powerpc/kernel/pci-common.c int pci_mmap_page_range(struct pci_dev * · line 577

Quoted 10 lines
arch/powerpc/kernel/pci-common.c +10 -0
+			return -EINVAL;
+		out_le16(addr, val >> 16);
+		return 2;
+	case 4:
+		if (port & 3)
+			return -EINVAL;
+		out_le32(addr, val);
+		return 4;
+	}
+	return -EINVAL;

Feel free to change the generic code if it makes things easier for you, the only limitation is that we have to live within the generic sysfs read/write functions. Obviously I didn't worry about it when doing this code on ia64...

Jesse

#2 lore raw
Quoted 4 lines · Jesse Barnes

Feel free to change the generic code if it makes things easier for you, the only limitation is that we have to live within the generic sysfs read/write functions. Obviously I didn't worry about it when doing this code on ia64...

I started to do that and then decided not to bother...

Ben.

#3 lore raw
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 4 lines · Jesse Barnes

Feel free to change the generic code if it makes things easier for you, the only limitation is that we have to live within the generic sysfs read/write functions. Obviously I didn't worry about it when doing this code on ia64...

I started to do that and then decided not to bother...

Well than you can at least update the comment in the ppc platform code from "The generic code is idiotic" to "The generic code is idiotic and I'm too lazy to fix it". :)

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#4 lore raw
Quoted 7 lines · Jesse Barnes
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Jesse Barnes

Feel free to change the generic code if it makes things easier for you, the only limitation is that we have to live within the generic sysfs read/write functions. Obviously I didn't worry about it when doing this code on ia64...

Quoted 5 lines
Quoted 1 line

I started to do that and then decided not to bother...

Well than you can at least update the comment in the ppc platform code from "The generic code is idiotic" to "The generic code is idiotic and I'm too lazy to fix it". :)

Meuhh... Ok, I'll have another look. The main reason I didn't want to change it was that I didn't want to have to fix ia64 more than I already did :-)

Cheers,
Ben.