* 5 component for device model
- the device model core -> defines a set of structures and functions
- 'include/linux/device.h', 'drivers/base/*.c'
- the generic bus drivers
- bus / struct bus_type / bus_register(), bus_unregister()
- the bus controller drivers
- device / struct device / device_register(), device_unregister()
- the device drivers
- driver / sturce device_driver / driver_register(), driver_unregister()
- the class drivers
- class / struct class / class_register(), class_unregister()
* Device Model Core
- 'struct bus_type' : Represents busses(PCI, USB, I2C, etc.)
- 'struct device' : Represents devices(Intel AC97 audio controller, Intel PRO/100 ethernet controller, a PS/2 mouse, etc.)
- 'struct device_driver' : Represents kernel drivers that handle devices
- 'struct class ' : Represents a class of devices(sound, input, graphics, etc.)
- 'include/linux/device.h', 'drivers/base/*.c'
* device_register() : 한 device에 대해 맞는 driver들을 검색
* driver_register() : 한 driver에 대해 맞는 device들을 검색
* Generic Bus Drivers
- kernel이 지원하는 모든 bus마다 generic bus driver가 있다. Generic bus driver는 sturct bus_type을 allocate하고 bus_register()를 써서 kernel의 bus type list에 register한다.
- bus_type structure
- name (string)
- !klist_devices (klist)
- !klist_driver (klist)
- match (fp)
- suspend (fp)
- resume (fp)
- klist_devices는 이 bus에 존재하는 device들의 list, Bus controller driver가 device_register()를 호출함에 의해 update 됨.
- Bus controller driver는 system initialization 시 bus를 scan해서 어떤 device들이 있는지 check한 뒤 각 device마다 device_register()를 호출해서 klist_devices를 scan해서 맞는 driver (match() 이용)를 찾는다. 그런 뒤 device를 klist_devices에 update한다.
- Bus controller driver는 또한 gadget이 hot plugged 되었을 때(어떤 device인지 확인한 뒤) device_register()를 호출해서 klist_drivers를 scan해서 각 device 마다 맞는 driver( match() 이용 )를 찾는다. 그런뒤 device를 klist_devices에 update 한다.
- klist_driver는 이 bus에 존재하는 device들을 handle할 수 있는 driver들의 list, Device driver가 스스로 initialization 할 때, driver_register()를 호출하여 자신을 등록함으로써 갱신된다.
- Device Driver가 kernel에 inserted 되면, 이 driver는 driver_register()를 호출하여 해당 bus에 대해 klist_devices를 scan하여 이 driver가 다룰 수 있는 device들을 찾는다. 그런 뒤 driver를 klist_drivers에 update 한다.
- match()에 의해 device와 driver가 associated 되는 것을 binding이라고 한다.
- ex) 'drivers/net/phy/mdio_bus.c'
struct bus_type mdio_bus_type = {
. name = "mdio_bus",
.match = mdio_bus_match,
.suspend = mdio_bus_suspend,
.resume = mdio_bus_resume,
};
. name = "mdio_bus",
.match = mdio_bus_match,
.suspend = mdio_bus_suspend,
.resume = mdio_bus_resume,
};
* '!' is internal to the device motel core and should not be touched by the bus controller driver directly.
* Bus Controller Drivers
- Bus의 device driver다. 따라서, 여느 device drivers와 마찬가지로 자신을 driver_register()로 등록함. 그러나 추가적으로 자신이 다루는 bus 상에 있는 devices를 detect하여 device_register()를 이용해 등록한다. bus_type 구조체의 klist_devices list에.
- 새로운 Linux device driver model에서 모든 device는 bus 상에 존재하므로, 결국 bus controller driver가 모든 device를 등록한다. struct device 형태로. bus_type 구조체의 klist_devices list에.
- device
- bus_id (string)
- bus (bus_type)
- parent (device)
- !driver(device_driver)
- 'drivers/net/gianfar_mii.c'
* Device Drivers
- 모든 device driver는, driver_register()를 호출해 bus_type 구조체의 klist_driver list에 자기 자신을 등록한다. 그 다음에 device model core가 이 driver를 한 device와 binding을 시도함.
- 한 device가 registered 되면 (이는 곧 이 device를 handle할 수 있는 drivers가 klist_drivers에 등록된다는 말이므로) 한 특정 driver에 의해 handled 될 수 있는데, 그 driver의 probe member가 하는 일이 바로 그 특정 device 하나를 위해 이 driver의 한 instance를 생성해내는 (그리고 그 device를 초기화하는) 일이다.
- device_driver
- bus (bus_type)
- probe (fp)
- remove (fp)
- suspend (fp)
- resume (fp)
- bus는 이 driver가 등록될 klist_drivers를 가진 bus_type 구조체에 대한 pointer.
- probe는, 이 driver가 지원하는 device가 detected (이는 곧 device를 지원하는 drivers를 klist_drivers에서 찾아내는 일을 한 것 즉, binded) 될 때마다 불리는 callback function. 이 함수는 driver 자신을 각 device 당 하나 씩 instantiate한 뒤 그 device를 initialize 한다.
- remove는 이 driver를 그 device로부터 unbind하기 위해 불리는 callback function. Unbinding은 device가 physically removed 되거나 driver가 unloaded 되거나 system이 shutdown 될 때 일어난다.
- 'drivers/net/phy/'
* Class Drivers
- Class driver는 그것이 표현하는 device class들에 대해 struct class를 instantiate하여 class_register()를 통해 device model core에 등록한다.
- Devices를 적당한 class에 추가하는 것은 각 해당 device driver의 책임이다.
- class
- name (string)
- !devices (list)
- devices는 이 class에 속한 device들의 list이다. 이 list는 device driver들에 의해 갱신된다. (그 device driver들이 자기 자신들을 각 device들에 대해 instantiate할 때).
* Conclusion
- 결국 이런 data structure들이 있음으로 해서, device들이 어떻게 tree 구조를 이루고 있는지 알 수 있고, 어떤 종류의 device들이 system에 존재하는지도 알 수 있다.
- 그 효과는 더 나은 power management, 그리고 system에 연결된 devices에 대한 더 나은 통찰.
출처 : 블로그
이 내용을 어느 블로그에서 얻은 것인지 알수 있을까요?
답글삭제이 내용의 출처를 알수 없을까요?
답글삭제죄송합니다. 답변이 늦었습니다. 제가 이 블로그는 관리를 안해서 이제야 확인했습니다.
삭제글 제일 아래에 "출처" 라고 링크를 달았는데, 안보이시나봐요(ㅜㅜ) 아래 URL에서 가져왔습니다.
트랙백: http://ye-not-guilty.blogspot.kr/2010/02/linux-26-device-model.html
트랙백의 트랙백: http://bravegnu.org/device-model/device-model.txt