Skip to contentSkip to conversation

Add PRUSS UIO driver support

PATCH Superseded Pratheesh Gangadhar 3 participants 9 messages Feb 28, 2011 – Mar 1, 2011 Userspace I/O (UIO)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 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 |  237 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 255 insertions(+), 0 deletions(-)
 create mode 100644 drivers/uio/uio_pruss.c
#1 lore raw

PATCH v6 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 |  237 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 255 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 +237 -0

237 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#2 lore raw

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

drivers/uio/uio_pruss.c line 193

Quoted 12 lines · Pratheesh Gangadhar
drivers/uio/uio_pruss.c new file +12 -0
+
+		/* Register PRUSS IRQ lines */
+		p->irq = IRQ_DA8XX_EVTOUT0 + cnt;
+		p->handler = pruss_handler;
+
+		ret = uio_register_device(&dev->dev, p);
+
+		if (ret < 0)
+			goto out_free;
+	}
+
+	spin_lock_init(&lock);

That's too late. uio_register_device() enables the irq, and your spin_lock is not ready at that time.

drivers/uio/uio_pruss.c line 200

Quoted 7 lines
drivers/uio/uio_pruss.c new file +7 -0
+	platform_set_drvdata(dev, info);
+	return 0;
+
+out_free:
+	pruss_cleanup(dev, info);
+	return ret;
+}

Thanks,
Hans

#3 lore raw

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

Hi,

Quoted 11 lines

-----Original Message-----
From: Hans J. Koch [mailto:hjk at hansjkoch.de]
Sent: Tuesday, March 01, 2011 2:57 AM
To: TK, Pratheesh Gangadhar
Cc: linux-kernel at vger.kernel.org; hjk at hansjkoch.de; gregkh at suse.de; tglx at linutronix.de; sshtylyov at mvista.com; arnd at arndb.de; Chatterjee, Amit; davinci-linux-open-source at linux.davincidsp.com; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH v6 1/1] PRUSS UIO driver support

On Tue, Mar 01, 2011 at 02:31:35AM +0530, Pratheesh Gangadhar wrote:

Quoted 15 lines

drivers/uio/uio_pruss.c line 193

Quoted 12 lines
drivers/uio/uio_pruss.c new file +12 -0
+
+		/* Register PRUSS IRQ lines */
+		p->irq = IRQ_DA8XX_EVTOUT0 + cnt;
+		p->handler = pruss_handler;
+
+		ret = uio_register_device(&dev->dev, p);
+
+		if (ret < 0)
+			goto out_free;
+	}
+
+	spin_lock_init(&lock);

That's too late. uio_register_device() enables the irq, and your spin_lock is not ready at that time.

This is ok in this context as "modprobe uio_pruss" is pre-requisite for running PRUSS firmware and without firmware running PRUSS won't generate interrupts. Actually PRUSS INTC is not setup till we start user application.

Thanks,
Pratheesh

#8 lore raw

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

In reply to Pratheesh Gangadhar

Review

Quoted 2 lines · Pratheesh Gangadhar
(quoted diff) +2 -0
+
+static spinlock_t lock;

static DEFINE_SPINLOCK(lock);

Quoted 4 lines
drivers/uio/uio_pruss.c new file +4 -0
+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 *dev_info)
+{
+	unsigned long flags;
+	int val, intr_mask = (1 << (irq - 1));
+	void __iomem *base = dev_info->mem[0].internal_addr;
+	void __iomem *intren_reg = base + PINTC_HIER;
+	void __iomem *intrstat_reg = base + PINTC_HIPIR + ((irq - 1) << 2);
+
+	spin_lock_irqsave(&lock, flags);

spin_lock() is enough as we run handlers with interrupts disabled.

drivers/uio/uio_pruss.c line 91

Quoted 12 lines
drivers/uio/uio_pruss.c new file +12 -0
+	val = ioread32(intren_reg);
+	/* Is interrupt enabled and active ? */
+	if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND)) {
+		spin_unlock_irqrestore(&lock, flags);
+		return IRQ_NONE;
+	}
+
+	/* Disable interrupt */
+	iowrite32((val & ~intr_mask), intren_reg);
+	spin_unlock_irqrestore(&lock, flags);
+	return IRQ_HANDLED;
+}

So now you still have not solved the problem of user space enabling an interrupt again. That's racy as well and you can solve it by providing an uio->irq_control function which handles the interrupt enable register under the lock as well.

Thanks,

tglx

#4 lore raw

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

In reply to TK, Pratheesh Gangadhar
Quoted 17 lines · Pratheesh Gangadhar
Quoted 8 lines · Pratheesh Gangadhar
Quoted 7 lines
drivers/uio/uio_pruss.c new file +7 -0
+
+		/* Register PRUSS IRQ lines */
+		p->irq = IRQ_DA8XX_EVTOUT0 + cnt;
+		p->handler = pruss_handler;
+
+		ret = uio_register_device(&dev->dev, p);
+
Quoted 8 lines

drivers/uio/uio_pruss.c line 193

Quoted 5 lines
drivers/uio/uio_pruss.c new file +5 -0
+		if (ret < 0)
+			goto out_free;
+	}
+
+	spin_lock_init(&lock);

That's too late. uio_register_device() enables the irq, and your spin_lock is not ready at that time.

Quoted 4 lines

This is ok in this context as "modprobe uio_pruss" is pre-requisite for running PRUSS firmware and without firmware running PRUSS won't generate interrupts. Actually PRUSS INTC is not setup till we start user application.

No, it's not. If you enable interrupts you have to be prepared for getting one whether the device mask is enabled or not. It's that simple.

Thanks,

tglx

#5 lore raw

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

In reply to TK, Pratheesh Gangadhar
Quoted 29 lines · Pratheesh Gangadhar

Hi,

Quoted 11 lines

-----Original Message-----
From: Hans J. Koch [mailto:hjk at hansjkoch.de]
Sent: Tuesday, March 01, 2011 2:57 AM
To: TK, Pratheesh Gangadhar
Cc: linux-kernel at vger.kernel.org; hjk at hansjkoch.de; gregkh at suse.de; tglx at linutronix.de; sshtylyov at mvista.com; arnd at arndb.de; Chatterjee, Amit; davinci-linux-open-source at linux.davincidsp.com; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH v6 1/1] PRUSS UIO driver support

On Tue, Mar 01, 2011 at 02:31:35AM +0530, Pratheesh Gangadhar wrote:

Quoted 15 lines

drivers/uio/uio_pruss.c line 193

Quoted 12 lines
drivers/uio/uio_pruss.c new file +12 -0
+
+		/* Register PRUSS IRQ lines */
+		p->irq = IRQ_DA8XX_EVTOUT0 + cnt;
+		p->handler = pruss_handler;
+
+		ret = uio_register_device(&dev->dev, p);
+
+		if (ret < 0)
+			goto out_free;
+	}
+
+	spin_lock_init(&lock);

That's too late. uio_register_device() enables the irq, and your spin_lock is not ready at that time.

Quoted 4 lines

This is ok in this context as "modprobe uio_pruss" is pre-requisite for running PRUSS firmware and without firmware running PRUSS won't generate interrupts. Actually PRUSS INTC is not setup till we start user application.

What if the user application is stopped, UIO driver module unloaded and loaded again?

Anyway, please don't use that kind of argumentation. The next newbie developer might copy your work as a basis for his new driver, and there it probably won't work.

Simply put the spin_lock_init before the loop.

Thanks,
Hans

#6 lore raw

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

Hi,

Quoted 42 lines

-----Original Message-----
From: Hans J. Koch [mailto:hjk at hansjkoch.de]
Sent: Wednesday, March 02, 2011 12:04 AM
To: TK, Pratheesh Gangadhar
Cc: Hans J. Koch; linux-kernel at vger.kernel.org; gregkh at suse.de; tglx at linutronix.de; sshtylyov at mvista.com; arnd at arndb.de; Chatterjee, Amit; davinci-linux-open-source at linux.davincidsp.com; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH v6 1/1] PRUSS UIO driver support

Quoted 8 lines · Pratheesh Gangadhar

Hi,

Quoted 6 lines

-----Original Message-----
From: Hans J. Koch [mailto:hjk at hansjkoch.de]
Sent: Tuesday, March 01, 2011 2:57 AM
To: TK, Pratheesh Gangadhar
Cc: linux-kernel at vger.kernel.org; hjk at hansjkoch.de; gregkh at suse.de; tglx at linutronix.de; sshtylyov at mvista.com; arnd at arndb.de; Chatterjee,

Amit;

Quoted 5 lines
Quoted 5 lines

davinci-linux-open-source at linux.davincidsp.com; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v6 1/1] PRUSS UIO driver support

On Tue, Mar 01, 2011 at 02:31:35AM +0530, Pratheesh Gangadhar wrote:

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/uio/uio_pruss.c new file +6 -0
+
+		/* Register PRUSS IRQ lines */
+		p->irq = IRQ_DA8XX_EVTOUT0 + cnt;
+		p->handler = pruss_handler;
+
+		ret = uio_register_device(&dev->dev, p);
Quoted 8 lines

drivers/uio/uio_pruss.c line 193

Quoted 6 lines
drivers/uio/uio_pruss.c new file +6 -0
+
+		if (ret < 0)
+			goto out_free;
+	}
+
+	spin_lock_init(&lock);

That's too late. uio_register_device() enables the irq, and your

spin_lock

Quoted 2 lines
Quoted 1 line

is not ready at that time.

Quoted 8 lines
Quoted 4 lines

This is ok in this context as "modprobe uio_pruss" is pre-requisite for running PRUSS firmware and without firmware running PRUSS won't generate interrupts. Actually PRUSS INTC is not setup till we start user application.

What if the user application is stopped, UIO driver module unloaded and loaded again?

This is a possible scenario - may be a buggy application. Normally when application is stopped, PRUs are stopped by exit handler.

Quoted 6 lines

Anyway, please don't use that kind of argumentation. The next newbie developer might copy your work as a basis for his new driver, and there it probably won't work.

Simply put the spin_lock_init before the loop.

Agree, will fix this in next version.

Thanks,
Pratheesh

#7 lore raw

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

Quoted 10 lines · Pratheesh Gangadhar

Hi,

Quoted 9 lines

-----Original Message-----
From: Hans J. Koch [mailto:hjk at hansjkoch.de]
Sent: Wednesday, March 02, 2011 12:04 AM
To: TK, Pratheesh Gangadhar
Cc: Hans J. Koch; linux-kernel at vger.kernel.org; gregkh at suse.de; tglx at linutronix.de; sshtylyov at mvista.com; arnd at arndb.de; Chatterjee, Amit; davinci-linux-open-source at linux.davincidsp.com; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH v6 1/1] PRUSS UIO driver support

Sigh, can you please use a mailer which does not repeat the headers for no value and just has a single line like this:

Quoted 8 lines
Quoted 7 lines · Pratheesh Gangadhar

Anyway, please don't use that kind of argumentation. The next newbie developer might copy your work as a basis for his new driver, and there it probably won't work.

Simply put the spin_lock_init before the loop.

Agree, will fix this in next version.

As I said before, we want stuff initialized when it is possibly used. But first of all we ant people to use the proper mechanisms to achive that.

If that's a module global lock then it needs to be instantiated by

static DEFINE_SPINLOCK(lock);

which implies the initialization of the lock.

If it's a lock which is in allocated memory then the

   spin_lock_init(&lock);

wants to be before it can be possibly used.

So in your case DEFINE_SPINLOCK is the correct solution.

Thanks,

tglx