Userspace I/O

From krtkl wiki
Jump to: navigation, search

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);