1
Chapter 6
Device Drivers
2
● File Type
● From App to Device
● Driver Registration
● Hotplug
● MMC Size & Partitions
● Request Queue & Elevator
3
File Type
*. 只有 type 為 b/c 的稱為 device file
*. type/major/minor 決定唯一 device
type major/minor
block device
mmc
可以存取任意位置
bl...
4
From App to Device
vfs
執行預設 operations 裡的 open
1. 從 type 對應 table 根據 major/minor
找 driver 註冊的 cdev
2. 執行 cdev 自帶的 open( ...
5
From App to Device
user space
kernel space
.open
.llseek
.open
.llseek
.read
.write
.mmap
...
c device file
.open
.relea...
8
Driver Registration
1. 準備 cdev & operations
2. 註冊 region(major/minor)
(3. 註冊 hotplug 機制 , for probe)
1. 註冊 hotplug 機制 , ...
10
Hotplug
bus
usb
driver
mmc
driver
usb
device
sd
driver
match
fail
match
fail
match
pass
進行 probe
*. 這邊的 device, 是 kerne...
11
Hotplug
bus
usb
driver
mmc
driver
usb
device
sd
driver
mmc
device
match
pass
進行 probe
1. 註冊 hotplug 機制 , for probe
----...
14
MMC Size & Partitions
partition
info
operations
gendisk
p0
noop
elevator
queue
request
queue
.request_fn
.make_request_...
15
MMC Size & Partitions
sector
0
3
2
1
13
name = “MBOOT”
start_block = 4096
block_count = 6144
name = “RTPM”
start_block ...
16
MMC Size & Partitions
noop
elevator
queue
request
queue
.request_fn
.make_request_fn
partition
table
partition
info
p1
...
22
Request Queue & Elevator
bio request
task plug
plug
elevator queue request queue
cfq usb disk A
deadline usb disk B
noo...
23
Request Queue & Elevator
task plug
noop emmc
bio
plug
.make_request_fn: 把 bio 串入 plug/queue
.request_fn:
把 rq 從 request...
24
Request Queue & Elevator
task plug
noop emmc
bio
1. if plug
嘗試合併到 task plug 的 request
plug
25
Request Queue & Elevator
task plug
noop emmc
bio
1. if plug
嘗試合併到 task plug 的 request
2. 嘗試合併到
elevator queue 的 request...
26
Request Queue & Elevator
request
3. 包裝成 request
noop emmc
task plug
plug
elevator queue request queue
27
Request Queue & Elevator
request
3. 包裝成 request
4. if plug, 串入 task plug
noop emmc
task plug
plug
elevator queue reques...
28
Request Queue & Elevator
request
3. 包裝成 request
4. if plug, 串入 task plug
5. 串入 elevator queue
( 或 request queue)
執行 dri...
29
Request Queue & Elevator
task plug
elevator queue request queue
cfq usb disk A
deadline usb disk B
noop emmc
30
Request Queue & Elevator
task plug
elevator queue request queue
cfq usb disk A
deadline usb disk B
noop emmc
執行 driver
...
31
Request Queue & Elevator
task plug
elevator queue request queue
cfq usb disk A
deadline usb disk B
noop emmc
執行 driver
...
32
Request Queue & Elevator
task plug
elevator queue request queue
cfq usb disk A
deadline usb disk B
noop emmc
執行 driver
...
33
Request Queue & Elevator
request queue
page
frame
page
frame
34
Request Queue & Elevator
request queue
mmc driver 把 request(read/write/...) 轉成 cmd 組合
page
frame
page
frame
35
Request Queue & Elevator
request queue
mmc driver 把 request(read/write/...) 轉成 cmd 組合
敲 fcie register
透過 host 發送 protoc...
36
Request Queue & Elevator
request queue
mmc driver
mmc device
把 request(read/write/...) 轉成 cmd 組合
敲 fcie register
透過 hos...
Prochain SlideShare
Chargement dans…5
×

ch6-pv2-device-drivers

211 vues

Publié le

0 commentaire
0 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Aucun téléchargement
Vues
Nombre de vues
211
Sur SlideShare
0
Issues des intégrations
0
Intégrations
11
Actions
Partages
0
Téléchargements
3
Commentaires
0
J’aime
0
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

ch6-pv2-device-drivers

  1. 1. 1 Chapter 6 Device Drivers
  2. 2. 2 ● File Type ● From App to Device ● Driver Registration ● Hotplug ● MMC Size & Partitions ● Request Queue & Elevator
  3. 3. 3 File Type *. 只有 type 為 b/c 的稱為 device file *. type/major/minor 決定唯一 device type major/minor block device mmc 可以存取任意位置 block data 會被 cache 在 memory b 沒特別意義 分區 character device ir, uart 不行存取任意位置 byte data 不被 cache 在 memory c 類型 (e.g. memory) 子類型 (e.g. null/zero) e.g. data 存取 transfer unit 保留 data type 白 major 白 minor
  4. 4. 4 From App to Device vfs 執行預設 operations 裡的 open 1. 從 type 對應 table 根據 major/minor 找 driver 註冊的 cdev 2. 執行 cdev 自帶的 open( ) app lib syscall filesystem 準備 inode & 安裝預設 operations open device file glibc/bionic sys_open do_sys_open user space kernel space open( ) cdev
  5. 5. 5 From App to Device user space kernel space .open .llseek .open .llseek .read .write .mmap ... c device file .open .release .llseek .read .write .unlocked_ioctl ... .open .release .ioctl ... b device file default operations driver default operations driver (partial)
  6. 6. 8 Driver Registration 1. 準備 cdev & operations 2. 註冊 region(major/minor) (3. 註冊 hotplug 機制 , for probe) 1. 註冊 hotplug 機制 , for probe ----- probe 之後 ----- 2. 準備 gendisk & operations & request queue & elevator 3. 註冊 region(major/minor) & add partition open( ) read( ) write( ) cdev 0 1 254 cdev_map open( ) read( ) write( ) cdev open( ) read( ) write( ) cdev 0 1 254 bdev_map open( ) read( ) write( ) gendisk open( ) read( ) write( ) gendisk request queue request queue elevator elevator minor minor major major
  7. 7. 10 Hotplug bus usb driver mmc driver usb device sd driver match fail match fail match pass 進行 probe *. 這邊的 device, 是 kernel 內部自用的 struct 沒有 major/minor 概念
  8. 8. 11 Hotplug bus usb driver mmc driver usb device sd driver mmc device match pass 進行 probe 1. 註冊 hotplug 機制 , for probe ----- probe 之後 ----- 2. 準備 gendisk & operations & request queue & elevator 3. 註冊 region(major/minor) & add partition
  9. 9. 14 MMC Size & Partitions partition info operations gendisk p0 noop elevator queue request queue .request_fn .make_request_fn partition table 1. 註冊 hotplug 機制 , for probe ----- probe 之後 ----- 2. 準備 gendisk & operations & request queue & elevator 3. 註冊 region(major/minor) & add partition
  10. 10. 15 MMC Size & Partitions sector 0 3 2 1 13 name = “MBOOT” start_block = 4096 block_count = 6144 name = “RTPM” start_block = 907264 block_count = 512 14 magic not match name = “MPOOL” start_block = 10240 block_count = 4096 MPOOL MBOOT partition table KL RFS customer MSLIB APP customerbackup CONFIG certificate tee RTPM oad 7G 443M
  11. 11. 16 MMC Size & Partitions noop elevator queue request queue .request_fn .make_request_fn partition table partition info p1 partition info p2 partition info p13 .start_sect .nr_sects bdev partition info operations gendisk p0 1. 註冊 hotplug 機制 , for probe ----- probe 之後 ----- 2. 準備 gendisk & operations & request queue & elevator 3. 註冊 region(major/minor) & add partition 0 1 254 bdev_map open( ) read( ) write( ) gendisk open( ) read( ) write( ) gendisk request queue request queue elevator elevator
  12. 12. 22 Request Queue & Elevator bio request task plug plug elevator queue request queue cfq usb disk A deadline usb disk B noop emmc
  13. 13. 23 Request Queue & Elevator task plug noop emmc bio plug .make_request_fn: 把 bio 串入 plug/queue .request_fn: 把 rq 從 request_queue 取出 交給 driver 處理 ( 先 drain) .request_fn .make_request_fn
  14. 14. 24 Request Queue & Elevator task plug noop emmc bio 1. if plug 嘗試合併到 task plug 的 request plug
  15. 15. 25 Request Queue & Elevator task plug noop emmc bio 1. if plug 嘗試合併到 task plug 的 request 2. 嘗試合併到 elevator queue 的 requestplug
  16. 16. 26 Request Queue & Elevator request 3. 包裝成 request noop emmc task plug plug elevator queue request queue
  17. 17. 27 Request Queue & Elevator request 3. 包裝成 request 4. if plug, 串入 task plug noop emmc task plug plug elevator queue request queue
  18. 18. 28 Request Queue & Elevator request 3. 包裝成 request 4. if plug, 串入 task plug 5. 串入 elevator queue ( 或 request queue) 執行 driver 處理 request queue noop emmc task plug plug elevator queue request queue
  19. 19. 29 Request Queue & Elevator task plug elevator queue request queue cfq usb disk A deadline usb disk B noop emmc
  20. 20. 30 Request Queue & Elevator task plug elevator queue request queue cfq usb disk A deadline usb disk B noop emmc 執行 driver 處理 request
  21. 21. 31 Request Queue & Elevator task plug elevator queue request queue cfq usb disk A deadline usb disk B noop emmc 執行 driver 處理 request
  22. 22. 32 Request Queue & Elevator task plug elevator queue request queue cfq usb disk A deadline usb disk B noop emmc 執行 driver 處理 request
  23. 23. 33 Request Queue & Elevator request queue page frame page frame
  24. 24. 34 Request Queue & Elevator request queue mmc driver 把 request(read/write/...) 轉成 cmd 組合 page frame page frame
  25. 25. 35 Request Queue & Elevator request queue mmc driver 把 request(read/write/...) 轉成 cmd 組合 敲 fcie register 透過 host 發送 protocol(cmd + data) page frame page frame mstar fcie host mstar fcie driver
  26. 26. 36 Request Queue & Elevator request queue mmc driver mmc device 把 request(read/write/...) 轉成 cmd 組合 敲 fcie register 透過 host 發送 protocol(cmd + data) 根據收到 protocol 執行 cmd 達成 request(read/write/...) read: storage --> dram write: dram --> storage 其它 , flush/discard/write_same/zeroout/... page frame page frame rw rw mstar fcie host mstar fcie driver cmddata

×