Skip to contentSkip to conversation

request_firmware() backport to 2.4 kernels

PATCH In review Manuel Estrada Sainz 2 participants 3 messages May 24, 2003 – May 30, 2003

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

PATCH 1/1 request_firmware() backport to 2.4 kernels

Hi everyone,

Now that request_firmware() is on it's way to the main 2.5 tree, it is time to consider what should be done for 2.4 kernels.

At least Pavel's spectrum24 driver would be ready for submission if this functionality was available, and I hope to get orinoco_usb stable enough for 2.4 inclusion before 2.6 comes out, which also needs such functionality.

Notes on the attached patch:
---------------------------

- 99% compatible with 2.5 implementation both on the kernel's and hotplug's sides. The other 1% is:
- To kernel code: the 'device' argument is 'char *' instead of 'struct device *'.
- To hotplug: the prefix for $DEVPATH is /proc/ instead of /sys/
- Doesn't modify any existing code.
- Uses procfs in place of sysfs.

Please comment

Manuel

Signature · 6 lines
--- Manuel Estrada Sainz <[email protected]>
                         <[email protected]>
			 <[email protected]>
------------------------ <[email protected]> -------------------
Let us have the serenity to accept the things we cannot change, courage to
change the things we can, and wisdom to know the difference.
Documentation/Configure.help +6 -0
diff --exclude=CVS -urN linux-2.4.orig/Documentation/Configure.help linux-2.4.mine/Documentation/Configure.help
@@ -26525,6 +26525,12 @@
 
   If unsure, say N.
 
+Hotplug firmware loading support (EXPERIMENTAL)
+CONFIG_FW_LOADER
+  This option is provided for the case where no in-kernel-tree modules require
+  hotplug firmware loading support, but a module built outside the kernel tree
+  does.
+
 #
 # A couple of things I keep forgetting:
 #   capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet,
include/linux/firmware.h +20 -0
diff --exclude=CVS -urN linux-2.4.orig/include/linux/firmware.h linux-2.4.mine/include/linux/firmware.h
@@ -0,0 +1,20 @@
+#ifndef _LINUX_FIRMWARE_H
+#define _LINUX_FIRMWARE_H
+#include <linux/module.h>
+#include <linux/types.h>
+#define FIRMWARE_NAME_MAX 30 
+struct firmware {
+	size_t size;
+	u8 *data;
+};
+int request_firmware (const struct firmware **fw, const char *name,
+		      const char *device);
+int request_firmware_nowait (
+	struct module *module,
+	const char *name, const char *device, void *context,
+	void (*cont)(const struct firmware *fw, void *context));
+/* On 2.5 'device' is 'struct device *' */
+
+void release_firmware (const struct firmware *fw);
+void register_firmware (const char *name, const u8 *data, size_t size);
+#endif
lib/Config.in +4 -0
diff --exclude=CVS -urN linux-2.4.orig/lib/Config.in linux-2.4.mine/lib/Config.in
@@ -35,4 +35,8 @@
   fi
 fi
 
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+   tristate 'Hotplug firmware loading support (EXPERIMENTAL)' CONFIG_FW_LOADER
+fi
+
 endmenu
lib/Makefile +3 -1
diff --exclude=CVS -urN linux-2.4.orig/lib/Makefile linux-2.4.mine/lib/Makefile
@@ -8,11 +8,13 @@
 
 L_TARGET := lib.a
 
-export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o
+export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o \
+	       firmware_class.o
 
 obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
 	 bust_spinlocks.o rbtree.o dump_stack.o
 
+obj-$(CONFIG_FW_LOADER) += firmware_class.o
 obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
 obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
 
lib/firmware_class.c +566 -0

566 lines not on this page · raw message

#1 lore raw

Review

Quoted 11 lines · Manuel Estrada Sainz
(quoted diff) +11 -0
+	if (device) {
+		envp[i++] = scratch;
+		scratch += sprintf(scratch, "DEVPATH=/driver/firmware/%s",
+				   device) + 1;
+	}
+
+	envp[i++] = scratch;
+	scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
+
+	envp[i++] = scratch;
+	scratch += sprintf(scratch, "FIRMWARE=%s", name) + 1;

Ingo Oeser wisely suggested using snprintf in some of this cases, attached goes an updated patch and an incremental patch for easier reading.

Have a nice day

Manuel

Signature · 6 lines
--- Manuel Estrada Sainz <[email protected]>
                         <[email protected]>
			 <[email protected]>
------------------------ <[email protected]> -------------------
Let us have the serenity to accept the things we cannot change, courage to
change the things we can, and wisdom to know the difference.
lib/firmware_class.c +4 -3
diff -u linux-2.4.mine/lib/firmware_class.c linux-2.4.mine/lib/firmware_class.c
@@ -123,15 +123,16 @@
 
 	if (device) {
 		envp[i++] = scratch;
-		scratch += sprintf(scratch, "DEVPATH=/driver/firmware/%s",
-				   device) + 1;
+		scratch += snprintf(scratch, FIRMWARE_NAME_MAX,
+				    "DEVPATH=/driver/firmware/%s", device) + 1;
 	}
 
 	envp[i++] = scratch;
 	scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
 
 	envp[i++] = scratch;
-	scratch += sprintf(scratch, "FIRMWARE=%s", name) + 1;
+	scratch += snprintf(scratch, FIRMWARE_NAME_MAX,
+			    "FIRMWARE=%s", name) + 1;
 
 	envp[i++] = 0;
 
Documentation/Configure.help +6 -0
diff --exclude=CVS -urN linux-2.4.orig/Documentation/Configure.help linux-2.4.mine/Documentation/Configure.help
@@ -26542,6 +26542,12 @@
 
   If unsure, say N.
 
+Hotplug firmware loading support (EXPERIMENTAL)
+CONFIG_FW_LOADER
+  This option is provided for the case where no in-kernel-tree modules require
+  hotplug firmware loading support, but a module built outside the kernel tree
+  does.
+
 NatSemi SCx200 support
 CONFIG_SCx200
   This provides basic support for the National Semiconductor SCx200
include/linux/firmware.h +20 -0
diff --exclude=CVS -urN linux-2.4.orig/include/linux/firmware.h linux-2.4.mine/include/linux/firmware.h
@@ -0,0 +1,20 @@
+#ifndef _LINUX_FIRMWARE_H
+#define _LINUX_FIRMWARE_H
+#include <linux/module.h>
+#include <linux/types.h>
+#define FIRMWARE_NAME_MAX 30 
+struct firmware {
+	size_t size;
+	u8 *data;
+};
+int request_firmware (const struct firmware **fw, const char *name,
+		      const char *device);
+int request_firmware_nowait (
+	struct module *module,
+	const char *name, const char *device, void *context,
+	void (*cont)(const struct firmware *fw, void *context));
+/* On 2.5 'device' is 'struct device *' */
+
+void release_firmware (const struct firmware *fw);
+void register_firmware (const char *name, const u8 *data, size_t size);
+#endif
lib/Config.in +4 -0
diff --exclude=CVS -urN linux-2.4.orig/lib/Config.in linux-2.4.mine/lib/Config.in
@@ -35,4 +35,8 @@
   fi
 fi
 
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+   tristate 'Hotplug firmware loading support (EXPERIMENTAL)' CONFIG_FW_LOADER
+fi
+
 endmenu
lib/Makefile +3 -1
diff --exclude=CVS -urN linux-2.4.orig/lib/Makefile linux-2.4.mine/lib/Makefile
@@ -8,11 +8,13 @@
 
 L_TARGET := lib.a
 
-export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o
+export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o \
+	       firmware_class.o
 
 obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
 	 bust_spinlocks.o rbtree.o dump_stack.o
 
+obj-$(CONFIG_FW_LOADER) += firmware_class.o
 obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
 obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
 
lib/firmware_class.c +567 -0

567 lines not on this page · raw message