Difference between revisions of "Userspace I/O"

From krtkl wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
  
 
<pre>
 
<pre>
axi_gpio0: gpio@41200000 {
+
fpga-axi@0 {
        reg = <0x41200000 0x10000>;
+
compatible = "simple-bus";
        compatible = "krtkl,generic-uio,ui_pdrv";
+
#address-cells = <1>;
        interrupt-parent = <&intc>;
+
#size-cells = <1>;
        interrupts = <0 29 4>;  
+
ranges;
 +
interrupt-parent = <&intc>;
 +
 
 +
uio0: uio0@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 29 4>;
 +
};
 +
 
 +
uio1: uio1@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 30 4>;
 +
};
 +
 
 +
uio2: uio2@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 31 4>;
 +
};
 +
 
 +
uio3: uio3@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 32 4>;
 +
};
 +
 
 +
uio4: uio4@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 33 4>;
 +
};
 +
 
 +
uio5: uio5@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 34 4>;
 +
};
 +
 
 +
uio6: uio6@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 35 4>;
 +
};
 +
 
 +
uio7: uio7@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 36 4>;
 +
};
 +
 
 +
uio8: uio8@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 52 4>;
 +
};
 +
 
 +
uio9: uio9@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 53 4>;
 +
};
 +
 
 +
uio10: uio10@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 54 4>;
 +
};
 +
 
 +
uio11: uio11@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 55 4>;
 +
};
 +
 
 +
uio12: uio12@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 56 4>;
 +
};
 +
 
 +
uio13: uio13@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 57 4>;
 +
};
 +
 
 +
uio14: uio14@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 58 4>;
 +
};
 +
 
 +
uio15: uio15@40000000 {
 +
reg = <0x40000000 0x80000000>;
 +
compatible = "krtkl,generic-uio,ui_pdrv";
 +
status = "okay";
 +
interrupt-parent = <&intc>;
 +
interrupts = <0 59 4>;
 +
};
 
};
 
};
 
</pre>
 
</pre>
Line 25: Line 154:
 
/* Close the UIO device */
 
/* Close the UIO device */
 
close(fd);
 
close(fd);
 
/* Apply the offset to the memory */
 
iomem += offset / sizeof(void *);
 
  
 
/* Point structure to memory */
 
/* Point structure to memory */

Latest revision as of 03:51, 18 June 2018

Boot Arguments

uio_pdrv_genirq.of_id=krtkl,generic-uio,ui_pdrv

Device Tree Bindings

fpga-axi@0 {
	compatible = "simple-bus";
	#address-cells = <1>;
	#size-cells = <1>;
	ranges;
	interrupt-parent = <&intc>;

	uio0: uio0@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 29 4>;
	};

	uio1: uio1@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 30 4>;
	};

	uio2: uio2@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 31 4>;
	};

	uio3: uio3@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 32 4>;
	};

	uio4: uio4@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 33 4>;
	};

	uio5: uio5@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 34 4>;
	};

	uio6: uio6@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 35 4>;
	};

	uio7: uio7@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 36 4>;
	};

	uio8: uio8@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 52 4>;
	};

	uio9: uio9@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 53 4>;
	};

	uio10: uio10@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 54 4>;
	};

	uio11: uio11@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 55 4>;
	};

	uio12: uio12@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 56 4>;
	};

	uio13: uio13@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 57 4>;
	};

	uio14: uio14@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 58 4>;
	};

	uio15: uio15@40000000 {
		reg = <0x40000000 0x80000000>;
		compatible = "krtkl,generic-uio,ui_pdrv";
		status = "okay";
		interrupt-parent = <&intc>;
		interrupts = <0 59 4>;
	};
};

Application Interface

/* Open the UIO device */
fd = open("/dev/uio0", O_RDWR | O_SYNC);

/* Map the memory */
iomem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

/* Close the UIO device */
close(fd);

/* Point structure to memory */
dev = (struct peripheral *)iomem;

/* Perform read/write operations using structure pointer */
dev->ier = (1 << 0);

/* Unmask the interrupt */
en = 1;
write(fd, &en, sizeof(en));

/* Wait for an interrupt with blocking read */
read(fd, &nirq, sizeof(nirq));

/* Handle the interrupt */
if (nirq) {
        stat = dev->isr;           /* Read interrupt  status */
        if (stat)
                dev->isr = stat;   /* Clear interrupt on device */

        data = dev->data;
}

/* Unmap the memory when finished */
munmap(iomem, size);

fd = open("/dev/uio0", O_RDWR | O_SYNC);

/* Map the Nth memory map by specifying offset of N * PAGE_SIZE */
iomem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, PAGE_SIZE);

close(fd);

/* Perform memory operations */
msync(iomem, size, MS_SYNC);

munmap(iomem, size);