From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jon Smirl Date: Sun, 20 Mar 2005 04:06:59 +0000 Subject: Rework of request firmware Message-Id: <9e473391050319200625032789@mail.gmail.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="----=_Part_936_23455848.1111291619503" List-Id: To: linux-hotplug@vger.kernel.org ------=_Part_936_23455848.1111291619503 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sat, 26 Feb 2005 20:41:16 +0100, Kay Sievers wrote: > I think the request_firmware() should be redesigned in a generic > request_user_data(kobj) call. This event would copy arbitrary data into > a sysfs file and something like KOBJ_REQUEST_DATA would do it. > > The call should create a file inside of a existing device and the event > handler should copy the data into this file instead of creating a own > class device for the firmware as we do today. This is a rework of request firmware to move the attributes from their own class into the device sysfs directory. I am also generalizing things so that I can request a post (this is what I need) as well as firmware. This is a first post of the code, please tell me what I can do to improve it before I send it to lkml. The changes in radeonfb are so that I can test it. There are also some debug printf's still in. Use the attachment with patch, gmail word wraps and I can't stop it. I made a few changes in the base code: 1) I modified kobj_hotplug() to take an extra function for adding variables. This lets the event add the normal variable for the kset and then I can tack mine on too. 2) New event KOBJ_POST. $POST and $FIRMWARE are used to differentiate post versus firmware load in the script. Should this be two events instead? 3) The script now needs to be in /etc/hotplug.d/default/30-post.hotplug. firmware.agent isn't used anymore. The firmware doesn't need to change or move. 4) I added a pointer to 'struct device' to track the firmware in sysfs. Is there a better way to do this? 5) I added the time out to /sys/firmware/post_timeout since there is no /sys/class/firmware any more. 6) How should everything be named? firmware, post, initialization, etc?? 7) Should request_firmware() be deprecated forcing the move to request_firmware_nowait? 8) Should I keep the different signatures on the nowait callbacks? -- Jon Smirl jonsmirl@gmail.com ===== drivers/acpi/container.c 1.2 vs edited ===== --- 1.2/drivers/acpi/container.c 2004-11-11 02:56:31 -05:00 +++ edited/drivers/acpi/container.c 2005-03-19 01:38:11 -05:00 @@ -182,16 +182,16 @@ if (ACPI_FAILURE(status) || !device) { result = container_device_add(&device, handle); if (!result) - kobject_hotplug(&device->kobj, KOBJ_ONLINE); + kobject_hotplug(&device->kobj, KOBJ_ONLINE, NULL); } else { /* device exist and this is a remove request */ - kobject_hotplug(&device->kobj, KOBJ_OFFLINE); + kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); } } break; case ACPI_NOTIFY_EJECT_REQUEST: if (!acpi_bus_get_device(handle, &device) && device) { - kobject_hotplug(&device->kobj, KOBJ_OFFLINE); + kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); } break; default: ===== drivers/acpi/processor_core.c 1.80 vs edited ===== --- 1.80/drivers/acpi/processor_core.c 2004-12-14 07:14:54 -05:00 +++ edited/drivers/acpi/processor_core.c 2005-03-19 01:38:57 -05:00 @@ -730,7 +730,7 @@ return_VALUE(-ENODEV); if ((pr->id >=0) && (pr->id < NR_CPUS)) { - kobject_hotplug(&(*device)->kobj, KOBJ_ONLINE); + kobject_hotplug(&(*device)->kobj, KOBJ_ONLINE, NULL); } return_VALUE(0); } @@ -774,13 +774,13 @@ } if (pr->id >= 0 && (pr->id < NR_CPUS)) { - kobject_hotplug(&device->kobj, KOBJ_OFFLINE); + kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); break; } result = acpi_processor_start(device); if ((!result) && ((pr->id >=0) && (pr->id < NR_CPUS))) { - kobject_hotplug(&device->kobj, KOBJ_ONLINE); + kobject_hotplug(&device->kobj, KOBJ_ONLINE, NULL); } else { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Device [%s] failed to start\n", @@ -801,7 +801,7 @@ } if ((pr->id < NR_CPUS) && (cpu_present(pr->id))) - kobject_hotplug(&device->kobj, KOBJ_OFFLINE); + kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); break; default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, ===== drivers/base/cpu.c 1.22 vs edited ===== --- 1.22/drivers/base/cpu.c 2005-01-31 01:33:46 -05:00 +++ edited/drivers/base/cpu.c 2005-03-19 01:39:16 -05:00 @@ -33,7 +33,7 @@ case '0': ret = cpu_down(cpu->sysdev.id); if (!ret) - kobject_hotplug(&dev->kobj, KOBJ_OFFLINE); + kobject_hotplug(&dev->kobj, KOBJ_OFFLINE, NULL); break; case '1': ret = cpu_up(cpu->sysdev.id); ===== drivers/base/firmware.c 1.9 vs edited ===== --- 1.9/drivers/base/firmware.c 2004-09-24 14:45:35 -04:00 +++ edited/drivers/base/firmware.c 2005-03-19 11:16:01 -05:00 @@ -14,21 +14,57 @@ static decl_subsys(firmware, NULL, NULL); +int post_timeout = 10; /* In seconds */ +EXPORT_SYMBOL_GPL(post_timeout); + int firmware_register(struct subsystem * s) { kset_set_kset_s(s, firmware_subsys); return subsystem_register(s); } +EXPORT_SYMBOL_GPL(firmware_register); void firmware_unregister(struct subsystem * s) { subsystem_unregister(s); } +EXPORT_SYMBOL_GPL(firmware_unregister); + +/** + * post_timeout_store: + * Description: + * Sets the number of seconds to wait for the post/firmware load. + * Once this expires an error will be return to the driver and no + * firmware will be provided. + * + * Note: zero means 'wait for ever' + * + **/ +static ssize_t post_timeout_store(struct subsystem *subsys, const char *buf, size_t count) +{ + post_timeout = simple_strtol(buf, NULL, 10); + return count; +} +static ssize_t post_timeout_show(struct subsystem *subsys, char *buf) +{ + return sprintf(buf, "%d\n", post_timeout); +} +static struct subsys_attribute post_timeout_attr = { + .attr = {.name = "post_timeout", .mode = 0644, .owner = THIS_MODULE}, + .show = post_timeout_show, + .store = post_timeout_store +}; int __init firmware_init(void) { - return subsystem_register(&firmware_subsys); + int error; + if ((error = subsystem_register(&firmware_subsys))) + return error; + + if ((error = subsys_create_file(&firmware_subsys, &post_timeout_attr))) { + subsystem_unregister(&firmware_subsys); + return error; + } + return 0; } -EXPORT_SYMBOL_GPL(firmware_register); -EXPORT_SYMBOL_GPL(firmware_unregister); ===== drivers/base/firmware_class.c 1.25 vs edited ===== --- 1.25/drivers/base/firmware_class.c 2004-11-26 15:26:48 -05:00 +++ edited/drivers/base/firmware_class.c 2005-03-19 21:11:15 -05:00 @@ -1,7 +1,8 @@ /* - * firmware_class.c - Multi purpose firmware loading support + * firmware_class.c - Multi purpose post support * * Copyright (c) 2003 Manuel Estrada Sainz + * Copyright (c) 2005 Jon Smirl * * Please see Documentation/firmware_class/ for more information. * @@ -20,7 +21,7 @@ #include "base.h" MODULE_AUTHOR("Manuel Estrada Sainz "); -MODULE_DESCRIPTION("Multi purpose firmware loading support"); +MODULE_DESCRIPTION("Multi purpose post support"); MODULE_LICENSE("GPL"); enum { @@ -30,8 +31,6 @@ FW_STATUS_READY, }; -static int loading_timeout = 10; /* In seconds */ - /* fw_lock could be moved to 'struct firmware_priv' but since it is just * guarding for corner cases a global lock should be OK */ static DECLARE_MUTEX(fw_lock); @@ -49,69 +48,41 @@ static inline void fw_load_abort(struct firmware_priv *fw_priv) { + printk(KERN_ERR "fw_load_abort\n"); set_bit(FW_STATUS_ABORT, &fw_priv->status); wmb(); complete(&fw_priv->completion); } -static ssize_t -firmware_timeout_show(struct class *class, char *buf) -{ - return sprintf(buf, "%d\n", loading_timeout); -} - -/** - * firmware_timeout_store: - * Description: - * Sets the number of seconds to wait for the firmware. Once - * this expires an error will be return to the driver and no - * firmware will be provided. - * - * Note: zero means 'wait for ever' - * - **/ -static ssize_t -firmware_timeout_store(struct class *class, const char *buf, size_t count) -{ - loading_timeout = simple_strtol(buf, NULL, 10); - return count; -} - -static CLASS_ATTR(timeout, 0644, firmware_timeout_show, firmware_timeout_store); - -static void fw_class_dev_release(struct class_device *class_dev); -int firmware_class_hotplug(struct class_device *dev, char **envp, - int num_envp, char *buffer, int buffer_size); - -static struct class firmware_class = { - .name = "firmware", - .hotplug = firmware_class_hotplug, - .release = fw_class_dev_release, -}; - int -firmware_class_hotplug(struct class_device *class_dev, char **envp, +post_hotplug(struct kset *kset, struct kobject *kobj, char **envp, int num_envp, char *buffer, int buffer_size) { - struct firmware_priv *fw_priv = class_get_devdata(class_dev); + struct device *dev = container_of(kobj, struct device, kobj); + struct firmware_priv *fw_priv = dev->post_data; int i = 0, len = 0; if (!test_bit(FW_STATUS_READY, &fw_priv->status)) return -ENODEV; - if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &len, - "FIRMWARE=%s", fw_priv->fw_id)) - return -ENOMEM; - + if (fw_priv->fw) { + if (add_hotplug_env_var(envp, num_envp, &i, buffer, + buffer_size, &len, "FIRMWARE=%s", fw_priv->fw_id)) + return -ENOMEM; + } else { + if (add_hotplug_env_var(envp, num_envp, &i, buffer, + buffer_size, &len, "POST=%s", fw_priv->fw_id)) + return -ENOMEM; + } envp[i] = NULL; return 0; } static ssize_t -firmware_loading_show(struct class_device *class_dev, char *buf) +post_status_show(struct device *dev, char *buf) { - struct firmware_priv *fw_priv = class_get_devdata(class_dev); + struct firmware_priv *fw_priv = dev->post_data; int loading = test_bit(FW_STATUS_LOADING, &fw_priv->status); return sprintf(buf, "%d\n", loading); } @@ -126,13 +97,13 @@ * -1: Conclude the load with an error and discard any written data. **/ static ssize_t -firmware_loading_store(struct class_device *class_dev, - const char *buf, size_t count) +post_status_store(struct device *dev, const char *buf, size_t count) { - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - int loading = simple_strtol(buf, NULL, 10); + struct firmware_priv *fw_priv = dev->post_data; + int status = simple_strtol(buf, NULL, 10); - switch (loading) { + printk(KERN_ERR "post_status_store: status %d\n", status); + switch (status) { case 1: down(&fw_lock); vfree(fw_priv->fw->data); @@ -151,7 +122,7 @@ /* fallthrough */ default: printk(KERN_ERR "%s: unexpected value (%d)\n", __FUNCTION__, - loading); + status); /* fallthrough */ case -1: fw_load_abort(fw_priv); @@ -161,15 +132,14 @@ return count; } -static CLASS_DEVICE_ATTR(loading, 0644, - firmware_loading_show, firmware_loading_store); +static DEVICE_ATTR(post_status, 0644, post_status_show, post_status_store); static ssize_t -firmware_data_read(struct kobject *kobj, - char *buffer, loff_t offset, size_t count) +post_data_read(struct kobject *kobj, + char *buffer, loff_t offset, size_t count) { - struct class_device *class_dev = to_class_dev(kobj); - struct firmware_priv *fw_priv = class_get_devdata(class_dev); + struct device *dev = container_of(kobj, struct device, kobj); + struct firmware_priv *fw_priv = dev->post_data; struct firmware *fw; ssize_t ret_count = count; @@ -191,6 +161,7 @@ up(&fw_lock); return ret_count; } + static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) { @@ -225,8 +196,8 @@ * the driver as a firmware image. **/ static ssize_t -firmware_data_write(struct kobject *kobj, - char *buffer, loff_t offset, size_t count) +post_data_write(struct kobject *kobj, + char *buffer, loff_t offset, size_t count) { struct class_device *class_dev = to_class_dev(kobj); struct firmware_priv *fw_priv = class_get_devdata(class_dev); @@ -254,124 +225,82 @@ return retval; } static struct bin_attribute firmware_attr_data_tmpl = { - .attr = {.name = "data", .mode = 0644, .owner = THIS_MODULE}, + .attr = {.name = "post_data", .mode = 0644, .owner = THIS_MODULE}, .size = 0, - .read = firmware_data_read, - .write = firmware_data_write, + .read = post_data_read, + .write = post_data_write, }; static void -fw_class_dev_release(struct class_device *class_dev) -{ - struct firmware_priv *fw_priv = class_get_devdata(class_dev); - - kfree(fw_priv); - kfree(class_dev); - - module_put(THIS_MODULE); -} - -static void -firmware_class_timeout(u_long data) +post_timeout_abort(u_long data) { struct firmware_priv *fw_priv = (struct firmware_priv *) data; + printk(KERN_ERR "post_timeout_abort: time out\n"); fw_load_abort(fw_priv); } -static inline void -fw_setup_class_device_id(struct class_device *class_dev, struct device *dev) -{ - /* XXX warning we should watch out for name collisions */ - strlcpy(class_dev->class_id, dev->bus_id, BUS_ID_SIZE); -} - static int -fw_register_class_device(struct class_device **class_dev_p, - const char *fw_name, struct device *device) +fw_register_device(const char *fw_name, struct device *device) { int retval; struct firmware_priv *fw_priv = kmalloc(sizeof (struct firmware_priv), GFP_KERNEL); - struct class_device *class_dev = kmalloc(sizeof (struct class_device), - GFP_KERNEL); - - *class_dev_p = NULL; - if (!fw_priv || !class_dev) { + if (!fw_priv) { printk(KERN_ERR "%s: kmalloc failed\n", __FUNCTION__); retval = -ENOMEM; goto error_kfree; } memset(fw_priv, 0, sizeof (*fw_priv)); - memset(class_dev, 0, sizeof (*class_dev)); init_completion(&fw_priv->completion); fw_priv->attr_data = firmware_attr_data_tmpl; strlcpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX); - fw_priv->timeout.function = firmware_class_timeout; + fw_priv->timeout.function = post_timeout_abort; fw_priv->timeout.data = (u_long) fw_priv; init_timer(&fw_priv->timeout); + + device->post_data = fw_priv; - fw_setup_class_device_id(class_dev, device); - class_dev->dev = device; - class_dev->class = &firmware_class; - class_set_devdata(class_dev, fw_priv); - retval = class_device_register(class_dev); - if (retval) { - printk(KERN_ERR "%s: class_device_register failed\n", - __FUNCTION__); - goto error_kfree; - } - *class_dev_p = class_dev; return 0; error_kfree: kfree(fw_priv); - kfree(class_dev); return retval; } static int -fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, - const char *fw_name, struct device *device) +fw_setup_device(struct firmware *fw, const char *fw_name, struct device *device) { - struct class_device *class_dev; struct firmware_priv *fw_priv; int retval; - *class_dev_p = NULL; - retval = fw_register_class_device(&class_dev, fw_name, device); + retval = fw_register_device(fw_name, device); if (retval) goto out; - /* Need to pin this module until class device is destroyed */ - __module_get(THIS_MODULE); - - fw_priv = class_get_devdata(class_dev); - + fw_priv = device->post_data; fw_priv->fw = fw; - retval = sysfs_create_bin_file(&class_dev->kobj, &fw_priv->attr_data); + + retval = sysfs_create_bin_file(&device->kobj, &fw_priv->attr_data); if (retval) { printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", __FUNCTION__); - goto error_unreg; + goto out; } - retval = class_device_create_file(class_dev, - &class_device_attr_loading); - if (retval) { - printk(KERN_ERR "%s: class_device_create_file failed\n", - __FUNCTION__); - goto error_unreg; + if (fw) { + retval = device_create_file(device, &dev_attr_post_status); + if (retval) { + printk(KERN_ERR "%s: device_create_file failed\n", + __FUNCTION__); + goto out; + } } - set_bit(FW_STATUS_READY, &fw_priv->status); - *class_dev_p = class_dev; goto out; -error_unreg: - class_device_unregister(class_dev); out: return retval; } @@ -388,62 +317,79 @@ * should be distinctive enough not to be confused with any other * firmware image for this or any other device. **/ -int -request_firmware(const struct firmware **firmware_p, const char *name, +static int +request(const struct firmware **firmware_p, const char *name, struct device *device) { - struct class_device *class_dev; struct firmware_priv *fw_priv; - struct firmware *firmware; + struct firmware *firmware = NULL; int retval; - if (!firmware_p) - return -EINVAL; - - *firmware_p = firmware = kmalloc(sizeof (struct firmware), GFP_KERNEL); - if (!firmware) { - printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", - __FUNCTION__); - retval = -ENOMEM; - goto out; + if (firmware_p) { + *firmware_p = firmware = kmalloc(sizeof (struct firmware), GFP_KERNEL); + if (!firmware) { + printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", + __FUNCTION__); + retval = -ENOMEM; + goto out; + } + memset(firmware, 0, sizeof (*firmware)); } - memset(firmware, 0, sizeof (*firmware)); - retval = fw_setup_class_device(firmware, &class_dev, name, device); + retval = fw_setup_device(firmware, name, device); if (retval) goto error_kfree_fw; - fw_priv = class_get_devdata(class_dev); + fw_priv = device->post_data; - if (loading_timeout) { - fw_priv->timeout.expires = jiffies + loading_timeout * HZ; + if (post_timeout) { + fw_priv->timeout.expires = jiffies + post_timeout * HZ; add_timer(&fw_priv->timeout); } - kobject_hotplug(&class_dev->kobj, KOBJ_ADD); + printk(KERN_ERR "request_firmware: hotplug event\n"); + kobject_hotplug(&device->kobj, KOBJ_POST, post_hotplug); wait_for_completion(&fw_priv->completion); set_bit(FW_STATUS_DONE, &fw_priv->status); + printk(KERN_ERR "request_firmware: complete\n"); del_timer_sync(&fw_priv->timeout); - down(&fw_lock); - if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) { - retval = -ENOENT; - release_firmware(fw_priv->fw); - *firmware_p = NULL; + if (firmware_p) { + down(&fw_lock); + if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) { + retval = -ENOENT; + release_firmware(fw_priv->fw); + *firmware_p = NULL; + } + fw_priv->fw = NULL; + up(&fw_lock); + + sysfs_remove_bin_file(&device->kobj, &fw_priv->attr_data); } - fw_priv->fw = NULL; - up(&fw_lock); - class_device_unregister(class_dev); + device_remove_file(device, &dev_attr_post_status); + goto out; error_kfree_fw: - kfree(firmware); - *firmware_p = NULL; + if (firmware) { + kfree(firmware); + *firmware_p = NULL; + } out: return retval; } +int +request_firmware(const struct firmware **firmware_p, const char *name, + struct device *device) +{ + if (!firmware_p) + return -EINVAL; + return request(firmware_p, name, device); +} +EXPORT_SYMBOL(request_firmware); + /** * release_firmware: - release the resource associated with a firmware image **/ @@ -455,6 +401,7 @@ kfree(fw); } } +EXPORT_SYMBOL(release_firmware); /** * register_firmware: - provide a firmware image for later usage @@ -472,6 +419,7 @@ * decide if firmware caching is reasonable just leave it as a * noop */ } +EXPORT_SYMBOL(register_firmware); /* Async support */ struct firmware_work { @@ -480,11 +428,12 @@ const char *name; struct device *device; void *context; - void (*cont)(const struct firmware *fw, void *context); + void (*cont_fw)(const struct firmware *fw, void *context); + void (*cont_post)(void *context); }; static int -request_firmware_work_func(void *arg) +request_post_work_func(void *arg) { struct firmware_work *fw_work = arg; const struct firmware *fw; @@ -492,10 +441,15 @@ WARN_ON(1); return 0; } - daemonize("%s/%s", "firmware", fw_work->name); - request_firmware(&fw, fw_work->name, fw_work->device); - fw_work->cont(fw, fw_work->context); - release_firmware(fw); + daemonize("%s/%s", "post", fw_work->name); + if (fw_work->cont_fw) { + request(&fw, fw_work->name, fw_work->device); + fw_work->cont_fw(fw, fw_work->context); + release_firmware(fw); + } else { + request(NULL, fw_work->name, fw_work->device); + fw_work->cont_post(fw_work->context); + } module_put(fw_work->module); kfree(fw_work); return 0; @@ -515,11 +469,12 @@ * @fw may be %NULL if firmware request fails. * **/ -int -request_firmware_nowait( +static int +request_nowait( struct module *module, const char *name, struct device *device, void *context, - void (*cont)(const struct firmware *fw, void *context)) + void (*cont_fw)(const struct firmware *fw, void *context), + void (*cont_post)(void *context)) { struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), GFP_ATOMIC); @@ -537,47 +492,37 @@ .name = name, .device = device, .context = context, - .cont = cont, + .cont_fw = cont_fw, + .cont_post = cont_post, }; - ret = kernel_thread(request_firmware_work_func, fw_work, + ret = kernel_thread(request_post_work_func, fw_work, CLONE_FS | CLONE_FILES); if (ret < 0) { - fw_work->cont(NULL, fw_work->context); + if (fw_work->cont_fw) + fw_work->cont_fw(NULL, fw_work->context); + if (fw_work->cont_post) + fw_work->cont_post(fw_work->context); return ret; } return 0; } -static int __init -firmware_class_init(void) +int +request_firmware_nowait(struct module *module, const char *name, + struct device *device, void *context, + void (*cont_fw)(const struct firmware *fw, void *context)) { - int error; - error = class_register(&firmware_class); - if (error) { - printk(KERN_ERR "%s: class_register failed\n", __FUNCTION__); - return error; - } - error = class_create_file(&firmware_class, &class_attr_timeout); - if (error) { - printk(KERN_ERR "%s: class_create_file failed\n", - __FUNCTION__); - class_unregister(&firmware_class); - } - return error; - + return request_nowait(module, name, device, context, cont_fw, NULL); } -static void __exit -firmware_class_exit(void) +EXPORT_SYMBOL(request_firmware_nowait); + +int +request_post_nowait(struct module *module, const char *name, + struct device *device, void *context, + void (*cont_post)(void *context)) { - class_unregister(&firmware_class); + return request_nowait(module, name, device, context, NULL, cont_post); } - -module_init(firmware_class_init); -module_exit(firmware_class_exit); - -EXPORT_SYMBOL(release_firmware); -EXPORT_SYMBOL(request_firmware); -EXPORT_SYMBOL(request_firmware_nowait); -EXPORT_SYMBOL(register_firmware); +EXPORT_SYMBOL(request_post_nowait); ===== drivers/video/aty/radeon_base.c 1.44 vs edited ===== --- 1.44/drivers/video/aty/radeon_base.c 2005-03-10 03:39:11 -05:00 +++ edited/drivers/video/aty/radeon_base.c 2005-03-19 21:17:49 -05:00 @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -2206,6 +2207,9 @@ .read = radeon_show_edid2, }; +static void radeon_post_finished(void *data) { + printk(KERN_ERR "radeon_post_finished\n"); +} static int radeonfb_pci_register (struct pci_dev *pdev, const struct pci_device_id *ent) @@ -2410,6 +2414,8 @@ } #endif + request_post_nowait(THIS_MODULE, "vbios.vm86", &pdev->dev, rinfo, radeon_post_finished); + printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name); if (rinfo->bios_seg) @@ -2453,7 +2459,19 @@ if (!rinfo) return; + /* Register some sysfs stuff (should be done better) */ + if (rinfo->mon1_EDID) + sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr); + if (rinfo->mon2_EDID) + sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr); + radeonfb_pm_exit(rinfo); + + /* Register some sysfs stuff (should be done better) */ + if (rinfo->mon1_EDID) + sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr); + if (rinfo->mon2_EDID) + sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr); #if 0 /* restore original state ===== include/linux/device.h 1.138 vs edited ===== --- 1.138/include/linux/device.h 2005-03-09 12:03:56 -05:00 +++ edited/include/linux/device.h 2005-03-19 11:11:34 -05:00 @@ -271,6 +271,7 @@ void *driver_data; /* data private to the driver */ void *platform_data; /* Platform specific data (e.g. ACPI, BIOS data relevant to device) */ + void *post_data; /* active during firmware load or post */ struct dev_pm_info power; u32 detach_state; /* State to enter when device is @@ -399,6 +400,7 @@ /* drivers/base/firmware.c */ extern int firmware_register(struct subsystem *); extern void firmware_unregister(struct subsystem *); +extern int post_timeout; /* In seconds */ /* debugging and troubleshooting/diagnostic helpers. */ #define dev_printk(level, dev, format, arg...) \ ===== include/linux/firmware.h 1.3 vs edited ===== --- 1.3/include/linux/firmware.h 2005-02-02 04:49:28 -05:00 +++ edited/include/linux/firmware.h 2005-03-19 21:12:52 -05:00 @@ -1,20 +1,27 @@ #ifndef _LINUX_FIRMWARE_H #define _LINUX_FIRMWARE_H +#include #include #include + #define FIRMWARE_NAME_MAX 30 + struct firmware { size_t size; u8 *data; }; -struct device; + +int request_post_nowait(struct module *module, const char *name, + struct device *device, void *context, + void (*cont_post)(void *context)); + int request_firmware(const struct firmware **fw, const char *name, struct device *device); -int request_firmware_nowait( - struct module *module, - const char *name, struct device *device, void *context, - void (*cont)(const struct firmware *fw, void *context)); - +int request_firmware_nowait(struct module *module, const char *name, + struct device *device, void *context, + void (*cont_fw)(const struct firmware *fw, void *context)); void release_firmware(const struct firmware *fw); + void register_firmware(const char *name, const u8 *data, size_t size); + #endif ===== include/linux/kobject.h 1.39 vs edited ===== --- 1.39/include/linux/kobject.h 2005-03-09 12:04:09 -05:00 +++ edited/include/linux/kobject.h 2005-03-19 01:32:55 -05:00 @@ -242,13 +242,19 @@ extern void subsys_remove_file(struct subsystem * , struct subsys_attribute *); #ifdef CONFIG_HOTPLUG -void kobject_hotplug(struct kobject *kobj, enum kobject_action action); +void kobject_hotplug(struct kobject *kobj, enum kobject_action action, + int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp, + int num_envp, char *buffer, int buffer_size) + ); int add_hotplug_env_var(char **envp, int num_envp, int *cur_index, char *buffer, int buffer_size, int *cur_len, const char *format, ...) __attribute__((format (printf, 7, 8))); #else -static inline void kobject_hotplug(struct kobject *kobj, enum kobject_action action) { } +static inline void kobject_hotplug(struct kobject *kobj, enum kobject_action action, + int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp, + int num_envp, char *buffer, int buffer_size) + ) { } static inline int add_hotplug_env_var(char **envp, int num_envp, int *cur_index, char *buffer, int buffer_size, int *cur_len, const char *format, ...) ===== include/linux/kobject_uevent.h 1.6 vs edited ===== --- 1.6/include/linux/kobject_uevent.h 2004-11-08 14:43:30 -05:00 +++ edited/include/linux/kobject_uevent.h 2005-03-17 10:36:00 -05:00 @@ -29,6 +29,7 @@ KOBJ_UMOUNT = (__force kobject_action_t) 0x05, /* umount event for block devices */ KOBJ_OFFLINE = (__force kobject_action_t) 0x06, /* offline event for hotplug devices */ KOBJ_ONLINE = (__force kobject_action_t) 0x07, /* online event for hotplug devices */ + KOBJ_POST = (__force kobject_action_t) 0x08, /* post event supports user space initialization */ }; ===== lib/kobject.c 1.58 vs edited ===== --- 1.58/lib/kobject.c 2005-03-09 12:04:09 -05:00 +++ edited/lib/kobject.c 2005-03-19 01:39:37 -05:00 @@ -185,7 +185,7 @@ if (parent) kobject_put(parent); } else { - kobject_hotplug(kobj, KOBJ_ADD); + kobject_hotplug(kobj, KOBJ_ADD, NULL); } return error; @@ -301,7 +301,7 @@ void kobject_del(struct kobject * kobj) { - kobject_hotplug(kobj, KOBJ_REMOVE); + kobject_hotplug(kobj, KOBJ_REMOVE, NULL); sysfs_remove_dir(kobj); unlink(kobj); } ===== lib/kobject_uevent.c 1.18 vs edited ===== --- 1.18/lib/kobject_uevent.c 2005-01-08 00:44:13 -05:00 +++ edited/lib/kobject_uevent.c 2005-03-19 01:48:04 -05:00 @@ -44,6 +44,8 @@ return "offline"; case KOBJ_ONLINE: return "online"; + case KOBJ_POST: + return "post"; default: return NULL; } @@ -187,7 +189,9 @@ * @action: action that is happening (usually "ADD" or "REMOVE") * @kobj: struct kobject that the action is happening to */ -void kobject_hotplug(struct kobject *kobj, enum kobject_action action) +void kobject_hotplug(struct kobject *kobj, enum kobject_action action, + int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp, + int num_envp, char *buffer, int buffer_size)) { char *argv [3]; char **envp = NULL; @@ -279,6 +283,17 @@ if (hotplug_ops->hotplug) { /* have the kset specific function add its stuff */ retval = hotplug_ops->hotplug (kset, kobj, + &envp[i], NUM_ENVP - i, scratch, + BUFFER_SIZE - (scratch - buffer)); + if (retval) { + pr_debug ("%s - hotplug() returned %d\n", + __FUNCTION__, retval); + goto exit; + } + } + if (hotplug) { + /* have the call specific function add on its stuff */ + retval = hotplug (kset, kobj, &envp[i], NUM_ENVP - i, scratch, BUFFER_SIZE - (scratch - buffer)); if (retval) { ------=_Part_936_23455848.1111291619503 Content-Type: text/x-diff; name="firmware.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="firmware.patch" =3D=3D=3D=3D=3D drivers/acpi/container.c 1.2 vs edited =3D=3D=3D=3D=3D --- 1.2/drivers/acpi/container.c=092004-11-11 02:56:31 -05:00 +++ edited/drivers/acpi/container.c=092005-03-19 01:38:11 -05:00 @@ -182,16 +182,16 @@ =09=09=09if (ACPI_FAILURE(status) || !device) { =09=09=09=09result =3D container_device_add(&device, handle); =09=09=09=09if (!result) -=09=09=09=09=09kobject_hotplug(&device->kobj, KOBJ_ONLINE); +=09=09=09=09=09kobject_hotplug(&device->kobj, KOBJ_ONLINE, NULL); =09=09=09} else { =09=09=09=09/* device exist and this is a remove request */ -=09=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE); +=09=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); =09=09=09} =09=09} =09=09break; =09case ACPI_NOTIFY_EJECT_REQUEST: =09=09if (!acpi_bus_get_device(handle, &device) && device) { -=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE); +=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); =09=09} =09=09break; =09default: =3D=3D=3D=3D=3D drivers/acpi/processor_core.c 1.80 vs edited =3D=3D=3D=3D= =3D --- 1.80/drivers/acpi/processor_core.c=092004-12-14 07:14:54 -05:00 +++ edited/drivers/acpi/processor_core.c=092005-03-19 01:38:57 -05:00 @@ -730,7 +730,7 @@ =09=09return_VALUE(-ENODEV); =20 =09if ((pr->id >=3D0) && (pr->id < NR_CPUS)) { -=09=09kobject_hotplug(&(*device)->kobj, KOBJ_ONLINE); +=09=09kobject_hotplug(&(*device)->kobj, KOBJ_ONLINE, NULL); =09} =09return_VALUE(0); } @@ -774,13 +774,13 @@ =09=09} =20 =09=09if (pr->id >=3D 0 && (pr->id < NR_CPUS)) { -=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE); +=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); =09=09=09break; =09=09} =20 =09=09result =3D acpi_processor_start(device); =09=09if ((!result) && ((pr->id >=3D0) && (pr->id < NR_CPUS))) { -=09=09=09kobject_hotplug(&device->kobj, KOBJ_ONLINE); +=09=09=09kobject_hotplug(&device->kobj, KOBJ_ONLINE, NULL); =09=09} else { =09=09=09ACPI_DEBUG_PRINT((ACPI_DB_ERROR, =09=09=09=09"Device [%s] failed to start\n", @@ -801,7 +801,7 @@ =09=09} =20 =09=09if ((pr->id < NR_CPUS) && (cpu_present(pr->id))) -=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE); +=09=09=09kobject_hotplug(&device->kobj, KOBJ_OFFLINE, NULL); =09=09break; =09default: =09=09ACPI_DEBUG_PRINT((ACPI_DB_INFO, =3D=3D=3D=3D=3D drivers/base/cpu.c 1.22 vs edited =3D=3D=3D=3D=3D --- 1.22/drivers/base/cpu.c=092005-01-31 01:33:46 -05:00 +++ edited/drivers/base/cpu.c=092005-03-19 01:39:16 -05:00 @@ -33,7 +33,7 @@ =09case '0': =09=09ret =3D cpu_down(cpu->sysdev.id); =09=09if (!ret) -=09=09=09kobject_hotplug(&dev->kobj, KOBJ_OFFLINE); +=09=09=09kobject_hotplug(&dev->kobj, KOBJ_OFFLINE, NULL); =09=09break; =09case '1': =09=09ret =3D cpu_up(cpu->sysdev.id); =3D=3D=3D=3D=3D drivers/base/firmware.c 1.9 vs edited =3D=3D=3D=3D=3D --- 1.9/drivers/base/firmware.c=092004-09-24 14:45:35 -04:00 +++ edited/drivers/base/firmware.c=092005-03-19 11:16:01 -05:00 @@ -14,21 +14,57 @@ =20 static decl_subsys(firmware, NULL, NULL); =20 +int post_timeout =3D 10; /* In seconds */ +EXPORT_SYMBOL_GPL(post_timeout); + int firmware_register(struct subsystem * s) { =09kset_set_kset_s(s, firmware_subsys); =09return subsystem_register(s); } +EXPORT_SYMBOL_GPL(firmware_register); =20 void firmware_unregister(struct subsystem * s) { =09subsystem_unregister(s); } +EXPORT_SYMBOL_GPL(firmware_unregister); + +/** + * post_timeout_store: + * Description: + *=09Sets the number of seconds to wait for the post/firmware load. + *=09Once this expires an error will be return to the driver and no + *=09firmware will be provided. + * + *=09Note: zero means 'wait for ever' + * + **/ +static ssize_t post_timeout_store(struct subsystem *subsys, const char *bu= f, size_t count) +{ +=09post_timeout =3D simple_strtol(buf, NULL, 10); +=09return count; +} +static ssize_t post_timeout_show(struct subsystem *subsys, char *buf) +{ +=09return sprintf(buf, "%d\n", post_timeout); +} +static struct subsys_attribute post_timeout_attr =3D { +=09.attr =3D {.name =3D "post_timeout", .mode =3D 0644, .owner =3D THIS_MO= DULE}, +=09.show =3D post_timeout_show, +=09.store =3D post_timeout_store +}; =20 int __init firmware_init(void) { -=09return subsystem_register(&firmware_subsys); +=09int error; +=09if ((error =3D subsystem_register(&firmware_subsys))) +=09=09return error; +=09 +=09if ((error =3D subsys_create_file(&firmware_subsys, &post_timeout_attr)= )) { +=09=09subsystem_unregister(&firmware_subsys); +=09=09return error; +=09} +=09return 0; } =20 -EXPORT_SYMBOL_GPL(firmware_register); -EXPORT_SYMBOL_GPL(firmware_unregister); =3D=3D=3D=3D=3D drivers/base/firmware_class.c 1.25 vs edited =3D=3D=3D=3D= =3D --- 1.25/drivers/base/firmware_class.c=092004-11-26 15:26:48 -05:00 +++ edited/drivers/base/firmware_class.c=092005-03-19 21:11:15 -05:00 @@ -1,7 +1,8 @@ /* - * firmware_class.c - Multi purpose firmware loading support + * firmware_class.c - Multi purpose post support * * Copyright (c) 2003 Manuel Estrada Sainz + * Copyright (c) 2005 Jon Smirl * * Please see Documentation/firmware_class/ for more information. * @@ -20,7 +21,7 @@ #include "base.h" =20 MODULE_AUTHOR("Manuel Estrada Sainz "); -MODULE_DESCRIPTION("Multi purpose firmware loading support"); +MODULE_DESCRIPTION("Multi purpose post support"); MODULE_LICENSE("GPL"); =20 enum { @@ -30,8 +31,6 @@ =09FW_STATUS_READY, }; =20 -static int loading_timeout =3D 10;=09/* In seconds */ - /* fw_lock could be moved to 'struct firmware_priv' but since it is just * guarding for corner cases a global lock should be OK */ static DECLARE_MUTEX(fw_lock); @@ -49,69 +48,41 @@ static inline void fw_load_abort(struct firmware_priv *fw_priv) { +=09printk(KERN_ERR "fw_load_abort\n"); =09set_bit(FW_STATUS_ABORT, &fw_priv->status); =09wmb(); =09complete(&fw_priv->completion); } =20 -static ssize_t -firmware_timeout_show(struct class *class, char *buf) -{ -=09return sprintf(buf, "%d\n", loading_timeout); -} - -/** - * firmware_timeout_store: - * Description: - *=09Sets the number of seconds to wait for the firmware. Once - *=09this expires an error will be return to the driver and no - *=09firmware will be provided. - * - *=09Note: zero means 'wait for ever' - * - **/ -static ssize_t -firmware_timeout_store(struct class *class, const char *buf, size_t count) -{ -=09loading_timeout =3D simple_strtol(buf, NULL, 10); -=09return count; -} - -static CLASS_ATTR(timeout, 0644, firmware_timeout_show, firmware_timeout_s= tore); - -static void fw_class_dev_release(struct class_device *class_dev); -int firmware_class_hotplug(struct class_device *dev, char **envp, -=09=09=09 int num_envp, char *buffer, int buffer_size); - -static struct class firmware_class =3D { -=09.name=09=09=3D "firmware", -=09.hotplug=09=3D firmware_class_hotplug, -=09.release=09=3D fw_class_dev_release, -}; - int -firmware_class_hotplug(struct class_device *class_dev, char **envp, +post_hotplug(struct kset *kset, struct kobject *kobj, char **envp, =09=09 int num_envp, char *buffer, int buffer_size) { -=09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); +=09struct device *dev =3D container_of(kobj, struct device, kobj); +=09struct firmware_priv *fw_priv =3D dev->post_data; =09int i =3D 0, len =3D 0; =20 =09if (!test_bit(FW_STATUS_READY, &fw_priv->status)) =09=09return -ENODEV; =20 -=09if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &len, -=09=09=09"FIRMWARE=3D%s", fw_priv->fw_id)) -=09=09return -ENOMEM; - +=09if (fw_priv->fw) { +=09=09if (add_hotplug_env_var(envp, num_envp, &i, buffer, +=09=09 buffer_size, &len, "FIRMWARE=3D%s", fw_priv->fw_id)) +=09=09=09return -ENOMEM; +=09} else { +=09=09if (add_hotplug_env_var(envp, num_envp, &i, buffer, +=09=09 buffer_size, &len, "POST=3D%s", fw_priv->fw_id)) +=09=09=09return -ENOMEM; +=09} =09envp[i] =3D NULL; =20 =09return 0; } =20 static ssize_t -firmware_loading_show(struct class_device *class_dev, char *buf) +post_status_show(struct device *dev, char *buf) { -=09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); +=09struct firmware_priv *fw_priv =3D dev->post_data; =09int loading =3D test_bit(FW_STATUS_LOADING, &fw_priv->status); =09return sprintf(buf, "%d\n", loading); } @@ -126,13 +97,13 @@ *=09-1: Conclude the load with an error and discard any written data. **/ static ssize_t -firmware_loading_store(struct class_device *class_dev, -=09=09 const char *buf, size_t count) +post_status_store(struct device *dev, const char *buf, size_t count) { -=09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); -=09int loading =3D simple_strtol(buf, NULL, 10); +=09struct firmware_priv *fw_priv =3D dev->post_data; +=09int status =3D simple_strtol(buf, NULL, 10); =20 -=09switch (loading) { +=09printk(KERN_ERR "post_status_store: status %d\n", status); +=09switch (status) { =09case 1: =09=09down(&fw_lock); =09=09vfree(fw_priv->fw->data); @@ -151,7 +122,7 @@ =09=09/* fallthrough */ =09default: =09=09printk(KERN_ERR "%s: unexpected value (%d)\n", __FUNCTION__, -=09=09 loading); +=09=09 status); =09=09/* fallthrough */ =09case -1: =09=09fw_load_abort(fw_priv); @@ -161,15 +132,14 @@ =09return count; } =20 -static CLASS_DEVICE_ATTR(loading, 0644, -=09=09=09firmware_loading_show, firmware_loading_store); +static DEVICE_ATTR(post_status, 0644, post_status_show, post_status_store)= ; =20 static ssize_t -firmware_data_read(struct kobject *kobj, -=09=09 char *buffer, loff_t offset, size_t count) +post_data_read(struct kobject *kobj,=20 +=09 char *buffer, loff_t offset, size_t count) { -=09struct class_device *class_dev =3D to_class_dev(kobj); -=09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); +=09struct device *dev =3D container_of(kobj, struct device, kobj); +=09struct firmware_priv *fw_priv =3D dev->post_data; =09struct firmware *fw; =09ssize_t ret_count =3D count; =20 @@ -191,6 +161,7 @@ =09up(&fw_lock); =09return ret_count; } + static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) { @@ -225,8 +196,8 @@ *=09the driver as a firmware image. **/ static ssize_t -firmware_data_write(struct kobject *kobj, -=09=09 char *buffer, loff_t offset, size_t count) +post_data_write(struct kobject *kobj,=20 +=09=09char *buffer, loff_t offset, size_t count) { =09struct class_device *class_dev =3D to_class_dev(kobj); =09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); @@ -254,124 +225,82 @@ =09return retval; } static struct bin_attribute firmware_attr_data_tmpl =3D { -=09.attr =3D {.name =3D "data", .mode =3D 0644, .owner =3D THIS_MODULE}, +=09.attr =3D {.name =3D "post_data", .mode =3D 0644, .owner =3D THIS_MODUL= E}, =09.size =3D 0, -=09.read =3D firmware_data_read, -=09.write =3D firmware_data_write, +=09.read =3D post_data_read, +=09.write =3D post_data_write, }; =20 static void -fw_class_dev_release(struct class_device *class_dev) -{ -=09struct firmware_priv *fw_priv =3D class_get_devdata(class_dev); - -=09kfree(fw_priv); -=09kfree(class_dev); - -=09module_put(THIS_MODULE); -} - -static void -firmware_class_timeout(u_long data) +post_timeout_abort(u_long data) { =09struct firmware_priv *fw_priv =3D (struct firmware_priv *) data; +=09printk(KERN_ERR "post_timeout_abort: time out\n"); =09fw_load_abort(fw_priv); } =20 -static inline void -fw_setup_class_device_id(struct class_device *class_dev, struct device *de= v) -{ -=09/* XXX warning we should watch out for name collisions */ -=09strlcpy(class_dev->class_id, dev->bus_id, BUS_ID_SIZE); -} - static int -fw_register_class_device(struct class_device **class_dev_p, -=09=09=09 const char *fw_name, struct device *device) +fw_register_device(const char *fw_name, struct device *device) { =09int retval; =09struct firmware_priv *fw_priv =3D kmalloc(sizeof (struct firmware_priv)= , =09=09=09=09=09=09GFP_KERNEL); -=09struct class_device *class_dev =3D kmalloc(sizeof (struct class_device)= , -=09=09=09=09=09=09 GFP_KERNEL); - -=09*class_dev_p =3D NULL; =20 -=09if (!fw_priv || !class_dev) { +=09if (!fw_priv) { =09=09printk(KERN_ERR "%s: kmalloc failed\n", __FUNCTION__); =09=09retval =3D -ENOMEM; =09=09goto error_kfree; =09} =09memset(fw_priv, 0, sizeof (*fw_priv)); -=09memset(class_dev, 0, sizeof (*class_dev)); =20 =09init_completion(&fw_priv->completion); =09fw_priv->attr_data =3D firmware_attr_data_tmpl; =09strlcpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX); =20 -=09fw_priv->timeout.function =3D firmware_class_timeout; +=09fw_priv->timeout.function =3D post_timeout_abort; =09fw_priv->timeout.data =3D (u_long) fw_priv; =09init_timer(&fw_priv->timeout); +=09 +=09device->post_data =3D fw_priv; =20 -=09fw_setup_class_device_id(class_dev, device); -=09class_dev->dev =3D device; -=09class_dev->class =3D &firmware_class; -=09class_set_devdata(class_dev, fw_priv); -=09retval =3D class_device_register(class_dev); -=09if (retval) { -=09=09printk(KERN_ERR "%s: class_device_register failed\n", -=09=09 __FUNCTION__); -=09=09goto error_kfree; -=09} -=09*class_dev_p =3D class_dev; =09return 0; =20 error_kfree: =09kfree(fw_priv); -=09kfree(class_dev); =09return retval; } =20 static int -fw_setup_class_device(struct firmware *fw, struct class_device **class_dev= _p, -=09=09 const char *fw_name, struct device *device) +fw_setup_device(struct firmware *fw, const char *fw_name, struct device *d= evice) { -=09struct class_device *class_dev; =09struct firmware_priv *fw_priv; =09int retval; =20 -=09*class_dev_p =3D NULL; -=09retval =3D fw_register_class_device(&class_dev, fw_name, device); +=09retval =3D fw_register_device(fw_name, device); =09if (retval) =09=09goto out; =20 -=09/* Need to pin this module until class device is destroyed */ -=09__module_get(THIS_MODULE); - -=09fw_priv =3D class_get_devdata(class_dev); - +=09fw_priv =3D device->post_data; =09fw_priv->fw =3D fw; -=09retval =3D sysfs_create_bin_file(&class_dev->kobj, &fw_priv->attr_data)= ; +=09 +=09retval =3D sysfs_create_bin_file(&device->kobj, &fw_priv->attr_data); =09if (retval) { =09=09printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", =09=09 __FUNCTION__); -=09=09goto error_unreg; +=09=09goto out; =09} =20 -=09retval =3D class_device_create_file(class_dev, -=09=09=09=09=09 &class_device_attr_loading); -=09if (retval) { -=09=09printk(KERN_ERR "%s: class_device_create_file failed\n", -=09=09 __FUNCTION__); -=09=09goto error_unreg; +=09if (fw) { +=09=09retval =3D device_create_file(device, &dev_attr_post_status); +=09=09if (retval) { +=09=09=09printk(KERN_ERR "%s: device_create_file failed\n", +=09=09=09 __FUNCTION__); +=09=09=09goto out; +=09=09} =09} - =09set_bit(FW_STATUS_READY, &fw_priv->status); -=09*class_dev_p =3D class_dev; =09goto out; =20 -error_unreg: -=09class_device_unregister(class_dev); out: =09return retval; } @@ -388,62 +317,79 @@ *=09should be distinctive enough not to be confused with any other *=09firmware image for this or any other device. **/ -int -request_firmware(const struct firmware **firmware_p, const char *name, +static int +request(const struct firmware **firmware_p, const char *name, =09=09 struct device *device) { -=09struct class_device *class_dev; =09struct firmware_priv *fw_priv; -=09struct firmware *firmware; +=09struct firmware *firmware =3D NULL; =09int retval; =20 -=09if (!firmware_p) -=09=09return -EINVAL; - -=09*firmware_p =3D firmware =3D kmalloc(sizeof (struct firmware), GFP_KERN= EL); -=09if (!firmware) { -=09=09printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", -=09=09 __FUNCTION__); -=09=09retval =3D -ENOMEM; -=09=09goto out; +=09if (firmware_p) { +=09=09*firmware_p =3D firmware =3D kmalloc(sizeof (struct firmware), GFP_K= ERNEL); +=09=09if (!firmware) { +=09=09=09printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", +=09=09=09 __FUNCTION__); +=09=09=09retval =3D -ENOMEM; +=09=09=09goto out; +=09=09} +=09=09memset(firmware, 0, sizeof (*firmware)); =09} -=09memset(firmware, 0, sizeof (*firmware)); =20 -=09retval =3D fw_setup_class_device(firmware, &class_dev, name, device); +=09retval =3D fw_setup_device(firmware, name, device); =09if (retval) =09=09goto error_kfree_fw; =20 -=09fw_priv =3D class_get_devdata(class_dev); +=09fw_priv =3D device->post_data; =20 -=09if (loading_timeout) { -=09=09fw_priv->timeout.expires =3D jiffies + loading_timeout * HZ; +=09if (post_timeout) { +=09=09fw_priv->timeout.expires =3D jiffies + post_timeout * HZ; =09=09add_timer(&fw_priv->timeout); =09} =20 -=09kobject_hotplug(&class_dev->kobj, KOBJ_ADD); +=09printk(KERN_ERR "request_firmware: hotplug event\n"); +=09kobject_hotplug(&device->kobj, KOBJ_POST, post_hotplug); =09wait_for_completion(&fw_priv->completion); =09set_bit(FW_STATUS_DONE, &fw_priv->status); +=09printk(KERN_ERR "request_firmware: complete\n"); =20 =09del_timer_sync(&fw_priv->timeout); =20 -=09down(&fw_lock); -=09if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) = { -=09=09retval =3D -ENOENT; -=09=09release_firmware(fw_priv->fw); -=09=09*firmware_p =3D NULL; +=09if (firmware_p) { +=09=09down(&fw_lock); +=09=09if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status= )) { +=09=09=09retval =3D -ENOENT; +=09=09=09release_firmware(fw_priv->fw); +=09=09=09*firmware_p =3D NULL; +=09=09} +=09=09fw_priv->fw =3D NULL; +=09=09up(&fw_lock); +=09 +=09=09sysfs_remove_bin_file(&device->kobj, &fw_priv->attr_data); =09} -=09fw_priv->fw =3D NULL; -=09up(&fw_lock); -=09class_device_unregister(class_dev); +=09device_remove_file(device, &dev_attr_post_status); +=09 =09goto out; =20 error_kfree_fw: -=09kfree(firmware); -=09*firmware_p =3D NULL; +=09if (firmware) { +=09=09kfree(firmware); +=09=09*firmware_p =3D NULL; +=09} out: =09return retval; } =20 +int +request_firmware(const struct firmware **firmware_p, const char *name, +=09=09 struct device *device) +{ +=09if (!firmware_p) +=09=09return -EINVAL; +=09return request(firmware_p, name, device); +} +EXPORT_SYMBOL(request_firmware); + /** * release_firmware: - release the resource associated with a firmware ima= ge **/ @@ -455,6 +401,7 @@ =09=09kfree(fw); =09} } +EXPORT_SYMBOL(release_firmware); =20 /** * register_firmware: - provide a firmware image for later usage @@ -472,6 +419,7 @@ =09 * decide if firmware caching is reasonable just leave it as a =09 * noop */ } +EXPORT_SYMBOL(register_firmware); =20 /* Async support */ struct firmware_work { @@ -480,11 +428,12 @@ =09const char *name; =09struct device *device; =09void *context; -=09void (*cont)(const struct firmware *fw, void *context); +=09void (*cont_fw)(const struct firmware *fw, void *context); +=09void (*cont_post)(void *context); }; =20 static int -request_firmware_work_func(void *arg) +request_post_work_func(void *arg) { =09struct firmware_work *fw_work =3D arg; =09const struct firmware *fw; @@ -492,10 +441,15 @@ =09=09WARN_ON(1); =09=09return 0; =09} -=09daemonize("%s/%s", "firmware", fw_work->name); -=09request_firmware(&fw, fw_work->name, fw_work->device); -=09fw_work->cont(fw, fw_work->context); -=09release_firmware(fw); +=09daemonize("%s/%s", "post", fw_work->name); +=09if (fw_work->cont_fw) { +=09=09request(&fw, fw_work->name, fw_work->device); +=09=09fw_work->cont_fw(fw, fw_work->context); +=09=09release_firmware(fw); +=09} else { +=09=09request(NULL, fw_work->name, fw_work->device); +=09=09fw_work->cont_post(fw_work->context); +=09} =09module_put(fw_work->module); =09kfree(fw_work); =09return 0; @@ -515,11 +469,12 @@ *=09@fw may be %NULL if firmware request fails. * **/ -int -request_firmware_nowait( +static int +request_nowait( =09struct module *module, =09const char *name, struct device *device, void *context, -=09void (*cont)(const struct firmware *fw, void *context)) +=09void (*cont_fw)(const struct firmware *fw, void *context), +=09void (*cont_post)(void *context)) { =09struct firmware_work *fw_work =3D kmalloc(sizeof (struct firmware_work)= , =09=09=09=09=09=09GFP_ATOMIC); @@ -537,47 +492,37 @@ =09=09.name =3D name, =09=09.device =3D device, =09=09.context =3D context, -=09=09.cont =3D cont, +=09=09.cont_fw =3D cont_fw, +=09=09.cont_post =3D cont_post, =09}; =20 -=09ret =3D kernel_thread(request_firmware_work_func, fw_work, +=09ret =3D kernel_thread(request_post_work_func, fw_work, =09=09=09 CLONE_FS | CLONE_FILES); =20 =09if (ret < 0) { -=09=09fw_work->cont(NULL, fw_work->context); +=09=09if (fw_work->cont_fw) +=09=09=09fw_work->cont_fw(NULL, fw_work->context); +=09=09if (fw_work->cont_post) +=09=09=09fw_work->cont_post(fw_work->context); =09=09return ret; =09} =09return 0; } =20 -static int __init -firmware_class_init(void) +int +request_firmware_nowait(struct module *module, const char *name, +=09=09=09struct device *device, void *context, +=09=09=09void (*cont_fw)(const struct firmware *fw, void *context)) { -=09int error; -=09error =3D class_register(&firmware_class); -=09if (error) { -=09=09printk(KERN_ERR "%s: class_register failed\n", __FUNCTION__); -=09=09return error; -=09} -=09error =3D class_create_file(&firmware_class, &class_attr_timeout); -=09if (error) { -=09=09printk(KERN_ERR "%s: class_create_file failed\n", -=09=09 __FUNCTION__); -=09=09class_unregister(&firmware_class); -=09} -=09return error; - +=09return request_nowait(module, name, device, context, cont_fw, NULL); } -static void __exit -firmware_class_exit(void) +EXPORT_SYMBOL(request_firmware_nowait); + +int +request_post_nowait(struct module *module, const char *name, +=09=09 struct device *device, void *context, +=09=09 void (*cont_post)(void *context)) { -=09class_unregister(&firmware_class); +=09return request_nowait(module, name, device, context, NULL, cont_post); } - -module_init(firmware_class_init); -module_exit(firmware_class_exit); - -EXPORT_SYMBOL(release_firmware); -EXPORT_SYMBOL(request_firmware); -EXPORT_SYMBOL(request_firmware_nowait); -EXPORT_SYMBOL(register_firmware); +EXPORT_SYMBOL(request_post_nowait); =3D=3D=3D=3D=3D drivers/video/aty/radeon_base.c 1.44 vs edited =3D=3D=3D=3D= =3D --- 1.44/drivers/video/aty/radeon_base.c=092005-03-10 03:39:11 -05:00 +++ edited/drivers/video/aty/radeon_base.c=092005-03-19 21:17:49 -05:00 @@ -71,6 +71,7 @@ #include #include #include +#include =20 #include #include @@ -2206,6 +2207,9 @@ =09.read=09=3D radeon_show_edid2, }; =20 +static void radeon_post_finished(void *data) { +=09printk(KERN_ERR "radeon_post_finished\n"); +} =20 static int radeonfb_pci_register (struct pci_dev *pdev, =09=09=09=09 const struct pci_device_id *ent) @@ -2410,6 +2414,8 @@ =09} #endif =20 +=09request_post_nowait(THIS_MODULE, "vbios.vm86", &pdev->dev, rinfo, radeo= n_post_finished); + =09printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name); =20 =09if (rinfo->bios_seg) @@ -2453,7 +2459,19 @@ if (!rinfo) return; =20 +=09/* Register some sysfs stuff (should be done better) */ +=09if (rinfo->mon1_EDID) +=09=09sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr); +=09if (rinfo->mon2_EDID) +=09=09sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr); + =09radeonfb_pm_exit(rinfo); + +=09/* Register some sysfs stuff (should be done better) */ +=09if (rinfo->mon1_EDID) +=09=09sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr); +=09if (rinfo->mon2_EDID) +=09=09sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr); =20 #if 0 =09/* restore original state =3D=3D=3D=3D=3D include/linux/device.h 1.138 vs edited =3D=3D=3D=3D=3D --- 1.138/include/linux/device.h=092005-03-09 12:03:56 -05:00 +++ edited/include/linux/device.h=092005-03-19 11:11:34 -05:00 @@ -271,6 +271,7 @@ =09void=09=09*driver_data;=09/* data private to the driver */ =09void=09=09*platform_data;=09/* Platform specific data (e.g. ACPI, =09=09=09=09=09 BIOS data relevant to device) */ +=09void=09=09*post_data;=09/* active during firmware load or post */ =09struct dev_pm_info=09power; =20 =09u32=09=09detach_state;=09/* State to enter when device is @@ -399,6 +400,7 @@ /* drivers/base/firmware.c */ extern int firmware_register(struct subsystem *); extern void firmware_unregister(struct subsystem *); +extern int post_timeout; /* In seconds */ =20 /* debugging and troubleshooting/diagnostic helpers. */ #define dev_printk(level, dev, format, arg...)=09\ =3D=3D=3D=3D=3D include/linux/firmware.h 1.3 vs edited =3D=3D=3D=3D=3D --- 1.3/include/linux/firmware.h=092005-02-02 04:49:28 -05:00 +++ edited/include/linux/firmware.h=092005-03-19 21:12:52 -05:00 @@ -1,20 +1,27 @@ #ifndef _LINUX_FIRMWARE_H #define _LINUX_FIRMWARE_H +#include #include #include + #define FIRMWARE_NAME_MAX 30=20 + struct firmware { =09size_t size; =09u8 *data; }; -struct device; + +int request_post_nowait(struct module *module, const char *name, +=09=09=09struct device *device, void *context, +=09=09=09void (*cont_post)(void *context)); + int request_firmware(const struct firmware **fw, const char *name, =09=09 struct device *device); -int request_firmware_nowait( -=09struct module *module, -=09const char *name, struct device *device, void *context, -=09void (*cont)(const struct firmware *fw, void *context)); - +int request_firmware_nowait(struct module *module, const char *name, +=09=09struct device *device, void *context,=20 +=09=09void (*cont_fw)(const struct firmware *fw, void *context)); void release_firmware(const struct firmware *fw); + void register_firmware(const char *name, const u8 *data, size_t size); + #endif =3D=3D=3D=3D=3D include/linux/kobject.h 1.39 vs edited =3D=3D=3D=3D=3D --- 1.39/include/linux/kobject.h=092005-03-09 12:04:09 -05:00 +++ edited/include/linux/kobject.h=092005-03-19 01:32:55 -05:00 @@ -242,13 +242,19 @@ extern void subsys_remove_file(struct subsystem * , struct subsys_attribut= e *); =20 #ifdef CONFIG_HOTPLUG -void kobject_hotplug(struct kobject *kobj, enum kobject_action action); +void kobject_hotplug(struct kobject *kobj, enum kobject_action action, +=09=09 int (*hotplug)(struct kset *kset, struct kobject *kobj, char **= envp, +=09=09 int num_envp, char *buffer, int buffer_size) +=09=09 ); int add_hotplug_env_var(char **envp, int num_envp, int *cur_index, =09=09=09char *buffer, int buffer_size, int *cur_len, =09=09=09const char *format, ...) =09__attribute__((format (printf, 7, 8))); #else -static inline void kobject_hotplug(struct kobject *kobj, enum kobject_acti= on action) { } +static inline void kobject_hotplug(struct kobject *kobj, enum kobject_acti= on action, +=09=09=09=09 int (*hotplug)(struct kset *kset, struct kobject *kobj, cha= r **envp, +=09=09=09=09 int num_envp, char *buffer, int buffer_size) +=09=09=09=09 ) { } static inline int add_hotplug_env_var(char **envp, int num_envp, int *cur_= index,=20 =09=09=09=09 char *buffer, int buffer_size, int *cur_len,=20 =09=09=09=09 const char *format, ...) =3D=3D=3D=3D=3D include/linux/kobject_uevent.h 1.6 vs edited =3D=3D=3D=3D= =3D --- 1.6/include/linux/kobject_uevent.h=092004-11-08 14:43:30 -05:00 +++ edited/include/linux/kobject_uevent.h=092005-03-17 10:36:00 -05:00 @@ -29,6 +29,7 @@ =09KOBJ_UMOUNT=09=3D (__force kobject_action_t) 0x05,=09/* umount event fo= r block devices */ =09KOBJ_OFFLINE=09=3D (__force kobject_action_t) 0x06,=09/* offline event = for hotplug devices */ =09KOBJ_ONLINE=09=3D (__force kobject_action_t) 0x07,=09/* online event fo= r hotplug devices */ +=09KOBJ_POST =09=3D (__force kobject_action_t) 0x08,=09/* post event suppo= rts user space initialization */ }; =20 =20 =3D=3D=3D=3D=3D lib/kobject.c 1.58 vs edited =3D=3D=3D=3D=3D --- 1.58/lib/kobject.c=092005-03-09 12:04:09 -05:00 +++ edited/lib/kobject.c=092005-03-19 01:39:37 -05:00 @@ -185,7 +185,7 @@ =09=09if (parent) =09=09=09kobject_put(parent); =09} else { -=09=09kobject_hotplug(kobj, KOBJ_ADD); +=09=09kobject_hotplug(kobj, KOBJ_ADD, NULL); =09} =20 =09return error; @@ -301,7 +301,7 @@ =20 void kobject_del(struct kobject * kobj) { -=09kobject_hotplug(kobj, KOBJ_REMOVE); +=09kobject_hotplug(kobj, KOBJ_REMOVE, NULL); =09sysfs_remove_dir(kobj); =09unlink(kobj); } =3D=3D=3D=3D=3D lib/kobject_uevent.c 1.18 vs edited =3D=3D=3D=3D=3D --- 1.18/lib/kobject_uevent.c=092005-01-08 00:44:13 -05:00 +++ edited/lib/kobject_uevent.c=092005-03-19 01:48:04 -05:00 @@ -44,6 +44,8 @@ =09=09return "offline"; =09case KOBJ_ONLINE: =09=09return "online"; +=09case KOBJ_POST: +=09=09return "post"; =09default: =09=09return NULL; =09} @@ -187,7 +189,9 @@ * @action: action that is happening (usually "ADD" or "REMOVE") * @kobj: struct kobject that the action is happening to */ -void kobject_hotplug(struct kobject *kobj, enum kobject_action action) +void kobject_hotplug(struct kobject *kobj, enum kobject_action action, +=09=09int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp, +=09=09int num_envp, char *buffer, int buffer_size)) { =09char *argv [3]; =09char **envp =3D NULL; @@ -279,6 +283,17 @@ =09if (hotplug_ops->hotplug) { =09=09/* have the kset specific function add its stuff */ =09=09retval =3D hotplug_ops->hotplug (kset, kobj, +=09=09=09=09 &envp[i], NUM_ENVP - i, scratch, +=09=09=09=09 BUFFER_SIZE - (scratch - buffer)); +=09=09if (retval) { +=09=09=09pr_debug ("%s - hotplug() returned %d\n", +=09=09=09=09 __FUNCTION__, retval); +=09=09=09goto exit; +=09=09} +=09} +=09if (hotplug) { +=09=09/* have the call specific function add on its stuff */ +=09=09retval =3D hotplug (kset, kobj, =09=09=09=09 &envp[i], NUM_ENVP - i, scratch, =09=09=09=09 BUFFER_SIZE - (scratch - buffer)); =09=09if (retval) { ------=_Part_936_23455848.1111291619503 Content-Type: application/octet-stream; name="30-post.hotplug" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="30-post.hotplug" IyEvYmluL3NoCiMKIyBGaXJtd2FyZS1zcGVjaWZpYyBob3RwbHVnIHBvbGljeSBhZ2VudC4KIwoj IEtlcm5lbCBmaXJtd2FyZSBob3RwbHVnIHBhcmFtcyBpbmNsdWRlOgojCiMgICAgICAgQUNUSU9O PSVzIFthZGQgb3IgcmVtb3ZlXQojICAgICAgIERFVlBBVEg9JXMgW2luIDIuNSBrZXJuZWxzLCAv c3lzLyRERVZQQVRIXQojICAgICAgIEZJUk1XQVJFPSVzCiMKIyBISVNUT1JZOgojCiMgMjQtSnVs LTIwMDMgICBJbml0aWFsIHZlcnNpb24gb2YgIm5ldyIgaG90cGx1ZyBhZ2VudC4KIwojICRJZDog ZmlybXdhcmUuYWdlbnQsdiAxLjMgMjAwNC8wMy8xNCAxNTo1Mjo1NiB1a2FpIEV4cCAkCiMKCmNk IC9ldGMvaG90cGx1ZwouIC4vaG90cGx1Zy5mdW5jdGlvbnMKIyBERUJVRz15ZXMgZXhwb3J0IERF QlVHCgojIGRpcmVjdG9yeSBvZiB0aGUgZmlybXdhcmUgZmlsZXMKRklSTVdBUkVfRElSPS9saWIv ZmlybXdhcmUKCiMgbW91bnRwb2ludCBvZiBzeXNmcwpTWVNGUz0kKHNlZCAtbiAncy9eLiogXChb XiBdKlwpIHN5c2ZzIC4qJC9cMS9wJyAvcHJvYy9tb3VudHMpCgojIHVzZSAvcHJvYyBmb3IgMi40 IGtlcm5lbHMKaWYgWyAiJFNZU0ZTIiA9ICIiIF07IHRoZW4KICAgIFNZU0ZTPS9wcm9jCmZpCgoj CiMgV2hhdCB0byBkbyB3aXRoIHRoaXMgZmlybXdhcmUgaG90cGx1ZyBldmVudD8KIwpjYXNlICIk QUNUSU9OIiBpbgoKcG9zdCkKICAgIGlmIFsgISAtZSAkU1lTRlMvJERFVlBBVEgvcG9zdF9zdGF0 dXMgXTsgdGhlbgogICAgICAgIHNsZWVwIDEKICAgIGZpCgogICAgaWYgWyAiJEZJUk1XQVJFIiAh PSAiIiBdOyB0aGVuCiAgICAgICAgaWYgWyAtZiAiJEZJUk1XQVJFX0RJUi8kRklSTVdBUkUiIF07 IHRoZW4KICAgICAgICAgICAgZWNobyAxID4gJFNZU0ZTLyRERVZQQVRIL3Bvc3Rfc3RhdHVzCiAg ICAgICAgICAgIGNwICIkRklSTVdBUkVfRElSLyRGSVJNV0FSRSIgJFNZU0ZTLyRERVZQQVRIL3Bv c3RfZGF0YQogICAgICAgICAgICBlY2hvIDAgPiAkU1lTRlMvJERFVlBBVEgvcG9zdF9zdGF0dXMK ICAgICAgICBlbHNlCiAgICAgICAgICAgIGVjaG8gLTEgPiAkU1lTRlMvJERFVlBBVEgvcG9zdF9z dGF0dXMKICAgICAgICBmaQogICAgZmkKICAgIGlmIFsgIiRQT1NUIiAhPSAiIiBdOyB0aGVuCgll Y2hvICJQb3N0aW5nISAkUE9TVCIgPi9wb3N0CiAgICAgICAgZWNobyAxID4gJFNZU0ZTLyRERVZQ QVRIL3Bvc3Rfc3RhdHVzCiAgICAgICAgZXhlYyAkUE9TVCAiJEAiCiAgICAgICAgZWNobyAwID4g JFNZU0ZTLyRERVZQQVRIL3Bvc3Rfc3RhdHVzCgllY2hvICJQb3N0ZWQhICRQT1NUIiA+Pi9wb3N0 CiAgICBmaQogICAgOzsKCiopCiAgICA7OwoKZXNhYwo= ------=_Part_936_23455848.1111291619503-- ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel