Skip to contentSkip to conversation

Add PRUSS UIO driver support

PATCH Superseded Pratheesh Gangadhar 3 participants 6 messages Mar 1, 2011 – Mar 2, 2011 Userspace I/O (UIO)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add PRUSS UIO driver support

This patch series add support for PRUSS (Programmable Real-time Unit Sub System) UIO driver in Texas Instruments DA850, AM18xx and OMAP-L138 processors. PRUSS is programmable RISC core which can be used to implement Soft IPs (eg:- DMA, CAN, UART,SmartCard) and Industrial communications data link layers (eg:- PROFIBUS). UIO driver exposes PRUSS resources like memory and interrupts to user space application.PRUSS UIO application API can be used to control PRUs in PRUSS, setup PRU INTC, load firmware to PRUs and implement IPC between Host processor and PRUs. More information on PRUSS and UIO linux user space API available in the links below

http://processors.wiki.ti.com/index.php/Programmable_Realtime_Unit_Subsystem
http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader
http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader_API_Guide

Platform/board specific portion of this patch depends on Mistral patches below

[PATCH 1/1] davinci: changed SRAM allocator to shared ram :

				https://patchwork.kernel.org/patch/549351/
[PATCH 1/1] da830: macro rename DA8XX_LPSC0_DMAX to DA8XX_LPSC0_PRUSS :
				 https://patchwork.kernel.org/patch/549331/
[PATCH v2 01/13] mfd: pruss mfd driver :
				https://patchwork.kernel.org/patch/549531/
[PATCH v2 02/13] da850: pruss platform specific additions :
				https://patchwork.kernel.org/patch/549521/

I will submit a seperate patch set on top of these patches to support PRUSS UIO driver.

Pratheesh Gangadhar (1):
PRUSS UIO driver support

 drivers/uio/Kconfig     |   17 +++
 drivers/uio/Makefile    |    1 +
 drivers/uio/uio_pruss.c |  257 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/uio/uio_pruss.c
#1 lore raw

PATCH v7 1/1 PRUSS UIO driver support

This patch implements PRUSS (Programmable Real-time Unit Sub System) UIO driver which exports SOC resources associated with PRUSS like I/O, memories and IRQs to user space. PRUSS is dual 32-bit RISC processors which is efficient in performing embedded tasks that require manipulation of packed memory mapped data structures and handling system events that have tight real time constraints. This driver is currently supported on Texas Instruments DA850, AM18xx and OMAP-L138 devices.
For example, PRUSS runs firmware for real-time critical industrial communication data link layer and communicates with application stack running in user space via shared memory and IRQs.

---
 drivers/uio/Kconfig     |   17 +++
 drivers/uio/Makefile    |    1 +
 drivers/uio/uio_pruss.c |  257 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/uio/uio_pruss.c
drivers/uio/Kconfig +17 -0
index bb44079..6f3ea9b 100644
@@ -94,4 +94,21 @@ config UIO_NETX
 	  To compile this driver as a module, choose M here; the module
 	  will be called uio_netx.
 
+config UIO_PRUSS
+	tristate "Texas Instruments PRUSS driver"
+	depends on ARCH_DAVINCI_DA850
+	help
+	  PRUSS driver for OMAPL138/DA850/AM18XX devices
+	  PRUSS driver requires user space components, examples and user space
+	  driver is available from below SVN repo - you may use anonymous login
+
+	  https://gforge.ti.com/gf/project/pru_sw/
+
+	  More info on API is available at below wiki
+
+	  http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called uio_pruss.
+
 endif
drivers/uio/Makefile +1 -0
index 18fd818..d4dd9a5 100644
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC)	+= uio_aec.o
 obj-$(CONFIG_UIO_SERCOS3)	+= uio_sercos3.o
 obj-$(CONFIG_UIO_PCI_GENERIC)	+= uio_pci_generic.o
 obj-$(CONFIG_UIO_NETX)	+= uio_netx.o
+obj-$(CONFIG_UIO_PRUSS)         += uio_pruss.o
drivers/uio/uio_pruss.c new file +257 -0

257 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#2 lore raw

Re: [PATCH v7 1/1] PRUSS UIO driver support

Quoted 6 lines · Pratheesh Gangadhar
drivers/uio/uio_pruss.c new file +6 -0
+
+static DEFINE_SPINLOCK(lock);
+static struct clk *pruss_clk;
+static struct uio_info *info;
+static dma_addr_t sram_paddr, ddr_paddr;
+static void *prussio_vaddr, *sram_vaddr, *ddr_vaddr;

drivers/uio/uio_pruss.c line 79

Quoted 10 lines
drivers/uio/uio_pruss.c new file +10 -0
+
+static irqreturn_t pruss_handler(int irq, struct uio_info *info)
+{
+	int intr_bit = (irq - IRQ_DA8XX_EVTOUT0 + 2);
+	int val, intr_mask = (1 << intr_bit);
+	void __iomem *base = info->mem[0].internal_addr;
+	void __iomem *intren_reg = base + PINTC_HIER;
+	void __iomem *intrstat_reg = base + PINTC_HIPIR + (intr_bit << 2);
+
+	spin_lock_irq(&lock);

No, I said: spin_lock() is sufficient.

drivers/uio/uio_pruss.c line 83

Quoted 4 lines
drivers/uio/uio_pruss.c new file +4 -0
+	val = ioread32(intren_reg);
+	/* Is interrupt enabled and active ? */
+	if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND)) {
+		spin_unlock_irq(&lock);

You unconditinally enable interrupts here where you are not supposed to do so.

Quoted 7 lines
drivers/uio/uio_pruss.c new file +7 -0
+		return IRQ_NONE;
+	}
+
+	/* Disable interrupt */
+	iowrite32((val & ~intr_mask), intren_reg);
+	spin_unlock_irq(&lock);
+	return IRQ_HANDLED;

drivers/uio/uio_pruss.c line 100

Quoted 10 lines
drivers/uio/uio_pruss.c new file +10 -0
+}
+
+static int pruss_irqcontrol(struct uio_info *info, s32 irq_on)
+{
+	int intr_bit = info->irq - IRQ_DA8XX_EVTOUT0 + 2;
+	int val, intr_mask = (1 << intr_bit);
+	void __iomem *base = info->mem[0].internal_addr;
+	void __iomem *intren_reg = base + PINTC_HIER;
+
+	spin_lock_irq(&lock);

This one is correct, as this is always called from non interrupt disabled context.

drivers/uio/uio_pruss.c

Quoted 13 lines
drivers/uio/uio_pruss.c new file +11 -0
+	val = ioread32(intren_reg);
+	if (irq_on)
+		iowrite32((val | intr_mask), intren_reg);
+	else
+		iowrite32((val & ~intr_mask), intren_reg);
+	spin_unlock_irq(&lock);
+
+	return 0;
+}
 
 
+
+	spin_lock_init(&lock);

Sigh. DEFINE_SPINLOCK(lock); already initializes the lock.

It's not the purpose of a review to tell you what you need to change mechanically. Reviewers hint to a correct solution and you are supposed to lookup what that solution means and act accordingly. If you do not understand the hint or its implications please ask _before_ sending a new patch set.

Thanks,

tglx

#3 lore raw

Re: [PATCH v7 1/1] PRUSS UIO driver support

Quoted 11 lines · Thomas Gleixner

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+	spin_lock_init(&lock);

Sigh. DEFINE_SPINLOCK(lock); already initializes the lock.

It's not the purpose of a review to tell you what you need to change mechanically. Reviewers hint to a correct solution and you are supposed to lookup what that solution means and act accordingly. If you do not understand the hint or its implications please ask _before_ sending a new patch set.

Correct. But I'm to blame here, too, since I suggested the wrong solution. Sorry for that, Gangadhar!

Thanks,
Hans

#4 lore raw

RE: [PATCH v7 1/1] PRUSS UIO driver support

In reply to Thomas Gleixner

Hi,

Quoted 12 lines

From: Thomas Gleixner [mailto:tglx at linutronix.de]
Sent: Wednesday, March 02, 2011 3:15 AM

Quoted 10 lines
drivers/uio/uio_pruss.c new file +10 -0
+
+static DEFINE_SPINLOCK(lock);
+static struct clk *pruss_clk;
+static struct uio_info *info;
+static dma_addr_t sram_paddr, ddr_paddr;
+static void *prussio_vaddr, *sram_vaddr, *ddr_vaddr;
+
+static irqreturn_t pruss_handler(int irq, struct uio_info *info)
+{
+	int intr_bit = (irq - IRQ_DA8XX_EVTOUT0 + 2);
Quoted 8 lines

drivers/uio/uio_pruss.c line 79

Quoted 6 lines
drivers/uio/uio_pruss.c new file +6 -0
+	int val, intr_mask = (1 << intr_bit);
+	void __iomem *base = info->mem[0].internal_addr;
+	void __iomem *intren_reg = base + PINTC_HIER;
+	void __iomem *intrstat_reg = base + PINTC_HIPIR + (intr_bit << 2);
+
+	spin_lock_irq(&lock);

No, I said: spin_lock() is sufficient.

Ok.

Quoted 8 lines

drivers/uio/uio_pruss.c line 83

Quoted 4 lines
drivers/uio/uio_pruss.c new file +4 -0
+	val = ioread32(intren_reg);
+	/* Is interrupt enabled and active ? */
+	if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND)) {
+		spin_unlock_irq(&lock);

You unconditinally enable interrupts here where you are not supposed to do so.

Ok.

Quoted 5 lines

drivers/uio/uio_pruss.c line 88

Quoted 5 lines
drivers/uio/uio_pruss.c new file +5 -0
+		return IRQ_NONE;
+	}
+
+	/* Disable interrupt */
+	iowrite32((val & ~intr_mask), intren_reg);

I checked more on this and actually INTC h/w has Host Interrupt Enable Indexed Set Register (HIEISR) and Host Interrupt Enable Indexed Clear Register(HIEICR) which I can use to enable/disable interrupts without doing RMW. I will use these registers and then we don't need all the spinlock and irqcontrol stuff. So I need to do

iowrite32((intr_bit, HIEICR);// This disable the interrupt bit in intern_reg.

Userspace can use HIEISR to re-enable the interrupt.

Quoted 32 lines

drivers/uio/uio_pruss.c line 100

Quoted 12 lines
drivers/uio/uio_pruss.c new file +12 -0
+	spin_unlock_irq(&lock);
+	return IRQ_HANDLED;
+}
+
+static int pruss_irqcontrol(struct uio_info *info, s32 irq_on)
+{
+	int intr_bit = info->irq - IRQ_DA8XX_EVTOUT0 + 2;
+	int val, intr_mask = (1 << intr_bit);
+	void __iomem *base = info->mem[0].internal_addr;
+	void __iomem *intren_reg = base + PINTC_HIER;
+
+	spin_lock_irq(&lock);

This one is correct, as this is always called from non interrupt disabled context.

drivers/uio/uio_pruss.c

Quoted 13 lines
drivers/uio/uio_pruss.c new file +11 -0
+	val = ioread32(intren_reg);
+	if (irq_on)
+		iowrite32((val | intr_mask), intren_reg);
+	else
+		iowrite32((val & ~intr_mask), intren_reg);
+	spin_unlock_irq(&lock);
+
+	return 0;
+}
 
 
+
+	spin_lock_init(&lock);

Sigh. DEFINE_SPINLOCK(lock); already initializes the lock.

Quoted 5 lines

It's not the purpose of a review to tell you what you need to change mechanically. Reviewers hint to a correct solution and you are supposed to lookup what that solution means and act accordingly. If you do not understand the hint or its implications please ask _before_ sending a new patch set.

Seriously, I went to "fix the comments" mode. Sorry about that. Anyway I learnt more about things by making mistakes i.e. the positive side. Thanks a lot for helping us improve on this.

Pratheesh

#5 lore raw

RE: [PATCH v7 1/1] PRUSS UIO driver support

Quoted 10 lines · Pratheesh Gangadhar
Quoted 3 lines

From: Thomas Gleixner [mailto:tglx at linutronix.de]

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* Disable interrupt */
+	iowrite32((val & ~intr_mask), intren_reg);

I checked more on this and actually INTC h/w has Host Interrupt Enable Indexed Set Register (HIEISR) and Host Interrupt Enable Indexed Clear Register(HIEICR) which I can use to enable/disable interrupts without doing RMW. I will use these registers and then we don't need all the spinlock and irqcontrol stuff. So I need to do

Quoted 4 lines

iowrite32((intr_bit, HIEICR);// This disable the interrupt bit in intern_reg.

Userspace can use HIEISR to re-enable the interrupt.

Great, that makes it way simpler!

Quoted 9 lines
Quoted 5 lines

It's not the purpose of a review to tell you what you need to change mechanically. Reviewers hint to a correct solution and you are supposed to lookup what that solution means and act accordingly. If you do not understand the hint or its implications please ask _before_ sending a new patch set.

Seriously, I went to "fix the comments" mode. Sorry about that. Anyway I learnt more about things by making mistakes i.e. the positive side. Thanks a lot for helping us improve on this.

Welcome!

tglx