Skip to content

Commit a77ce81

Browse files
committed
driver core: Add ability for arch code to setup pdev_archdata
On some architectures we need to setup pdev_archdata before we add the device. Waiting til a bus_notifier is too late since we might need the pdev_archdata in the bus notifier. One example is setting up of dma_mask pointers such that it can be used in a bus_notifier. We add weak noop version of arch_setup_pdev_archdata() and allow the arch code to override with access the full definitions of struct device, struct platform_device, and struct pdev_archdata. Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
1 parent 3160b09 commit a77ce81

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎drivers/base/platform.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ struct device platform_bus = {
3131
};
3232
EXPORT_SYMBOL_GPL(platform_bus);
3333

34+
/**
35+
* arch_setup_pdev_archdata - Allow manipulation of archdata before its used
36+
* @dev: platform device
37+
*
38+
* This is called before platform_device_add() such that any pdev_archdata may
39+
* be setup before the platform_notifier is called. So if a user needs to
40+
* manipulate any relevant information in the pdev_archdata they can do:
41+
*
42+
* platform_devic_alloc()
43+
* ... manipulate ...
44+
* platform_device_add()
45+
*
46+
* And if they don't care they can just call platform_device_register() and
47+
* everything will just work out.
48+
*/
49+
void __weak arch_setup_pdev_archdata(struct platform_device *pdev)
50+
{
51+
}
52+
3453
/**
3554
* platform_get_resource - get a resource for a device
3655
* @dev: platform device
@@ -173,6 +192,7 @@ struct platform_device *platform_device_alloc(const char *name, int id)
173192
pa->pdev.id = id;
174193
device_initialize(&pa->pdev.dev);
175194
pa->pdev.dev.release = platform_device_release;
195+
arch_setup_pdev_archdata(&pa->pdev);
176196
}
177197

178198
return pa ? &pa->pdev : NULL;
@@ -334,6 +354,7 @@ EXPORT_SYMBOL_GPL(platform_device_del);
334354
int platform_device_register(struct platform_device *pdev)
335355
{
336356
device_initialize(&pdev->dev);
357+
arch_setup_pdev_archdata(pdev);
337358
return platform_device_add(pdev);
338359
}
339360
EXPORT_SYMBOL_GPL(platform_device_register);

‎include/linux/platform_device.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern void platform_device_unregister(struct platform_device *);
4242
extern struct bus_type platform_bus_type;
4343
extern struct device platform_bus;
4444

45+
extern void arch_setup_pdev_archdata(struct platform_device *);
4546
extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
4647
extern int platform_get_irq(struct platform_device *, unsigned int);
4748
extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);

0 commit comments

Comments
 (0)