Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
7b5eb7a9
Commit
7b5eb7a9
authored
Sep 26, 2002
by
Greg Kroah-Hartman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hotplug support to the driver core for devices, if their bus type supports it.
parent
82ba39ba
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
0 deletions
+123
-0
drivers/base/Makefile
drivers/base/Makefile
+2
-0
drivers/base/base.h
drivers/base/base.h
+10
-0
drivers/base/core.c
drivers/base/core.c
+6
-0
drivers/base/hotplug.c
drivers/base/hotplug.c
+103
-0
include/linux/device.h
include/linux/device.h
+2
-0
No files found.
drivers/base/Makefile
View file @
7b5eb7a9
...
...
@@ -6,6 +6,8 @@ obj-y := core.o sys.o interface.o power.o bus.o \
obj-y
+=
fs/
obj-$(CONFIG_HOTPLUG)
+=
hotplug.o
export-objs
:=
core.o power.o sys.o bus.o driver.o
\
class.o intf.o platform.o cpu.o
...
...
drivers/base/base.h
View file @
7b5eb7a9
...
...
@@ -50,3 +50,13 @@ extern void interface_remove(struct device_class *, struct device *);
extern
int
driver_attach
(
struct
device_driver
*
drv
);
extern
void
driver_detach
(
struct
device_driver
*
drv
);
#ifdef CONFIG_HOTPLUG
extern
int
dev_hotplug
(
struct
device
*
dev
,
const
char
*
action
);
#else
static
inline
int
dev_hotplug
(
struct
device
*
dev
,
const
char
*
action
)
{
return
0
;
}
#endif
drivers/base/core.c
View file @
7b5eb7a9
...
...
@@ -200,6 +200,9 @@ int device_register(struct device *dev)
if
(
platform_notify
)
platform_notify
(
dev
);
/* notify userspace of device entry */
dev_hotplug
(
dev
,
"add"
);
register_done:
if
(
error
)
{
spin_lock
(
&
device_lock
);
...
...
@@ -255,6 +258,9 @@ void put_device(struct device * dev)
if
(
platform_notify_remove
)
platform_notify_remove
(
dev
);
/* notify userspace that this device is about to disappear */
dev_hotplug
(
dev
,
"remove"
);
device_detach
(
dev
);
bus_remove_device
(
dev
);
...
...
drivers/base/hotplug.c
0 → 100644
View file @
7b5eb7a9
/*
* drivers/base/hotplug.c - hotplug call code
*
* Copyright (c) 2000-2001 David Brownell
* Copyright (c) 2002 Greg Kroah-Hartman
* Copyright (c) 2002 IBM Corp.
*
* Based off of drivers/usb/core/usb.c:call_agent(), which was
* written by David Brownell.
*
*/
#define DEBUG 0
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/kmod.h>
#include <linux/interrupt.h>
#include "base.h"
/*
* hotplugging invokes what /proc/sys/kernel/hotplug says (normally
* /sbin/hotplug) when devices get added or removed.
*
* This invokes a user mode policy agent, typically helping to load driver
* or other modules, configure the device, and more. Drivers can provide
* a MODULE_DEVICE_TABLE to help with module loading subtasks.
*/
#define BUFFER_SIZE 1024
/* should be enough memory for the env */
#define NUM_ENVP 32
/* number of env pointers */
int
dev_hotplug
(
struct
device
*
dev
,
const
char
*
action
)
{
char
*
argv
[
3
],
**
envp
,
*
buffer
,
*
scratch
;
int
retval
;
int
i
=
0
;
pr_debug
(
"%s
\n
"
,
__FUNCTION__
);
if
(
!
dev
)
return
-
ENODEV
;
if
(
!
dev
->
bus
||
!
dev
->
bus
->
hotplug
)
return
-
ENODEV
;
if
(
!
hotplug_path
[
0
])
return
-
ENODEV
;
if
(
in_interrupt
())
{
pr_debug
(
"%s - in_interrupt, not allowed!"
,
__FUNCTION__
);
return
-
EIO
;
}
if
(
!
current
->
fs
->
root
)
{
/* don't try to do anything unless we have a root partition */
pr_debug
(
"%s - %s -- no FS yet
\n
"
,
__FUNCTION__
,
action
);
return
-
EIO
;
}
envp
=
(
char
**
)
kmalloc
(
NUM_ENVP
*
sizeof
(
char
*
),
GFP_KERNEL
);
if
(
!
envp
)
return
-
ENOMEM
;
buffer
=
kmalloc
(
BUFFER_SIZE
,
GFP_KERNEL
);
if
(
!
buffer
)
{
kfree
(
envp
);
return
-
ENOMEM
;
}
/* only one standardized param to hotplug command: the bus name */
argv
[
0
]
=
hotplug_path
;
argv
[
1
]
=
dev
->
bus
->
name
;
argv
[
2
]
=
0
;
/* minimal command environment */
envp
[
i
++
]
=
"HOME=/"
;
envp
[
i
++
]
=
"PATH=/sbin:/bin:/usr/sbin:/usr/bin"
;
scratch
=
buffer
;
/* action: add, remove */
envp
[
i
++
]
=
scratch
;
scratch
+=
sprintf
(
scratch
,
"ACTION=%s"
,
action
)
+
1
;
/* have the bus specific function set up the rest of the environment */
retval
=
dev
->
bus
->
hotplug
(
dev
,
&
envp
[
i
],
NUM_ENVP
-
i
,
scratch
,
BUFFER_SIZE
-
(
scratch
-
buffer
));
if
(
retval
)
{
pr_debug
(
"%s - hotplug() returned %d
\n
"
,
__FUNCTION__
,
retval
);
goto
exit
;
}
pr_debug
(
"%s: %s %s %s %s %s %s
\n
"
,
__FUNCTION__
,
argv
[
0
],
argv
[
1
],
action
,
envp
[
0
],
envp
[
1
],
envp
[
2
]);
retval
=
call_usermodehelper
(
argv
[
0
],
argv
,
envp
);
if
(
retval
)
pr_debug
(
"%s - call_usermodehelper returned %d
\n
"
,
__FUNCTION__
,
retval
);
exit:
kfree
(
buffer
);
kfree
(
envp
);
return
retval
;
}
include/linux/device.h
View file @
7b5eb7a9
...
...
@@ -67,6 +67,8 @@ struct bus_type {
int
(
*
match
)(
struct
device
*
dev
,
struct
device_driver
*
drv
);
struct
device
*
(
*
add
)
(
struct
device
*
parent
,
char
*
bus_id
);
int
(
*
hotplug
)
(
struct
device
*
dev
,
char
**
envp
,
int
num_envp
,
char
*
buffer
,
int
buffer_size
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment