Skip to contentSkip to conversation

Xilinx Internal Configuration Access Port device driver.

PATCH In review Stephen Neuendorffer 3 participants 9 messages Dec 4, 2007 – Jan 31, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Xilinx Internal Configuration Access Port device driver.

Supports static platform_device and static device tree configuration. This is a standalone driver that does not depend on EDK generated files. However, it is also somewhat different in functionality from the standard EDK driver.

1) The EDK driver doesn't support readback, which this driver does.
2) The EDK driver supports fine granularity reading and writing, which this driver does not. The fine granularity support is heavily architecture independent, which makes it difficult to make the driver forward compatible. The fine granularity support is also complex and probably better handled in user space anyway.

---

Grant,

No comments last time... It would be nice if this merged with 2.6.25, I think.

Steve

 drivers/char/Kconfig                       |    5 +
 drivers/char/Makefile                      |    1 +
 drivers/char/xilinx_hwicap/Makefile        |    7 +
 drivers/char/xilinx_hwicap/xhwicap_srp.c   |  414 ++++++++++++++++++++
 drivers/char/xilinx_hwicap/xilinx_hwicap.c |  565 ++++++++++++++++++++++++++++
 drivers/char/xilinx_hwicap/xilinx_hwicap.h |  539 ++++++++++++++++++++++++++
 6 files changed, 1531 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/xilinx_hwicap/Makefile
 create mode 100644 drivers/char/xilinx_hwicap/xhwicap_srp.c
 create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.c
 create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.h
drivers/char/Kconfig +5 -0
index bf18d75..72295cc 100644
@@ -573,6 +573,11 @@ config HVC_DRIVER
 	  It will automatically be selected if one of the back-end console drivers
 	  is selected.
 
+config XILINX_HWICAP
+	tristate "Xilinx OPB HWICAP Support"
+	depends on XILINX_VIRTEX
+	help
+	This option enables support for Xilinx Internal Configuration Access Port (ICAP) driver.
 
 config HVC_CONSOLE
 	bool "pSeries Hypervisor Virtual Console support"
drivers/char/Makefile +1 -0
index 07304d5..8cfcbb0 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_EFI_RTC)		+= efirtc.o
 obj-$(CONFIG_SGI_DS1286)	+= ds1286.o
 obj-$(CONFIG_SGI_IP27_RTC)	+= ip27-rtc.o
 obj-$(CONFIG_DS1302)		+= ds1302.o
+obj-$(CONFIG_XILINX_HWICAP)	+= xilinx_hwicap/
 ifeq ($(CONFIG_GENERIC_NVRAM),y)
   obj-$(CONFIG_NVRAM)	+= generic_nvram.o
 else
drivers/char/xilinx_hwicap/Makefile new file +7 -0
new file mode 100644
index 0000000..818f4e1
@@ -0,0 +1,7 @@
+#
+# Makefile for the Xilinx OPB hwicap driver
+#
+
+obj-$(CONFIG_XILINX_HWICAP) += xilinx_hwicap_m.o 
+ 
+xilinx_hwicap_m-y := xilinx_hwicap.o xhwicap_srp.o
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +414 -0

414 lines not on this page · raw message

drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +565 -0

565 lines not on this page · raw message

drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +539 -0

539 lines not on this page · raw message

Signature · 1 line
1.5.3.4-dirty
#1 lore raw
Quoted 12 lines · Stephen Neuendorffer

Supports static platform_device and static device tree configuration. This is a standalone driver that does not depend on EDK generated files. However, it is also somewhat different in functionality from the standard EDK driver.

1) The EDK driver doesn't support readback, which this driver does.
2) The EDK driver supports fine granularity reading and writing, which this driver does not. The fine granularity support is heavily architecture independent, which makes it difficult to make the driver forward compatible. The fine granularity support is also complex and probably better handled in user space anyway.

Quoted 6 lines

---

Grant,

No comments last time... It would be nice if this merged with 2.6.25, I think.

Sorry Steve, I must have missed it. I'll review and comment.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#2 lore raw
In reply to Stephen Neuendorffer
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Stephen" == Stephen Neuendorffer <[email protected]> writes:

Hi,

Stephen> Supports static platform_device and static device tree configuration. Stephen> This is a standalone driver that does not depend on EDK generated Stephen> files. However, it is also somewhat different in functionality from Stephen> the standard EDK driver.

Stephen> 1) The EDK driver doesn't support readback, which this driver does. Stephen> 2) The EDK driver supports fine granularity reading and writing, which Stephen> this driver does not. The fine granularity support is heavily Stephen> architecture independent, which makes it difficult to make the driver Stephen> forward compatible. The fine granularity support is also complex and Stephen> probably better handled in user space anyway.

Stephen> Signed-off-by: Stephen Neuendorffer <[email protected]> Stephen> ---

Stephen> Grant,

Stephen> No comments last time... It would be nice if this merged Stephen> with 2.6.25, I think.

Stephen> Steve

I never used the icap stuff, but here goes ..

 Stephen>  drivers/char/Kconfig                       |    5 +
 Stephen>  drivers/char/Makefile                      |    1 +
 Stephen>  drivers/char/xilinx_hwicap/Makefile        |    7 +
 Stephen>  drivers/char/xilinx_hwicap/xhwicap_srp.c   |  414 ++++++++++++++++++++
 Stephen>  drivers/char/xilinx_hwicap/xilinx_hwicap.c |  565 ++++++++++++++++++++++++++++
 Stephen>  drivers/char/xilinx_hwicap/xilinx_hwicap.h |  539 ++++++++++++++++++++++++++
 Stephen>  6 files changed, 1531 insertions(+), 0 deletions(-)
 Stephen>  create mode 100644 drivers/char/xilinx_hwicap/Makefile
 Stephen>  create mode 100644 drivers/char/xilinx_hwicap/xhwicap_srp.c
 Stephen>  create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.c
 Stephen>  create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.h

drivers/char/Kconfig config HVC_DRIVER · line 574

Quoted 7 lines
drivers/char/Kconfig +0 -0
index bf18d75..72295cc 100644
@@ -573,6 +573,11 @@ config HVC_DRIVER
 	  It will automatically be selected if one of the back-end console drivers
 	  is selected.

Please don't put the HWICAP option in the middle of the HVC options.

drivers/char/Kconfig config HVC_DRIVER · line 580

Quoted 5 lines
drivers/char/Kconfig +5 -0
+config XILINX_HWICAP
+	tristate "Xilinx OPB HWICAP Support"
+	depends on XILINX_VIRTEX
+	help
+	This option enables support for Xilinx Internal Configuration Access Port (ICAP) driver.

Line too long.

Quoted 21 lines
drivers/char/Kconfig +0 -0
 config HVC_CONSOLE
 	bool "pSeries Hypervisor Virtual Console support"
drivers/char/Makefile +1 -0
index 07304d5..8cfcbb0 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_EFI_RTC)		+= efirtc.o
 obj-$(CONFIG_SGI_DS1286)	+= ds1286.o
 obj-$(CONFIG_SGI_IP27_RTC)	+= ip27-rtc.o
 obj-$(CONFIG_DS1302)		+= ds1302.o
+obj-$(CONFIG_XILINX_HWICAP)	+= xilinx_hwicap/
 ifeq ($(CONFIG_GENERIC_NVRAM),y)
   obj-$(CONFIG_NVRAM)	+= generic_nvram.o
 else
drivers/char/xilinx_hwicap/Makefile new file +0 -0
new file mode 100644
index 0000000..818f4e1

drivers/char/xilinx_hwicap/Makefile line 7

Quoted 7 lines
drivers/char/xilinx_hwicap/Makefile new file +7 -0
@@ -0,0 +1,7 @@
+#
+# Makefile for the Xilinx OPB hwicap driver
+#
+
+obj-$(CONFIG_XILINX_HWICAP) += xilinx_hwicap_m.o 
+ 
+xilinx_hwicap_m-y := xilinx_hwicap.o xhwicap_srp.o

Those files are both quite small, couldn't you merge them and get rid of the global symbols and the xilinx_hwicap directory?

Quoted 30 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +24 -0
new file mode 100644
index 0000000..388eefe
@@ -0,0 +1,414 @@
+/*****************************************************************************
+ *
+ *     Author: Xilinx, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify it
+ *     under the terms of the GNU General Public License as published by the
+ *     Free Software Foundation; either version 2 of the License, or (at your
+ *     option) any later version.
+ *
+ *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
+ *     AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
+ *     SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,
+ *     OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
+ *     APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
+ *     THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
+ *     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
+ *     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
+ *     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
+ *     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
+ *     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
+ *     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ *     FOR A PARTICULAR PURPOSE.
+ *
+ *     Xilinx products are not intended for use in life support appliances,

drivers/char/xilinx_hwicap/xhwicap_srp.c line 34

Quoted 10 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +10 -0
+ *     devices, or systems. Use in such applications is expressly prohibited.
+ *
+ *     (c) Copyright 2003-2007 Xilinx Inc.
+ *     All rights reserved.
+ *
+ *     You should have received a copy of the GNU General Public License along
+ *     with this program; if not, write to the Free Software Foundation, Inc.,
+ *     675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ****************************************************************************/

Could you please you a smaller / standard GPL header instead?

Quoted 11 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +11 -0
+
+#include "xilinx_hwicap.h"
+
+#define XHI_BUFFER_START 0
+
+/****************************************************************************/
+/**
+ *
+ * Stores data in the storage buffer at the specified address.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.

drivers/char/xilinx_hwicap/xhwicap_srp.c line 55

Quoted 10 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +10 -0
+ *
+ * @param    Address - bram word address
+ *
+ * @param    Data - data to be stored at address
+ *
+ * @return   None.
+ *
+ * @note     None.
+ *
+*****************************************************************************/

Please use std kerneldoc format.

drivers/char/xilinx_hwicap/xhwicap_srp.c line 57

Quoted 2 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +2 -0
+void XHwIcap_StorageBufferWrite(struct xhwicap_drvdata *InstancePtr,
+				u32 Address, u32 Data)

No CamelCase, Uppercase parameters.

Quoted 46 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +46 -0
+{
+	/* Write data to storage buffer. */
+	XHwIcap_mSetBram(InstancePtr->baseAddress, Address, Data);
+}
+
+/****************************************************************************/
+/**
+ *
+ * Read data from the specified address in the storage buffer..
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @param    Address - bram word address
+ *
+ * @return   Data.
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+u32 XHwIcap_StorageBufferRead(struct xhwicap_drvdata *InstancePtr, u32 Address)
+{
+	u32 Data;
+
+	/* Read data from address. Multiply Address by 4 since 4 bytes per
+	 * word.*/
+	Data = XHwIcap_mGetBram(InstancePtr->baseAddress, Address);
+	return Data;
+
+}
+
+/****************************************************************************/
+/**
+ *
+ * Reads bytes from the device (ICAP) and puts it in the storage buffer.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @param    Offset - The storage buffer start address.
+ *
+ * @param    NumInts - The number of words (32 bit) to read from the
+ *           device (ICAP).
+ *
+ *@return    int - 0 or -EBUSY or -EINVAL
+ *
+ * @note     None.
+ *

drivers/char/xilinx_hwicap/xhwicap_srp.c line 113

Quoted 10 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +10 -0
+*****************************************************************************/
+int XHwIcap_DeviceRead(struct xhwicap_drvdata *InstancePtr, u32 Offset,
+		       u32 NumInts)
+{
+
+	s32 Retries = 0;
+
+	if (XHwIcap_mGetDoneReg(InstancePtr->baseAddress) == XHI_NOT_FINISHED) {
+		return -EBUSY;
+	}

No curly brackets around single statement. In general, please run the patch through checkpatch.pl and fixup stuff.

Quoted 403 lines
drivers/char/xilinx_hwicap/xhwicap_srp.c new file +301 -0
+
+	if ((Offset + NumInts) <= XHI_MAX_BUFFER_INTS) {
+		/* setSize NumInts*4 to get bytes. */
+		XHwIcap_mSetSizeReg((InstancePtr->baseAddress), (NumInts << 2));
+		XHwIcap_mSetOffsetReg((InstancePtr->baseAddress), Offset);
+		XHwIcap_mSetRncReg((InstancePtr->baseAddress), XHI_READBACK);
+
+		while (XHwIcap_mGetDoneReg(InstancePtr->baseAddress) ==
+		       XHI_NOT_FINISHED) {
+			Retries++;
+			if (Retries > XHI_MAX_RETRIES) {
+				return -EBUSY;
+			}
+		}
+	} else {
+		return -EINVAL;
+	}
+	return 0;
+
+};
+
+/****************************************************************************/
+/**
+ *
+ * Writes bytes from the storage buffer and puts it in the device (ICAP).
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @param    Offset - The storage buffer start address.
+ *
+ * @param    NumInts - The number of words (32 bit) to read from the
+ *           device (ICAP).
+ *
+ *@return    int - 0 or -EBUSY or -EINVAL
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+int XHwIcap_DeviceWrite(struct xhwicap_drvdata *InstancePtr, u32 Offset,
+			u32 NumInts)
+{
+
+	s32 Retries = 0;
+
+	if (XHwIcap_mGetDoneReg(InstancePtr->baseAddress) == XHI_NOT_FINISHED) {
+		return -EBUSY;
+	}
+
+	if ((Offset + NumInts) <= XHI_MAX_BUFFER_INTS) {
+		/* setSize NumInts*4 to get bytes.  */
+		XHwIcap_mSetSizeReg((InstancePtr->baseAddress), NumInts << 2);
+		XHwIcap_mSetOffsetReg((InstancePtr->baseAddress), Offset);
+		XHwIcap_mSetRncReg((InstancePtr->baseAddress), XHI_CONFIGURE);
+
+		while (XHwIcap_mGetDoneReg(InstancePtr->baseAddress) ==
+		       XHI_NOT_FINISHED) {
+			Retries++;
+			if (Retries > XHI_MAX_RETRIES) {
+				return -EBUSY;
+			}
+		}
+	} else {
+		return -EINVAL;
+	}
+	return 0;
+
+};
+
+/****************************************************************************/
+/**
+ *
+ * Sends a DESYNC command to the ICAP port.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ *@return    int - 0 or -EBUSY or -EINVAL
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+int XHwIcap_CommandDesync(struct xhwicap_drvdata *InstancePtr)
+{
+	int status;
+
+	XHwIcap_StorageBufferWrite(InstancePtr, 0,
+				   (XHwIcap_Type1Write(XHI_CMD) | 1));
+	XHwIcap_StorageBufferWrite(InstancePtr, 1, XHI_CMD_DESYNCH);
+	XHwIcap_StorageBufferWrite(InstancePtr, 2, XHI_NOOP_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 3, XHI_NOOP_PACKET);
+
+	/* send four words */
+	status = XHwIcap_DeviceWrite(InstancePtr, 0, 4);
+	if (status) {
+		return status;
+	}
+
+	return 0;
+}
+
+/****************************************************************************/
+/**
+ *
+ * Sends a CAPTURE command to the ICAP port.  This command caputres all
+ * of the flip flop states so they will be available during readback.
+ * One can use this command instead of enabling the CAPTURE block in the
+ * design.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @return    int - 0 or -EBUSY or -EINVAL
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+int XHwIcap_CommandCapture(struct xhwicap_drvdata *InstancePtr)
+{
+	int status;
+
+	/* DUMMY and SYNC */
+	XHwIcap_StorageBufferWrite(InstancePtr, 0, XHI_DUMMY_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 1, XHI_SYNC_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 2,
+				   (XHwIcap_Type1Write(XHI_CMD) | 1));
+	XHwIcap_StorageBufferWrite(InstancePtr, 3, XHI_CMD_GCAPTURE);
+	XHwIcap_StorageBufferWrite(InstancePtr, 4, XHI_DUMMY_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 5, XHI_DUMMY_PACKET);
+
+	/* send six words */
+	status = XHwIcap_DeviceWrite(InstancePtr, 0, 6);
+	if (status) {		/* send six words */
+		return status;
+	}
+
+	return 0;
+}
+
+/****************************************************************************/
+/**
+ *
+ * This function returns the value of the specified configuration
+ * register.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked
+ * on.
+ *
+ * @param    ConfigReg  - A constant which represents the configuration
+ * register value to be returned. Constants specified in xhwicap_i.h.  Examples:
+ * XHI_IDCODE, XHI_FLR.
+ *
+ * @return   The value of the specified configuration register.
+ *
+ *
+*****************************************************************************/
+
+u32 XHwIcap_GetConfigReg(struct xhwicap_drvdata *InstancePtr, u32 ConfigReg)
+{
+	u32 Packet;
+	int status;
+
+	/* Write bitstream to bram */
+	Packet = XHwIcap_Type1Read(ConfigReg) | 1;
+	XHwIcap_StorageBufferWrite(InstancePtr, 0, XHI_DUMMY_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 1, XHI_SYNC_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 2, Packet);
+	XHwIcap_StorageBufferWrite(InstancePtr, 3, XHI_NOOP_PACKET);
+	XHwIcap_StorageBufferWrite(InstancePtr, 4, XHI_NOOP_PACKET);
+
+	/* Transfer Bitstream from Bram to ICAP */
+	status = XHwIcap_DeviceWrite(InstancePtr, 0, 5);
+	if (status) {
+		return status;
+	}
+
+	/* Now readback one word into bram position
+	 * XHI_EX_BITSTREAM_LENGTH*/
+	status = XHwIcap_DeviceRead(InstancePtr, 5, 1);
+	if (status) {
+		return status;
+	}
+
+	/* Return the Register value */
+	return XHwIcap_StorageBufferRead(InstancePtr, 5);
+}
+
+/****************************************************************************
+ *
+ * Loads a partial bitstream from system memory.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @param    Data - Address of the data representing the partial bitstream
+ *
+ * @param    Size - the size of the partial bitstream in 32 bit words.
+ *
+ * @return   0, -EFBIG or -EINVAL.
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+int XHwIcap_SetConfiguration(struct xhwicap_drvdata *InstancePtr, u32 *Data,
+			     u32 Size)
+{
+	int status;
+	s32 BufferCount = 0;
+	s32 NumWrites = 0;
+	bool Dirty = 0;
+	u32 I;
+
+	/* Loop through all the data */
+	for (I = 0, BufferCount = 0; I < Size; I++) {
+
+		/* Copy data to bram */
+		XHwIcap_StorageBufferWrite(InstancePtr, BufferCount, Data[I]);
+		Dirty = 1;
+
+		if (BufferCount == XHI_MAX_BUFFER_INTS - 1) {
+			/* Write data to ICAP */
+			status = XHwIcap_DeviceWrite(InstancePtr, XHI_BUFFER_START,
+						XHI_MAX_BUFFER_INTS);
+			if (status != 0) {
+				/* abort. */
+				XHwIcap_mReset(InstancePtr->baseAddress);					return status;
+			}
+
+			BufferCount = 0;
+			NumWrites++;
+			Dirty = 0;
+		} else {
+			BufferCount++;
+		}
+	}
+
+	/* Write unwritten data to ICAP */
+	if (Dirty) {
+		/* Write data to ICAP */
+		status = XHwIcap_DeviceWrite(InstancePtr, XHI_BUFFER_START,
+					     BufferCount);
+		if (status != 0) {
+			/* abort. */
+			XHwIcap_mReset(InstancePtr->baseAddress);
+		}
+		return status;
+	}
+
+	return 0;
+};
+
+/****************************************************************************
+ *
+ * Reads Configuration Data from the device.
+ *
+ * @param    InstancePtr - a pointer to the XHwIcap instance to be worked on.
+ *
+ * @param    Data - Address of the data representing the partial bitstream
+ *
+ * @param    Size - the size of the partial bitstream in 32 bit words.
+ *
+ * @return   0, -EFBIG or -EINVAL.
+ *
+ * @note     None.
+ *
+*****************************************************************************/
+int XHwIcap_GetConfiguration(struct xhwicap_drvdata *InstancePtr, u32 *Data,
+			     u32 Size)
+{
+	int status;
+	s32 BufferCount = 0;
+	s32 NumReads = 0;
+	u32 I;
+
+	/* Loop through all the data */
+	for (I = 0, BufferCount = XHI_MAX_BUFFER_INTS; I < Size; I++) {
+		if (BufferCount == XHI_MAX_BUFFER_INTS) {
+			u32 intsRemaining = Size - I;
+			u32 intsToRead =
+			    intsRemaining <
+			    XHI_MAX_BUFFER_INTS ? intsRemaining :
+			    XHI_MAX_BUFFER_INTS;
+
+			/* Read data from ICAP */
+
+			status =
+			    XHwIcap_DeviceRead(InstancePtr, XHI_BUFFER_START,
+					       intsToRead);
+			if (status != 0) {
+				/* abort. */
+				XHwIcap_mReset(InstancePtr->baseAddress);
+				return status;
+			}
+
+			BufferCount = 0;
+			NumReads++;
+		}
+
+		/* Copy data from bram */
+		Data[I] = XHwIcap_StorageBufferRead(InstancePtr, BufferCount);
+		BufferCount++;
+	}
+
+	return 0;
+};
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +96 -0
new file mode 100644
index 0000000..d42538e
@@ -0,0 +1,565 @@
+/*****************************************************************************
+ *
+ *     Author: Xilinx, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify it
+ *     under the terms of the GNU General Public License as published by the
+ *     Free Software Foundation; either version 2 of the License, or (at your
+ *     option) any later version.
+ *
+ *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
+ *     AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
+ *     SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,
+ *     OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
+ *     APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
+ *     THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
+ *     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
+ *     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
+ *     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
+ *     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
+ *     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
+ *     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ *     FOR A PARTICULAR PURPOSE.
+ *
+ *     Xilinx products are not intended for use in life support appliances,
+ *     devices, or systems. Use in such applications is expressly prohibited.
+ *
+ *     (c) Copyright 2002 Xilinx Inc., Systems Engineering Group
+ *     (c) Copyright 2004 Xilinx Inc., Systems Engineering Group
+ *     (c) Copyright 2007 Xilinx Inc.
+ *     All rights reserved.
+ *
+ *     You should have received a copy of the GNU General Public License along
+ *     with this program; if not, write to the Free Software Foundation, Inc.,
+ *     675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *****************************************************************************/
+
+/*
+ * xilinx_hwicap.c
+ *
+ * This is the code behind /dev/xilinx_icap/'x' -- it allows a user-space
+ * application to use the Xilinx ICAP subsystem.
+ *
+ * A /dev/xilinx_icap/'x' device node represents an arbitrary device
+ * on port 'x'.  The following operations are possible:
+ *
+ * open		do nothing, set up default IEEE 1284 protocol to be COMPAT
+ * release	release port and unregister device (if necessary)
+ * write        Write a bitstream to the configuration processor.
+ * read         Read a data stream from the configuration processor.
+ *
+ * Note that in order to use the read interface, it is first necessary
+ * to write a request packet to the write interface.  i.e., it is not
+ * possible to simply readback the bitstream (or any configuration
+ * bits) from a device without specifically requesting them first.
+ * The code to craft such packets is intended to be part of the
+ * user-space application code that uses this device.  The simplest
+ * way to use this interface is simply:
+ *
+ * cp foo.bit /dev/xilinx_icap
+ *
+ * Note that unless foo.bit is an appropriately constructed partial
+ * bitstream, this has a high likelyhood of overwriting the design
+ * currently programmed in the FPGA.
+ */
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/fcntl.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
+#include <linux/sysctl.h>
+#include <linux/version.h>
+#include <linux/fs.h>
+#include <linux/cdev.h>
+#include <linux/platform_device.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+
+#ifdef CONFIG_OF
+/* For open firmware. */
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#endif
+
+#include "xilinx_hwicap.h"
+
+#define DRIVER_NAME "xilinx_icap"

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 106

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+
+#define XHWICAP_REGS   (0x10000)
+
+/* dynamically allocate device number */
+static int xhwicap_major = 0;
+static int xhwicap_minor = 0;
+static int xhwicap_no_minors = 4;
+module_param(xhwicap_major, int, S_IRUGO);
+module_param(xhwicap_minor, int, S_IRUGO);
+module_param(xhwicap_no_minors, int, S_IRUGO);

Why don't you request official major/minor numbers? (Documentation/devices.txt)

Quoted 363 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +363 -0
+
+static struct class *icap_class;
+
+int xhwicap_initialize_xhwicap(struct xhwicap_drvdata *drvdata)
+{
+
+	u32 DeviceIdCode;
+	u32 Packet;
+	int Status;
+
+	dev_dbg(drvdata->dev, "Reset...\n");
+
+	/* Abort any current transaction, to make sure we have the ICAP in */
+	/* a good state. */
+	XHwIcap_mReset(drvdata->baseAddress);
+
+	/* Read the IDCODE from ICAP if specified. */
+	{
+		dev_dbg(drvdata->dev, "Reading IDCODE...\n");
+
+		/* Write bitstream to bram */
+		Packet = XHwIcap_Type1Read(XHI_IDCODE) | 1;
+		XHwIcap_StorageBufferWrite(drvdata, 0, XHI_DUMMY_PACKET);
+		XHwIcap_StorageBufferWrite(drvdata, 1, XHI_SYNC_PACKET);
+		XHwIcap_StorageBufferWrite(drvdata, 2, Packet);
+		XHwIcap_StorageBufferWrite(drvdata, 3, XHI_NOOP_PACKET);
+		XHwIcap_StorageBufferWrite(drvdata, 4, XHI_NOOP_PACKET);
+
+		/* Transfer Bitstream from Bram to ICAP */
+		Status = XHwIcap_DeviceWrite(drvdata, 0, 5);
+		if (Status) {
+			return Status;
+		}
+
+		/* Now readback one word into bram position
+		 * XHI_EX_BITSTREAM_LENGTH*/
+		Status = XHwIcap_DeviceRead(drvdata, 5, 1);
+		if (Status) {
+			return Status;
+		}
+
+		/* Return the Register value */
+		DeviceIdCode = XHwIcap_StorageBufferRead(drvdata, 5);
+
+		/* Mask out the version section of the DeviceIdCode */
+		DeviceIdCode = DeviceIdCode & 0x0FFFFFFF;
+
+		dev_dbg(drvdata->dev, "Desync...\n");
+		Status = XHwIcap_CommandDesync(drvdata);
+
+		if (Status) {
+			return Status;
+		}
+	}
+
+	/* Abort any current transaction, to make sure we have the ICAP in */
+	/* a good state. */
+	XHwIcap_mReset(drvdata->baseAddress);
+
+	dev_info(drvdata->dev, "Device IDCODE = %x\n", DeviceIdCode);
+
+	return 0;
+}
+
+static ssize_t
+xhwicap_read(struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+	struct xhwicap_drvdata *drvdata = file->private_data;
+	ssize_t bytes_to_read = 0;
+	u32 *kbuf;
+	u32 words;
+	u32 bytes_remaining;
+	int Status;
+
+	if (drvdata->read_buffer_in_use) {
+		/* If there are leftover bytes in the buffer, just */
+		/* return them and don't try to read more from the */
+		/* ICAP device. */
+		bytes_to_read =
+		    (count <
+		     drvdata->read_buffer_in_use) ? count : drvdata->
+		    read_buffer_in_use;
+
+		/* Return the data currently in the read buffer. */
+		if (copy_to_user(buf, drvdata->read_buffer, bytes_to_read)) {
+			return -EFAULT;
+		}
+		drvdata->read_buffer_in_use -= bytes_to_read;
+		memcpy(drvdata->read_buffer + bytes_to_read,
+		       drvdata->read_buffer, 4 - bytes_to_read);
+	} else {
+		/* Get new data from the ICAP, and return was was requested. */
+		kbuf = (u32 *) get_zeroed_page(GFP_KERNEL);
+		if (!kbuf)
+			return -ENOMEM;
+
+		/* The ICAP device is only able to read complete */
+		/* words.  If a number of bytes that do not correspond */
+		/* to complete words is requested, then we read enough */
+		/* words to get the required number of bytes, and then */
+		/* save the remaining bytes for the next read. */
+
+		/* Determine the number of words to read, rounding up */
+		/* if necessary. */
+		words = ((count + 3) >> 2);
+		bytes_to_read = words << 2;
+
+		if (bytes_to_read > PAGE_SIZE) {
+			bytes_to_read = PAGE_SIZE;
+		}
+		/* Ensure we only read a complete number of words. */
+		/* BUG: should be count & 3? */
+		bytes_remaining = bytes_to_read & 3;
+		bytes_to_read &= ~3;
+		words = bytes_to_read >> 2;
+
+		Status = XHwIcap_GetConfiguration(drvdata, kbuf, words);
+		/* If we didn't read correctly, then bail out. */
+		if (Status) {
+			free_page((unsigned long)kbuf);
+			return -EFAULT;
+		}
+		/* If we fail to return the data to the user, then bail out. */
+		if (copy_to_user(buf, kbuf, bytes_to_read)) {
+			free_page((unsigned long)kbuf);
+			return -EFAULT;
+		}
+		memcpy(kbuf, drvdata->read_buffer, bytes_remaining);
+		drvdata->read_buffer_in_use = bytes_remaining;
+		free_page((unsigned long)kbuf);
+	}
+	return bytes_to_read;
+}
+
+static ssize_t xhwicap_write(struct file *file, const char *buf,
+			     size_t count, loff_t *ppos)
+{
+	struct xhwicap_drvdata *drvdata = file->private_data;
+	ssize_t written = 0;
+	ssize_t left = count;
+	u32 *kbuf;
+	int len;
+	int Status;
+
+	left += drvdata->write_buffer_in_use;
+
+	/* only write multiples of 4 bytes. */
+	if (left < 4)
+		return 0;
+
+	kbuf = (u32 *) __get_free_page(GFP_KERNEL);
+	if (!kbuf)
+		return -ENOMEM;
+
+	while (left > 3) {
+		/* only write multiples of 4 bytes, so there might */
+		/* be as many as 3 bytes left (at the end). */
+		len = left;
+
+		if (len > PAGE_SIZE)
+			len = PAGE_SIZE;
+		len &= ~3;
+
+		if (drvdata->write_buffer_in_use) {
+			memcpy(kbuf, drvdata->write_buffer,
+			       drvdata->write_buffer_in_use);
+			if (copy_from_user
+			    ((((char *)kbuf) + (drvdata->write_buffer_in_use)),
+			     buf + written,
+			     len - (drvdata->write_buffer_in_use))) {
+				free_page((unsigned long)kbuf);
+				return -EFAULT;
+			}
+		} else {
+			if (copy_from_user(kbuf, buf + written, len)) {
+				free_page((unsigned long)kbuf);
+				return -EFAULT;
+			}
+		}
+
+		Status = XHwIcap_SetConfiguration(drvdata, kbuf, len >> 2);
+
+		if (Status) {
+			free_page((unsigned long)kbuf);
+			return -EFAULT;
+		}
+		if (drvdata->write_buffer_in_use) {
+			len -= drvdata->write_buffer_in_use;
+			left -= drvdata->write_buffer_in_use;
+			drvdata->write_buffer_in_use = 0;
+		}
+		written += len;
+		left -= len;
+	}
+	if ((left > 0) && (left < 4)) {
+		if (!copy_from_user(drvdata->write_buffer, buf + written, left)) {
+			drvdata->write_buffer_in_use = left;
+			written += left;
+			left = 0;
+		}
+	}
+
+	free_page((unsigned long)kbuf);
+	return written;
+}
+
+static int xhwicap_open(struct inode *inode, struct file *file)
+{
+	struct xhwicap_drvdata *drvdata;
+	int status;
+
+	drvdata = container_of(inode->i_cdev, struct xhwicap_drvdata, cdev);
+
+	status = xhwicap_initialize_xhwicap(drvdata);
+	if (status) {
+		dev_err(drvdata->dev, "Failed to open file");
+		return -status;
+	}
+
+	drvdata->flags = 0;
+	file->private_data = drvdata;
+	drvdata->write_buffer_in_use = 0;
+	drvdata->read_buffer_in_use = 0;
+
+	return 0;
+}
+
+static int xhwicap_release(struct inode *inode, struct file *file)
+{
+	struct xhwicap_drvdata *drvdata = file->private_data;
+	int i;
+	int Status;
+
+	if (drvdata->write_buffer_in_use) {
+		/* Flush write buffer. */
+		for (i = drvdata->write_buffer_in_use; i < 4; i++) {
+			drvdata->write_buffer[i] = 0;
+		}
+		Status =
+		    XHwIcap_SetConfiguration(drvdata,
+					     (u32 *) drvdata->write_buffer, 1);
+		if (Status) {
+			return Status;
+		}
+	}
+
+	Status = XHwIcap_CommandDesync(drvdata);
+	if (Status) {
+		return Status;
+	}
+
+	return 0;
+}
+
+static struct file_operations xhwicap_fops = {
+	.owner = THIS_MODULE,
+	.write = xhwicap_write,
+	.read = xhwicap_read,
+	.open = xhwicap_open,
+	.release = xhwicap_release,
+};
+
+static int __init xhwicap_drv_probe(struct device *dev)
+{
+	dev_t devt;
+	struct platform_device *pdev = to_platform_device(dev);
+	struct xhwicap_drvdata *drvdata = NULL;
+	struct resource *regs_res;
+	int retval = 0;
+
+	if (!dev) {
+		return -EINVAL;
+	}
+
+	dev_info(dev, "Xilinx icap port driver\n");
+
+	devt = MKDEV(xhwicap_major, xhwicap_minor + pdev->id);
+
+	drvdata = kmalloc(sizeof(struct xhwicap_drvdata), GFP_KERNEL);
+	if (!drvdata) {
+		dev_err(dev, "Couldn't allocate device private record\n");
+		return -ENOMEM;
+	}
+	memset((void *)drvdata, 0, sizeof(struct xhwicap_drvdata));
+	dev_set_drvdata(dev, (void *)drvdata);
+
+	/* Map the control registers in */
+	regs_res = platform_get_resource(to_platform_device(dev),
+					 IORESOURCE_MEM, 0);
+	if (!regs_res) {
+		dev_err(dev, "Couldn't get registers resource\n");
+		retval = -EFAULT;
+		goto failed1;
+	}
+
+	drvdata->mem_start = regs_res->start;
+	drvdata->mem_end = regs_res->end;
+	drvdata->mem_size = regs_res->end - regs_res->start + 1;
+
+	if (drvdata->mem_size < XHWICAP_REGS) {
+		dev_err(dev, "Couldn't get registers resource\n");
+		retval = -EFAULT;
+		goto failed1;
+	}
+
+	if (!request_mem_region(drvdata->mem_start, drvdata->mem_size, DRIVER_NAME)) {
+		dev_err(dev, "Couldn't lock memory region at %p\n",
+			(void *)regs_res->start);
+		retval = -EBUSY;
+		goto failed1;
+	}
+
+	drvdata->devt = devt;
+	drvdata->dev = dev;
+	drvdata->baseAddress = ioremap(drvdata->mem_start, drvdata->mem_size);
+	if (!drvdata->baseAddress) {
+		dev_err(dev, "ioremap() failed\n");
+		goto failed2;
+	}
+
+	dev_info(dev, "ioremap %lx to %p with size %x\n",
+		 (unsigned long int)drvdata->mem_start,
+			drvdata->baseAddress, drvdata->mem_size);
+
+	cdev_init(&drvdata->cdev, &xhwicap_fops);
+	drvdata->cdev.owner = THIS_MODULE;
+	retval = cdev_add(&drvdata->cdev, devt, 1);
+	if (retval) {
+		dev_err(dev, "cdev_add() failed\n");
+		goto failed3;
+	}
+	/*  devfs_mk_cdev(devt, S_IFCHR|S_IRUGO|S_IWUGO, DRIVER_NAME); */
+	class_device_create(icap_class, NULL, devt, NULL, DRIVER_NAME);
+	return 0;		/* success */
+
+ failed3:
+	iounmap(drvdata->baseAddress);
+
+ failed2:
+	release_mem_region(regs_res->start, drvdata->mem_size);
+
+ failed1:
+	kfree(drvdata);
+
+	return retval;
+}
+
+static int __exit xhwicap_drv_remove(struct device *dev)
+{
+	struct xhwicap_drvdata *drvdata;
+
+	if (!dev)
+		return -EINVAL;
+
+	drvdata = (struct xhwicap_drvdata *)dev_get_drvdata(dev);
+
+	class_device_destroy(icap_class, drvdata->devt);
+	cdev_del(&drvdata->cdev);
+	iounmap(drvdata->baseAddress);
+	release_mem_region(drvdata->mem_start, drvdata->mem_size);
+	kfree(drvdata);
+	dev_set_drvdata(dev, NULL);
+

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 479

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+	return 0;		/* success */
+}
+
+static struct device_driver xhwicap_module_driver = {
+	.name = DRIVER_NAME,
+	.bus = &platform_bus_type,
+
+	.probe = xhwicap_drv_probe,
+	.remove = xhwicap_drv_remove,
+};

Please use struct platform_driver instead.

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 486

Quoted 7 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +7 -0
+
+static int __init xhwicap_module_init(void)
+{
+	dev_t devt;
+	int retval;
+
+	icap_class = class_create(THIS_MODULE, "xilinx_config");

What's that for?

Quoted 146 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +79 -0
+
+	if (xhwicap_major) {
+		devt = MKDEV(xhwicap_major, xhwicap_minor);
+		retval = register_chrdev_region(devt, xhwicap_no_minors,
+						DRIVER_NAME);
+	} else {
+		retval =
+		    alloc_chrdev_region(&devt, xhwicap_minor, xhwicap_no_minors,
+					DRIVER_NAME);
+		xhwicap_major = MAJOR(devt);
+	}
+	if (retval < 0) {
+		xhwicap_major = 0;
+		return retval;
+	}
+
+	retval = driver_register(&xhwicap_module_driver);
+
+	if (retval) {
+		unregister_chrdev_region(devt, xhwicap_no_minors);
+	}
+
+	return retval;
+}
+
+static void __exit xhwicap_module_cleanup(void)
+{
+	dev_t devt = MKDEV(xhwicap_major, xhwicap_minor);
+
+	class_destroy(icap_class);
+
+	driver_unregister(&xhwicap_module_driver);
+
+	unregister_chrdev_region(devt, xhwicap_no_minors);
+}
+
+module_init(xhwicap_module_init);
+module_exit(xhwicap_module_cleanup);
+
+#ifdef CONFIG_OF
+
+static int __init xilinx_hwicap_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *pdev;
+	int ret;
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, NULL, "xlnx,opb-hwicap")) != NULL;
+	     i++) {
+		struct resource r;
+
+		memset(&r, 0, sizeof(r));
+
+		ret = of_address_to_resource(np, 0, &r);
+		if (ret)
+			goto err;
+		pdev =
+		    platform_device_register_simple(DRIVER_NAME, i, &r, 1);
+
+		if (IS_ERR(pdev)) {
+			ret = PTR_ERR(pdev);
+			goto err;
+		}
+	}
+
+	return 0;
+err:
+	return ret;
+}
+
+module_init(xilinx_hwicap_of_init);
+
+#endif
+
+MODULE_AUTHOR("Xilinx, Inc; Xilinx Research Labs Group");
+MODULE_DESCRIPTION("Xilinx ICAP Port Driver");
+MODULE_LICENSE("GPL");
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +61 -0
new file mode 100644
index 0000000..80e3fe0
@@ -0,0 +1,539 @@
+/*****************************************************************************
+ *
+ *     Author: Xilinx, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify it
+ *     under the terms of the GNU General Public License as published by the
+ *     Free Software Foundation; either version 2 of the License, or (at your
+ *     option) any later version.
+ *
+ *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
+ *     AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
+ *     SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,
+ *     OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
+ *     APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
+ *     THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
+ *     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
+ *     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
+ *     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
+ *     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
+ *     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
+ *     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ *     FOR A PARTICULAR PURPOSE.
+ *
+ *     Xilinx products are not intended for use in life support appliances,
+ *     devices, or systems. Use in such applications is expressly prohibited.
+ *
+ *     (c) Copyright 2003-2007 Xilinx Inc.
+ *     All rights reserved.
+ *
+ *     You should have received a copy of the GNU General Public License along
+ *     with this program; if not, write to the Free Software Foundation, Inc.,
+ *     675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *****************************************************************************/
+
+#ifndef XILINX_HWICAP_H_	/* prevent circular inclusions */
+#define XILINX_HWICAP_H_	/* by using protection macros */
+
+#include <linux/types.h>
+#include <linux/cdev.h>
+#include <linux/version.h>
+#include <linux/platform_device.h>
+
+#include <asm/io.h>
+
+struct xhwicap_drvdata {
+	u32 flags;
+	u32 write_buffer_in_use;  /* Always in [0,3] */
+	u8 write_buffer[4];
+	u32 read_buffer_in_use;	  /* Always in [0,3] */
+	u8 read_buffer[4];
+	u32 mem_start;		  /* phys. address of the control registers */
+	u32 mem_end;		  /* phys. address of the control registers */
+	u32 mem_size;
+	void __iomem *baseAddress;/* virt. address of the control registers */
+
+	struct device *dev;
+	struct cdev cdev;	/* Char device structure */
+	dev_t devt;
+};
+

drivers/char/xilinx_hwicap/xilinx_hwicap.h line 71

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +10 -0
+/***************************** Include Files ********************************/
+
+#define virtex2 0
+#define virtex4 1
+
+#ifdef CONFIG_XILINX_VIRTEX_4_FX
+#define XHI_FAMILY virtex4
+#else
+#define XHI_FAMILY virtex2
+#endif

So having a single kernel with v2p/v4 support is not an option?

Quoted 195 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +195 -0
+
+/************************** Constant Definitions ****************************/
+
+#define XHI_PAD_FRAMES              0x1
+
+/* Mask for calculating configuration packet headers */
+#define XHI_WORD_COUNT_MASK_TYPE_1  0x7FFUL
+#define XHI_WORD_COUNT_MASK_TYPE_2  0x1FFFFFUL
+#define XHI_TYPE_MASK               0x7
+#define XHI_REGISTER_MASK           0xF
+#define XHI_OP_MASK                 0x3
+
+#define XHI_TYPE_SHIFT              29
+#define XHI_REGISTER_SHIFT          13
+#define XHI_OP_SHIFT                27
+
+#define XHI_TYPE_1                  1
+#define XHI_TYPE_2                  2
+#define XHI_OP_WRITE                2
+#define XHI_OP_READ                 1
+
+/* Address Block Types */
+#define XHI_FAR_CLB_BLOCK           0
+#define XHI_FAR_BRAM_BLOCK          1
+#define XHI_FAR_BRAM_INT_BLOCK      2
+
+/* Addresses of the Configuration Registers */
+#define XHI_CRC                     0
+#define XHI_FAR                     1
+#define XHI_FDRI                    2
+#define XHI_FDRO                    3
+#define XHI_CMD                     4
+#define XHI_CTL                     5
+#define XHI_MASK                    6
+#define XHI_STAT                    7
+#define XHI_LOUT                    8
+#define XHI_COR                     9
+#define XHI_MFWR                    10
+
+#if XHI_FAMILY == virtex4
+
+#define XHI_CBC                     11
+#define XHI_IDCODE                  12
+#define XHI_AXSS                    13
+#define XHI_NUM_REGISTERS           14
+
+#else
+
+#define XHI_FLR                     11
+#define XHI_KEY                     12
+#define XHI_CBC                     13
+#define XHI_IDCODE                  14
+#define XHI_NUM_REGISTERS           15
+
+#endif
+
+/* Configuration Commands */
+#define XHI_CMD_NULL                0
+#define XHI_CMD_WCFG                1
+#define XHI_CMD_MFW                 2
+#define XHI_CMD_DGHIGH              3
+#define XHI_CMD_RCFG                4
+#define XHI_CMD_START               5
+#define XHI_CMD_RCAP                6
+#define XHI_CMD_RCRC                7
+#define XHI_CMD_AGHIGH              8
+#define XHI_CMD_SWITCH              9
+#define XHI_CMD_GRESTORE            10
+#define XHI_CMD_SHUTDOWN            11
+#define XHI_CMD_GCAPTURE            12
+#define XHI_CMD_DESYNCH             13
+
+/* Packet constants */
+#define XHI_SYNC_PACKET             0xAA995566UL
+#define XHI_DUMMY_PACKET            0xFFFFFFFFUL
+#define XHI_NOOP_PACKET             (XHI_TYPE_1 << XHI_TYPE_SHIFT)
+#define XHI_TYPE_2_READ ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
+			(XHI_OP_READ << XHI_OP_SHIFT))
+
+#define XHI_TYPE_2_WRITE ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
+			(XHI_OP_WRITE << XHI_OP_SHIFT))
+
+#define XHI_TYPE2_CNT_MASK          0x07FFFFFF
+
+#define XHI_TYPE_1_PACKET_MAX_WORDS 2047UL
+#define XHI_TYPE_1_HEADER_BYTES     4
+#define XHI_TYPE_2_HEADER_BYTES     8
+
+/* Indicates how many bytes will fit in a buffer. (1 BRAM) */
+#define XHI_MAX_BUFFER_BYTES        2048
+#define XHI_MAX_BUFFER_INTS         512
+
+/* Number of frames in different tile types */
+#if XHI_FAMILY == virtex4
+
+#define XHI_GCLK_FRAMES             3
+#define XHI_IOB_FRAMES              30
+#define XHI_DSP_FRAMES              21
+#define XHI_CLB_FRAMES              22
+#define XHI_BRAM_FRAMES             64
+#define XHI_BRAM_INT_FRAMES         20
+
+#else
+
+#define XHI_GCLK_FRAMES             4
+#define XHI_IOB_FRAMES              4
+#define XHI_IOI_FRAMES              22
+#define XHI_CLB_FRAMES              22
+#define XHI_BRAM_FRAMES             64
+#define XHI_BRAM_INT_FRAMES         22
+
+#endif
+
+/* Device Resources */
+#define CLB                         0
+#define DSP                         1
+#define BRAM                        2
+#define BRAM_INT                    3
+#define IOB                         4
+#define IOI                         5
+#define CLK                         6
+#define MGT                         7
+
+#define BLOCKTYPE0                  0
+#define BLOCKTYPE1                  1
+#define BLOCKTYPE2                  2
+
+/* The number of words reserved for the header in the storage buffer. */
+/* MAY CHANGE FOR V4 */
+#define XHI_HEADER_BUFFER_WORDS     20
+#define XHI_HEADER_BUFFER_BYTES     (XHI_HEADER_BUFFER_WORDS << 2)
+
+/* CLB major frames start at 3 for the first column (since we are using
+ * column numbers that start at 1, when the column is added to this offset,
+ * that first one will be 3 as required. */
+#define XHI_CLB_MAJOR_FRAME_OFFSET  2
+
+/* File access and error constants */
+#define XHI_DEVICE_READ_ERROR       -1
+#define XHI_DEVICE_WRITE_ERROR      -2
+#define XHI_BUFFER_OVERFLOW_ERROR   -3
+
+#define XHI_DEVICE_READ             0x1
+#define XHI_DEVICE_WRITE            0x0
+
+/* Constants for checking transfer status */
+#define XHI_CYCLE_DONE              0
+#define XHI_CYCLE_EXECUTING         1
+
+/* Constant to use for CRC check when CRC has been disabled */
+#define XHI_DISABLED_AUTO_CRC       0x0000DEFCUL
+
+/* Major Row Offset */
+#define XHI_CLB_MAJOR_ROW_OFFSET 96+(32*XHI_HEADER_BUFFER_WORDS)-1
+
+/* Number of times to poll the done regsiter */
+#define XHI_MAX_RETRIES     1000
+
+/************************** Constant Definitions ****************************/
+
+/* XHwIcap register offsets */
+
+/* Size of transfer, read & write */
+#define XHI_SIZE_REG_OFFSET        0x800L
+/* Offset into bram, read & write */
+#define XHI_BRAM_OFFSET_REG_OFFSET 0x804L
+/* Read not Configure, direction of transfer.  Write only */
+#define XHI_RNC_REG_OFFSET         0x808L
+/* Indicates transfer complete. Read only */
+#define XHI_STATUS_REG_OFFSET      0x80CL
+
+/* Constants for setting the RNC register */
+#define XHI_CONFIGURE              0x0UL
+#define XHI_READBACK               0x1UL
+
+/* Constants for the Done register */
+#define XHI_NOT_FINISHED           0x0UL
+#define XHI_FINISHED               0x1UL
+
+/**************************** Type Definitions ******************************/
+
+/***************** Macros (Inline Functions) Definitions ********************/
+
+/****************************************************************************/
+/**
+*
+* Get the contents of the size register.
+*
+* The size register holds the number of 32 bit words to transfer between
+* bram and the icap (or icap to bram).
+*
+* @param    BaseAddress is the  base address of the device
+*
+* @return   A 32-bit value representing the contents of the size
+* register.

drivers/char/xilinx_hwicap/xilinx_hwicap.h line 276

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +10 -0
+*
+* @note
+*
+* u32 XHwIcap_mGetSizeReg(u32 BaseAddress);
+*
+*****************************************************************************/
+#define XHwIcap_mGetSizeReg(BaseAddress) \
+    (in_be32((u32 *)((BaseAddress) + XHI_SIZE_REG_OFFSET)))
+
+/****************************************************************************/

Why not a single getter with a offset/register parameter instead of all these? And use inline functions instead of macros.

Quoted 266 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +263 -0
+/**
+*
+* Get the contents of the bram offset register.
+*
+* The bram offset register holds the starting bram address to transfer
+* data from during configuration or write data to during readback.
+*
+* @param    BaseAddress is the  base address of the device
+*
+* @return   A 32-bit value representing the contents of the bram offset
+* register.
+*
+* @note
+*
+* u32 XHwIcap_mGetOffsetReg(u32 BaseAddress);
+*
+*****************************************************************************/
+#define XHwIcap_mGetOffsetReg(BaseAddress) \
+    (in_be32((u32 *)((BaseAddress + XHI_BRAM_OFFSET_REG_OFFSET))))
+
+/****************************************************************************/
+/**
+*
+* Get the contents of the done register.
+*
+* The done register is set to zero during configuration or readback.
+* When the current configuration or readback completes the done register
+* is set to one.
+*
+* @param    BaseAddress is the base address of the device
+*
+* @return   A 32-bit value with bit 1 representing done or not
+*
+* @note
+*
+* u32 XHwIcap_mGetDoneReg(u32 BaseAddress);
+*
+*****************************************************************************/
+
+#define XHwIcap_mGetDoneReg(BaseAddress) \
+    (in_be32((u32 *)((BaseAddress + XHI_STATUS_REG_OFFSET))) & 1)
+
+/****************************************************************************/
+/**
+*
+* Get the contents of the status register.
+*
+* The status register contains the ICAP status and the done bit.
+*
+* D8 - cfgerr
+* D7 - dalign
+* D6 - rip
+* D5 - in_abort_l
+* D4 - Always 1
+* D3 - Always 1
+* D2 - Always 1
+* D1 - Always 1
+* D0 - Done bit
+*
+* @param    BaseAddress is the base address of the device
+*
+* @return   A 32-bit value representing the contents of the status register
+*
+* @note
+*
+* u32 XHwIcap_mGetStatusReg(u32 BaseAddress);
+*
+*****************************************************************************/
+
+#define XHwIcap_mGetStatusReg(BaseAddress) \
+    (in_be32((u32 *)((BaseAddress + XHI_STATUS_REG_OFFSET))))
+
+#define XHwIcap_mReset(BaseAddress) \
+    (out_be32((u32 *)((BaseAddress + XHI_STATUS_REG_OFFSET)), 0xFEFE))
+
+/****************************************************************************/
+/**
+* Reads data from the storage buffer bram.
+*
+* A bram is used as a configuration memory cache.  One frame of data can
+* be stored in this "storage buffer".
+*
+* @param    BaseAddress - contains the base address of the component.
+*
+* @param    Offset - The offset into which the data should be read.
+*
+* @return   The value of the specified offset in the bram.
+*
+* @note
+*
+* u32 XHwIcap_mGetBram(u32 BaseAddress, u32 Offset);
+*
+*****************************************************************************/
+#define XHwIcap_mGetBram(BaseAddress, Offset) \
+    (in_be32((u32 *)((BaseAddress+(Offset<<2)))))
+
+/****************************************************************************/
+/**
+* Set the size register.
+*
+* The size register holds the number of 8 bit bytes to transfer between
+* bram and the icap (or icap to bram).
+*
+* @param    BaseAddress - contains the base address of the device.
+*
+* @param    Data - The size in bytes.
+*
+* @return   None.
+*
+* @note
+*
+* void XHwIcap_mSetSizeReg(u32 BaseAddress, u32 Data);
+*
+*****************************************************************************/
+#define XHwIcap_mSetSizeReg(BaseAddress, Data) \
+    (out_be32((u32 *)((BaseAddress) + XHI_SIZE_REG_OFFSET), (Data)))
+
+/****************************************************************************/
+/**
+* Set the bram offset register.
+*
+* The bram offset register holds the starting bram address to transfer
+* data from during configuration or write data to during readback.
+*
+* @param    BaseAddress contains the base address of the device.
+*
+* @param    Data is the value to be written to the data register.
+*
+* @return   None.
+*
+* @note
+*
+* void XHwIcap_mSetOffsetReg(u32 BaseAddress, u32 Data);
+*
+*****************************************************************************/
+#define XHwIcap_mSetOffsetReg(BaseAddress, Data) \
+    (out_be32((u32 *)((BaseAddress) + XHI_BRAM_OFFSET_REG_OFFSET), (Data)))
+
+/****************************************************************************/
+/**
+* Set the RNC (Readback not Configure) register.
+*
+* The RNC register determines the direction of the data transfer.  It
+* controls whether a configuration or readback take place.  Writing to
+* this register initiates the transfer.  A value of 1 initiates a
+* readback while writing a value of 0 initiates a configuration.
+*
+* @param    BaseAddress contains the base address of the device.
+*
+* @param    Data is the value to be written to the data register.
+*
+* @return   None.
+*
+* @note
+*
+* void XHwIcap_mSetRncReg(u32 BaseAddress, u32 Data);
+*
+*****************************************************************************/
+#define XHwIcap_mSetRncReg(BaseAddress, Data) \
+    (out_be32((u32 *)((BaseAddress) + XHI_RNC_REG_OFFSET), (Data)))
+
+/****************************************************************************/
+/**
+* Write data to the storage buffer bram.
+*
+* A bram is used as a configuration memory cache.  One frame of data can
+* be stored in this "storage buffer".
+*
+* @param    BaseAddress - contains the base address of the component.
+*
+* @param    Offset - The offset into which the data should be written.
+*
+* @param    Data - The value to be written to the bram offset.
+*
+* @return   None.
+*
+* @note
+*
+* void XHwIcap_mSetBram(u32 BaseAddress, u32 Offset, u32 Data);
+*
+*****************************************************************************/
+#define XHwIcap_mSetBram(BaseAddress, Offset, Data) \
+    (out_be32((u32 *)((BaseAddress+(Offset<<2))), (Data)))
+
+/****************************************************************************/
+/**
+*
+* Generates a Type 1 packet header that reads back the requested configuration
+* register.
+*
+* @param    Register is the address of the register to be read back.
+*           Register constants are defined in this file.
+*
+* @return   Type 1 packet header to read the specified register
+*
+* @note     None.
+*
+*****************************************************************************/
+#define XHwIcap_Type1Read(Register) \
+    ((XHI_TYPE_1 << XHI_TYPE_SHIFT) | (Register << XHI_REGISTER_SHIFT) | \
+    (XHI_OP_READ << XHI_OP_SHIFT))
+
+/****************************************************************************/
+/**
+*
+* Generates a Type 1 packet header that writes to the requested
+* configuration register.
+*
+* @param    Register is the address of the register to be written to.
+*           Register constants are defined in this file.
+*
+* @return   Type 1 packet header to write the specified register
+*
+* @note     None.
+*
+*****************************************************************************/
+#define XHwIcap_Type1Write(Register) \
+    ((XHI_TYPE_1 << XHI_TYPE_SHIFT) | (Register << XHI_REGISTER_SHIFT) | \
+    (XHI_OP_WRITE << XHI_OP_SHIFT))
+
+/************************** Function Prototypes *****************************/
+
+/* These functions are the ones defined in the lower level
+ * Self-Reconfiguration Platform (SRP) API.
+ */
+
+/* Initializes a XHwIcap instance.. */
+int XHwIcap_Initialize(struct xhwicap_drvdata *InstancePtr, u16 DeviceId,
+		       u32 DeviceIdCode);
+
+/* Reads integers from the device into the storage buffer. */
+int XHwIcap_DeviceRead(struct xhwicap_drvdata *InstancePtr, u32 Offset,
+		       u32 NumInts);
+
+/* Writes integers to the device from the storage buffer. */
+int XHwIcap_DeviceWrite(struct xhwicap_drvdata *InstancePtr, u32 Offset,
+			u32 NumInts);
+
+/* Writes word to the storage buffer. */
+void XHwIcap_StorageBufferWrite(struct xhwicap_drvdata *InstancePtr,
+				u32 Address, u32 Data);
+
+/* Reads word from the storage buffer. */
+u32 XHwIcap_StorageBufferRead(struct xhwicap_drvdata *InstancePtr, u32 Address);
+
+/* Loads a partial bitstream from system memory. */
+int XHwIcap_SetConfiguration(struct xhwicap_drvdata *InstancePtr, u32 *Data,
+			     u32 Size);
+
+/* Loads a partial bitstream from system memory. */
+int XHwIcap_GetConfiguration(struct xhwicap_drvdata *InstancePtr, u32 *Data,
+			     u32 Size);
+
+/* Sends a DESYNC command to the ICAP */
+int XHwIcap_CommandDesync(struct xhwicap_drvdata *InstancePtr);
+
+/* Sends a CAPTURE command to the ICAP */
+int XHwIcap_CommandCapture(struct xhwicap_drvdata *InstancePtr);
+
+/* Returns the value of the specified configuration register */
+u32 XHwIcap_GetConfigReg(struct xhwicap_drvdata *InstancePtr, u32 ConfigReg);
+
+#endif
Signature · 1 line
1.5.3.4-dirty
Signature · 1 line
Bye, Peter Korsgaard
#3 lore raw

Peter,

Sorry, this has taken so long... I've undertaken some significant refactorings, and included support for the new EDK9.2 xps_hwicap. Responses below.

Quoted 1 line

Please don't put the HWICAP option in the middle of the HVC options.

oops! fixed.

Quoted 9 lines

=20

drivers/char/Kconfig config HVC_DRIVER

Quoted 5 lines
drivers/char/Kconfig +5 -0
+config XILINX_HWICAP
+	tristate "Xilinx OPB HWICAP Support"
+	depends on XILINX_VIRTEX
+	help
+	This option enables support for Xilinx Internal=20

Configuration Access Port (ICAP) driver.
=20
Line too long.

fixed. checkpatch passes now.

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+obj-$(CONFIG_XILINX_HWICAP) +=3D xilinx_hwicap_m.o=20
+=20
+xilinx_hwicap_m-y :=3D xilinx_hwicap.o xhwicap_srp.o

=20
Those files are both quite small, couldn't you merge them and get rid of the global symbols and the xilinx_hwicap directory?

Its somewhat an artifact of the original EDK code that it is derived from,
but your probably right. I've refactored the code to look a little bit nicer, and now there is a new C file for the fifo-based xps_hwicap. I think it really does make sense to have multiple files, now.

Quoted 1 line

Could you please you a smaller / standard GPL header instead?

Although most copyrights are shorter, in poking through the code, there others which are of comparable size/language.

Quoted 1 line

Please use std kerneldoc format.

Fixed.

Quoted 1 line

No CamelCase, Uppercase parameters.

Fixed.

Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (XHwIcap_mGetDoneReg(InstancePtr->baseAddress) =3D=3D=20

XHI_NOT_FINISHED) {

Review

Quoted 2 lines
(quoted diff) +2 -0
+		return -EBUSY;
+	}

=20
No curly brackets around single statement. In general, please run the patch through checkpatch.pl and fixup stuff.

Gah... force of habit. Does anyone have an emacs mode that comes close to the linux coding style?

Quoted 2 lines

Why don't you request official major/minor numbers? (Documentation/devices.txt)

I sent a request to lanana over amonth ago, but haven't received a response. For embedded targets the dynamically allocated device is annoying, but without a static number I don't see what else to do. In any event, it is easy to change when a static device number is allocated.

Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static struct device_driver xhwicap_module_driver =3D {
+	.name =3D DRIVER_NAME,
+	.bus =3D &platform_bus_type,
+
+	.probe =3D xhwicap_drv_probe,
+	.remove =3D xhwicap_drv_remove,
+};

=20
Please use struct platform_driver instead.

That's what I get for copying old code. I also realized that there is a better way of dealing with the of_platform_device part. It's been rewritten to follow the pattern that Grant and I have been following.

Quoted 9 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 7 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +7 -0
+
+static int __init xhwicap_module_init(void)
+{
+	dev_t devt;
+	int retval;
+
+	icap_class =3D class_create(THIS_MODULE, "xilinx_config");

=20
What's that for?

To get this:

-bash-3.00# pwd
/sys/class
-bash-3.00# find xilinx_config
xilinx_config
xilinx_config/xilinx_icap
xilinx_config/xilinx_icap/subsystem
xilinx_config/xilinx_icap/uevent
xilinx_config/xilinx_icap/dev

I started trying to do more with this, but I could never quite figure out how to get sysfs to do what I wanted to. There's a couple of things (like the IDCODE) that would be interesting to see here, I think.

Quoted 7 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.h line 71

Quoted 5 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +5 -0
+#ifdef CONFIG_XILINX_VIRTEX_4_FX
+#define XHI_FAMILY virtex4
+#else
+#define XHI_FAMILY virtex2
+#endif

=20
So having a single kernel with v2p/v4 support is not an option?

I've fixed this to add a level of indirection, and to select the right value based on the device tree. This required a slight modification to the mhs->dts generator to make the 'xlnx,family' attribute visible. Note that we currently can't build a real v2/v4 kernel because of some v2pro errata. Currently, I enable the errata even in v4, which is not so nice.

Quoted 9 lines
Quoted 4 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +3 -0
+#define XHwIcap_mGetSizeReg(BaseAddress) \
+    (in_be32((u32 *)((BaseAddress) + XHI_SIZE_REG_OFFSET)))
+

=20

+/************************************************************ ****************/
=20
Why not a single getter with a offset/register parameter instead of all these? And use inline functions instead of macros.

Historical artifact to some extent, but I think it makes cleaner code than trying to read the constants, and in some cases, it's not a straightforward register read. In any event, they've been changed to be static inlines. In general, I cleaned the code up alot.

Quoted 1 line

Bye, Peter Korsgaard

Thanks! An update will be coming around shortly.

Steve

#4 lore raw

PATCH 1/1 Xilinx: hwicap driver

In reply to Peter Korsgaard

This includes code for new fifo-based xps_hwicap in addition to the older opb_hwicap, which has a significantly different interface. The common code between the two drivers is largely shared.

Significant differences exists between this driver and what is supported in the EDK drivers. In particular, most of the architecture-specific code for reconfiguring individual FPGA resources has been removed. This functionality is likely better provided in a user-space support library. In addition, read and write access is supported. In addition, although the xps_hwicap cores support interrupt-driver mode, this driver only supports polled operation, in order to make the code simpler, and since the interrupt processing overhead is likely to slow down the throughput under Linux.

---
 drivers/char/Kconfig                       |    7 +
 drivers/char/Makefile                      |    1 +
 drivers/char/xilinx_hwicap/Makefile        |    7 +
 drivers/char/xilinx_hwicap/buffer_icap.c   |  381 ++++++++++++
 drivers/char/xilinx_hwicap/buffer_icap.h   |   57 ++
 drivers/char/xilinx_hwicap/fifo_icap.c     |  381 ++++++++++++
 drivers/char/xilinx_hwicap/fifo_icap.h     |   62 ++
 drivers/char/xilinx_hwicap/xilinx_hwicap.c |  895 ++++++++++++++++++++++++++++
 drivers/char/xilinx_hwicap/xilinx_hwicap.h |  193 ++++++
 9 files changed, 1984 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/xilinx_hwicap/Makefile
 create mode 100644 drivers/char/xilinx_hwicap/buffer_icap.c
 create mode 100644 drivers/char/xilinx_hwicap/buffer_icap.h
 create mode 100644 drivers/char/xilinx_hwicap/fifo_icap.c
 create mode 100644 drivers/char/xilinx_hwicap/fifo_icap.h
 create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.c
 create mode 100644 drivers/char/xilinx_hwicap/xilinx_hwicap.h
drivers/char/Kconfig +7 -0
index ef1ed5d..157ae2a 100644
@@ -831,6 +831,13 @@ config DTLK
 	  To compile this driver as a module, choose M here: the
 	  module will be called dtlk.
 
+config XILINX_HWICAP
+	tristate "Xilinx HWICAP Support"
+	depends on XILINX_VIRTEX
+	help
+	  This option enables support for Xilinx Internal Configuration
+	  Access Port (ICAP) driver.
+
 config R3964
 	tristate "Siemens R3964 line discipline"
 	---help---
drivers/char/Makefile +1 -0
index 07304d5..3a278a0 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_EFI_RTC)		+= efirtc.o
 obj-$(CONFIG_SGI_DS1286)	+= ds1286.o
 obj-$(CONFIG_SGI_IP27_RTC)	+= ip27-rtc.o
 obj-$(CONFIG_DS1302)		+= ds1302.o
+obj-$(CONFIG_XILINX_HWICAP)    += xilinx_hwicap/
 ifeq ($(CONFIG_GENERIC_NVRAM),y)
   obj-$(CONFIG_NVRAM)	+= generic_nvram.o
 else
drivers/char/xilinx_hwicap/Makefile new file +7 -0
new file mode 100644
index 0000000..5491cbc
@@ -0,0 +1,7 @@
+#
+# Makefile for the Xilinx OPB hwicap driver
+#
+
+obj-$(CONFIG_XILINX_HWICAP) += xilinx_hwicap_m.o 
+ 
+xilinx_hwicap_m-y := xilinx_hwicap.o fifo_icap.o buffer_icap.o
drivers/char/xilinx_hwicap/buffer_icap.c new file +381 -0

381 lines not on this page · raw message

drivers/char/xilinx_hwicap/buffer_icap.h new file +57 -0

57 lines not on this page · raw message

drivers/char/xilinx_hwicap/fifo_icap.c new file +381 -0

381 lines not on this page · raw message

drivers/char/xilinx_hwicap/fifo_icap.h new file +62 -0

62 lines not on this page · raw message

drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +895 -0

895 lines not on this page · raw message

drivers/char/xilinx_hwicap/xilinx_hwicap.h new file +193 -0

193 lines not on this page · raw message

Signature · 1 line
1.5.3.4-dirty
#5 lore raw

Re: [PATCH] [POWERPC] Xilinx: hwicap driver

Quoted 14 lines · Stephen Neuendorffer

This includes code for new fifo-based xps_hwicap in addition to the older opb_hwicap, which has a significantly different interface. The common code between the two drivers is largely shared.

Significant differences exists between this driver and what is supported in the EDK drivers. In particular, most of the architecture-specific code for reconfiguring individual FPGA resources has been removed. This functionality is likely better provided in a user-space support library. In addition, read and write access is supported. In addition, although the xps_hwicap cores support interrupt-driver mode, this driver only supports polled operation, in order to make the code simpler, and since the interrupt processing overhead is likely to slow down the throughput under Linux.

Quoted 1 line

Comments below...

Also, I'm not sure if drivers/char/xilinx_hwicap is the best place for this driver. drivers/misc/ might be better (but I'm not sure; poll other people on this)

Finally, buffer_icap and fifo_icap are not huge blocks of code. Will they be used by any other drivers? Can they be rolled into the xilinx_hwicap.c file?

Quoted 14 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +14 -0
+static int buffer_icap_device_read(struct hwicap_drvdata *drvdata,
+               u32 offset, u32 count)
+{
+
+       s32 retries = 0;
+       void __iomem *base_address = drvdata->base_address;
+
+       if (buffer_icap_busy(base_address))
+               return -EBUSY;
+
+       if ((offset + count) <= XHI_MAX_BUFFER_INTS) {
+               /* setSize count*4 to get bytes. */
+               buffer_icap_set_size(base_address, (count << 2));
+               buffer_icap_set_offset(base_address, offset);

drivers/char/xilinx_hwicap/buffer_icap.c line 225

Quoted 10 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +10 -0
+               buffer_icap_set_rnc(base_address, XHI_READBACK);
+
+               while (buffer_icap_busy(base_address)) {
+                       retries++;
+                       if (retries > XHI_MAX_RETRIES)
+                               return -EBUSY;
+               }
+       } else {
+               return -EINVAL;
+       }

Style comment: reverse the condition and bail with return -EINVAL at the test point. It will simplify the code and better match with common practice in the kernel.

Quoted 25 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +25 -0
+       return 0;
+
+};
+
+/**
+ * buffer_icap_device_write: Transfer bytes from ICAP to the storage buffer.
+ * @parameter drvdata: a pointer to the drvdata.
+ * @parameter offset: The storage buffer start address.
+ * @parameter count: The number of words (32 bit) to read from the
+ *           device (ICAP).
+ **/
+static int buffer_icap_device_write(struct hwicap_drvdata *drvdata,
+               u32 offset, u32 count)
+{
+
+       s32 retries = 0;
+       void __iomem *base_address = drvdata->base_address;
+
+       if (buffer_icap_busy(base_address))
+               return -EBUSY;
+
+       if ((offset + count) <= XHI_MAX_BUFFER_INTS) {
+               /* setSize count*4 to get bytes. */
+               buffer_icap_set_size(base_address, count << 2);
+               buffer_icap_set_offset(base_address, offset);

drivers/char/xilinx_hwicap/buffer_icap.c line 260

Quoted 10 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +10 -0
+               buffer_icap_set_rnc(base_address, XHI_CONFIGURE);
+
+               while (buffer_icap_busy(base_address)) {
+                       retries++;
+                       if (retries > XHI_MAX_RETRIES)
+                               return -EBUSY;
+               }
+       } else {
+               return -EINVAL;
+       }

Ditto

Quoted 31 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +31 -0
+/**
+ * buffer_icap_set_configuration: Load a partial bitstream from system memory.
+ * @parameter drvdata: a pointer to the drvdata.
+ * @parameter data: Kernel address of the partial bitstream.
+ * @parameter size: the size of the partial bitstream in 32 bit words.
+ **/
+int buffer_icap_set_configuration(struct hwicap_drvdata *drvdata, u32 *data,
+                            u32 size)
+{
+       int status;
+       s32 buffer_count = 0;
+       s32 num_writes = 0;
+       bool dirty = 0;
+       u32 i;
+       void __iomem *base_address = drvdata->base_address;
+
+       /* Loop through all the data */
+       for (i = 0, buffer_count = 0; i < size; i++) {
+
+               /* Copy data to bram */
+               buffer_icap_set_bram(base_address, buffer_count, data[i]);
+               dirty = 1;
+
+               if (buffer_count == XHI_MAX_BUFFER_INTS - 1) {
+                       /* Write data to ICAP */
+                       status = buffer_icap_device_write(
+                                       drvdata,
+                                       XHI_BUFFER_START,
+                                       XHI_MAX_BUFFER_INTS);
+                       if (status != 0) {
+                               /* abort. */

drivers/char/xilinx_hwicap/buffer_icap.c line 318

Quoted 10 lines
drivers/char/xilinx_hwicap/buffer_icap.c new file +10 -0
+                               buffer_icap_reset(drvdata);
+                               return status;
+                       }
+
+                       buffer_count = 0;
+                       num_writes++;
+                       dirty = 0;
+               } else {
+                       buffer_count++;
+               }

Nit: Consider reversing the test condition and using 'buffer_count++; continue'

Quoted 4 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +4 -0
+static ssize_t
+hwicap_read(struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+       struct hwicap_drvdata *drvdata = file->private_data;

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 359

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+       ssize_t bytes_to_read = 0;
+       u32 *kbuf;
+       u32 words;
+       u32 bytes_remaining;
+       int status;
+
+       if (drvdata->is_accessing)
+               return -EBUSY;
+
+       drvdata->is_accessing = 1;

Race condition, you need to use a semaphore. Otherwise it is possible to get two processes (or even two threads of the same process) in the read() hook.

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 528

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+static int hwicap_open(struct inode *inode, struct file *file)
+{
+       struct hwicap_drvdata *drvdata;
+       int status;
+
+       drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev);
+       if (drvdata->is_open)
+               return -EBUSY;
+
+       drvdata->is_open = 1;

Also a race condition. Use a semaphore.

Also, this isn't sufficient to prevent 2 processes from having the device open. If a process has already opened it and then calls fork(), then *both* processes will have it opened even though the open fop was only called once. (It might not matter for this particular driver as the use case is limited; but it is something you should be aware of.)

Quoted 17 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +17 -0
+static int __devinit hwicap_setup(struct device *dev, int id,
+               const struct resource *regs_res,
+               const struct hwicap_driver_config *config,
+               const struct config_registers *config_regs)
+{
+       dev_t devt;
+       struct hwicap_drvdata *drvdata = NULL;
+       int retval = 0;
+
+       dev_info(dev, "Xilinx icap port driver\n");
+
+       if (id < 0) {
+               for (id = 0; id < HWICAP_DEVICES; id++)
+                       if (!probed_devices[id])
+                               break;
+       }
+       if (id < 0 || id >= HWICAP_DEVICES) {

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 604

Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+               dev_err(dev, "%s%i too large\n", DRIVER_NAME, id);
+               return -EINVAL;
+       }
+       if (probed_devices[id]) {
+               dev_err(dev, "cannot assign to %s%i; it is already in use\n",
+                       DRIVER_NAME, id);
+               return -EBUSY;
+       }
+
+       probed_devices[id] = 1;

Hmmm, I'm not thrilled with the fixed array of HWICAP devices. That sort of thing just ends up causing headaches down the road. Can the driver just allocate a new structure and the next available ID at probe time? (I hold my nose every time I write something like the above because I know I'm going to regret it later). sysfs/udev can provide details about which one is which.

drivers/char/xilinx_hwicap/xilinx_hwicap.c line 691

Quoted 8 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +8 -0
+
+static int __devexit hwicap_remove(struct device *dev)
+{
+       struct hwicap_drvdata *drvdata;
+
+       drvdata = (struct hwicap_drvdata *)dev_get_drvdata(dev);
+
+       if (drvdata) {

if (!drvdata)

    return 0;

Cheers,
g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#6 lore raw

RE: [PATCH] [POWERPC] Xilinx: hwicap driver

Quoted 4 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of

Grant Likely

Quoted 6 lines

Sent: Thursday, January 31, 2008 11:59 AM
To: Stephen Neuendorffer
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] [POWERPC] Xilinx: hwicap driver =20
On 1/31/08, Stephen Neuendorffer <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

This includes code for new fifo-based xps_hwicap in addition to the older opb_hwicap, which has a significantly different interface.

The

Quoted 5 lines
Quoted 5 lines

common code between the two drivers is largely shared.

Significant differences exists between this driver and what is supported in the EDK drivers. In particular, most of the architecture-specific code for reconfiguring individual FPGA

resources

Quoted 4 lines
Quoted 4 lines

has been removed. This functionality is likely better provided in a user-space support library. In addition, read and write access is supported. In addition, although the xps_hwicap cores support interrupt-driver mode, this driver only supports polled operation,

in

Quoted 4 lines
Quoted 4 lines

order to make the code simpler, and since the interrupt processing overhead is likely to slow down the throughput under Linux.

Signed-off-by Stephen Neuendorffer

<[email protected]>

Quoted 6 lines

=20
Comments below...
=20
Also, I'm not sure if drivers/char/xilinx_hwicap is the best place for this driver. drivers/misc/ might be better (but I'm not sure; poll other people on this)

I don't have strong opinions on this... If someone wants to say it should be in drivers/misc, I'm more than happy to move it. However, it doesn't seem like there is anything else that is a pure character device there.

Quoted 3 lines

Finally, buffer_icap and fifo_icap are not huge blocks of code. Will they be used by any other drivers? Can they be rolled into the xilinx_hwicap.c file?

They're not huge, but they are really independent from eachother. Furthermore, I expect that future cores will have DMA capability to increase bandwidth, which would result in a dma_icap file.

Quoted 3 lines

Style comment: reverse the condition and bail with return -EINVAL at the test point. It will simplify the code and better match with common practice in the kernel.

good point, I'll fix them all.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static ssize_t
+hwicap_read(struct file *file, char *buf, size_t count, loff_t

*ppos)

Quoted 8 lines
Quoted 8 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +8 -0
+{
+       struct hwicap_drvdata *drvdata =3D file->private_data;
+       ssize_t bytes_to_read =3D 0;
+       u32 *kbuf;
+       u32 words;
+       u32 bytes_remaining;
+       int status;
+
Quoted 8 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 4 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +4 -0
+       if (drvdata->is_accessing)
+               return -EBUSY;
+
+       drvdata->is_accessing =3D 1;

=20
Race condition, you need to use a semaphore. Otherwise it is possible to get two processes (or even two threads of the same process) in the read() hook.

good point. On thinking about this more, does the whole function need to be in a semaphore to protect against PREEMPT kernels?

Quoted 6 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 6 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +6 -0
+static int hwicap_open(struct inode *inode, struct file *file)
+{
+       struct hwicap_drvdata *drvdata;
+       int status;
+
+       drvdata =3D container_of(inode->i_cdev, struct =

hwicap_drvdata,
cdev);

Quoted 4 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 4 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +4 -0
+       if (drvdata->is_open)
+               return -EBUSY;
+
+       drvdata->is_open =3D 1;
Quoted 9 lines

=20
Also a race condition. Use a semaphore.
=20
Also, this isn't sufficient to prevent 2 processes from having the device open. If a process has already opened it and then calls fork(), then *both* processes will have it opened even though the open fop was only called once. (It might not matter for this particular driver as the use case is limited; but it is something you should be aware of.)

The fork I'm somewhat less concerned about, I think. If someone calls fork(), then it's up to them to synchronize their code correctly and only call close() once. The only reason to block the open is that it's the simplest way to keep track of the state between reads and writes.

Quoted 14 lines
Quoted 14 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +14 -0
+static int __devinit hwicap_setup(struct device *dev, int id,
+               const struct resource *regs_res,
+               const struct hwicap_driver_config *config,
+               const struct config_registers *config_regs)
+{
+       dev_t devt;
+       struct hwicap_drvdata *drvdata =3D NULL;
+       int retval =3D 0;
+
+       dev_info(dev, "Xilinx icap port driver\n");
+
+       if (id < 0) {
+               for (id =3D 0; id < HWICAP_DEVICES; id++)
+                       if (!probed_devices[id])
Quoted 8 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 8 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +8 -0
+                               break;
+       }
+       if (id < 0 || id >=3D HWICAP_DEVICES) {
+               dev_err(dev, "%s%i too large\n", DRIVER_NAME, id);
+               return -EINVAL;
+       }
+       if (probed_devices[id]) {
+               dev_err(dev, "cannot assign to %s%i; it is already

in use\n",

Quoted 5 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 5 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +5 -0
+                       DRIVER_NAME, id);
+               return -EBUSY;
+       }
+
+       probed_devices[id] =3D 1;
Quoted 7 lines

=20
Hmmm, I'm not thrilled with the fixed array of HWICAP devices. That sort of thing just ends up causing headaches down the road. Can the driver just allocate a new structure and the next available ID at probe time? (I hold my nose every time I write something like the above because I know I'm going to regret it later). sysfs/udev can provide details about which one is which.

Can you suggest a good driver to crib?

Quoted 2 lines

Cheers,
g.

Thanks!

#7 lore raw

Re: [PATCH] [POWERPC] Xilinx: hwicap driver

Quoted 11 lines · Stephen Neuendorffer
Quoted 6 lines

Also, this isn't sufficient to prevent 2 processes from having the device open. If a process has already opened it and then calls fork(), then *both* processes will have it opened even though the open fop was only called once. (It might not matter for this particular driver as the use case is limited; but it is something you should be aware of.)

The fork I'm somewhat less concerned about, I think. If someone calls fork(), then it's up to them to synchronize their code correctly and only call close() once. The only reason to block the open is that it's the simplest way to keep track of the state between reads and writes.

<interesting trivia> You're thinking of threads; not fork. When fork is called you get a whole new process which has all the same file descriptors open as the parent process. This is what the timeline would look like:

p1: open(/dev/hwcap0)
--- open fop called here (and struct file is allocated)
p1: fork()
--- p2 is created
p1: do stuff
p2: do stuff
p1: close()
p2: do more stuff
p2: close()
--- release fop called here (and struct file is released)

Notice how close is called twice (the correct behavour) yet release is only called once? :-) That means there are 2 processes sharing the same file structure.

Quoted 29 lines
Quoted 14 lines
Quoted 14 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +14 -0
+static int __devinit hwicap_setup(struct device *dev, int id,
+               const struct resource *regs_res,
+               const struct hwicap_driver_config *config,
+               const struct config_registers *config_regs)
+{
+       dev_t devt;
+       struct hwicap_drvdata *drvdata = NULL;
+       int retval = 0;
+
+       dev_info(dev, "Xilinx icap port driver\n");
+
+       if (id < 0) {
+               for (id = 0; id < HWICAP_DEVICES; id++)
+                       if (!probed_devices[id])
Quoted 8 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 8 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +8 -0
+                               break;
+       }
+       if (id < 0 || id >= HWICAP_DEVICES) {
+               dev_err(dev, "%s%i too large\n", DRIVER_NAME, id);
+               return -EINVAL;
+       }
+       if (probed_devices[id]) {
+               dev_err(dev, "cannot assign to %s%i; it is already

in use\n",

Quoted 6 lines
Quoted 5 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +5 -0
+                       DRIVER_NAME, id);
+               return -EBUSY;
+       }
+
+       probed_devices[id] = 1;
Quoted 8 lines
Quoted 6 lines

Hmmm, I'm not thrilled with the fixed array of HWICAP devices. That sort of thing just ends up causing headaches down the road. Can the driver just allocate a new structure and the next available ID at probe time? (I hold my nose every time I write something like the above because I know I'm going to regret it later). sysfs/udev can provide details about which one is which.

Can you suggest a good driver to crib?

What I would do is use a static struct list_head to hold a list of all instantiated devices. When you register a new device you can use list_for_each_entry to look for a free id. That way you don't have to preallocate an array for all the possible device numbers.

OTOH, how many of these devices are likely to be present on any one bitstream? If it is only 1 or 2 then it might be that the overhead isn't worth the savings. I won't complain if you decide it's better the way it is now.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#8 lore raw

RE: [PATCH] [POWERPC] Xilinx: hwicap driver

Quoted 4 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of

Grant Likely

Quoted 6 lines

Sent: Thursday, January 31, 2008 3:13 PM
To: Stephen Neuendorffer
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] [POWERPC] Xilinx: hwicap driver =20
On 1/31/08, Stephen Neuendorffer <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines

Also, this isn't sufficient to prevent 2 processes from having the device open. If a process has already opened it and then calls fork(), then *both* processes will have it opened even though the

open

Quoted 1 line
Quoted 1 line
Quoted 1 line

fop was only called once. (It might not matter for this

particular

Quoted 1 line
Quoted 1 line
Quoted 1 line

driver as the use case is limited; but it is something you should

be

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

aware of.)

The fork I'm somewhat less concerned about, I think. If someone

calls

Quoted 2 lines
Quoted 2 lines

fork(), then it's up to them to synchronize their code correctly and only call close() once. The only reason to block the open is that

it's

Quoted 1 line
Quoted 1 line

the simplest way to keep track of the state between reads and

writes.

Quoted 12 lines

=20
<interesting trivia> You're thinking of threads; not fork. When fork is called you get a whole new process which has all the same file descriptors open as the parent process. This is what the timeline would look like:
=20
p1: open(/dev/hwcap0)
--- open fop called here (and struct file is allocated)
p1: fork()
--- p2 is created
p1: do stuff
p2: do stuff

Quoted 8 lines

p1: close()
p2: do more stuff
p2: close()
--- release fop called here (and struct file is released) =20
Notice how close is called twice (the correct behavour) yet release is only called once? :-) That means there are 2 processes sharing the same file structure.

Hmm... hadn't realized that. In most uses of fork I've seen/thought of, the return value of fork is used to identify the parent and child processes and typically the child code avoids accessing the open files in order to avoid colliding output (and relies on the implicit close() on exit). In any event, regardless of when close is called, all we really care about is the release fop... Regardless, I'll be more careful about distinguishing the close and the release in the future, though :)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +10 -0
+static int __devinit hwicap_setup(struct device *dev, int id,
+               const struct resource *regs_res,
+               const struct hwicap_driver_config *config,
+               const struct config_registers *config_regs)
+{
+       dev_t devt;
+       struct hwicap_drvdata *drvdata =3D NULL;
+       int retval =3D 0;
+
+       dev_info(dev, "Xilinx icap port driver\n");
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 8 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +8 -0
+
+       if (id < 0) {
+               for (id =3D 0; id < HWICAP_DEVICES; id++)
+                       if (!probed_devices[id])
+                               break;
+       }
+       if (id < 0 || id >=3D HWICAP_DEVICES) {
+               dev_err(dev, "%s%i too large\n", DRIVER_NAME,

id);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 4 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +4 -0
+               return -EINVAL;
+       }
+       if (probed_devices[id]) {
+               dev_err(dev, "cannot assign to %s%i; it is

already

Quoted 8 lines
Quoted 8 lines

in use\n",

Quoted 7 lines

drivers/char/xilinx_hwicap/xilinx_hwicap.c

Quoted 5 lines
drivers/char/xilinx_hwicap/xilinx_hwicap.c new file +5 -0
+                       DRIVER_NAME, id);
+               return -EBUSY;
+       }
+
+       probed_devices[id] =3D 1;

Hmmm, I'm not thrilled with the fixed array of HWICAP devices.

That

Quoted 1 line
Quoted 1 line
Quoted 1 line

sort of thing just ends up causing headaches down the road. Can

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

driver just allocate a new structure and the next available ID at probe time? (I hold my nose every time I write something like the above because I know I'm going to regret it later). sysfs/udev

can

Quoted 13 lines
Quoted 3 lines
Quoted 1 line

provide details about which one is which.

Can you suggest a good driver to crib?

=20
What I would do is use a static struct list_head to hold a list of all instantiated devices. When you register a new device you can use list_for_each_entry to look for a free id. That way you don't have to preallocate an array for all the possible device numbers. =20
OTOH, how many of these devices are likely to be present on any one bitstream? If it is only 1 or 2 then it might be that the overhead isn't worth the savings. I won't complain if you decide it's better the way it is now.

In this case, it is highly likely that there will be only 1 in the system, and since the code is properly parameterized with respect to the number of devices that are registered, I don't think it's worth it.

Steve