赞
踩
虚拟终端(/dev/tty*)
当用户登录时,使用的是虚拟终端。使用Ctcl+Alt+[F1—F6]组合键时,我们就可以切换到tty1、tty2、tty3等上面去。此时显示器的内容发生了变化,那这个和显卡驱动,是如何关联的?
事实上,我们切换的时候需要调用到显卡驱动中的接口,重新设置显示器的输出,也就是定位到不同的显存内容,并且原理的显存应该保留,以便切换回来后依然是原来的内容。
显示器的终端驱动drivers/tty/vt/vt.c:
切换的试过键盘接收到中断,调用vt驱动中的schedule_console_callback.启动工作项。
- void schedule_console_callback(void)
- {
- schedule_work(&console_work);
- }
static DECLARE_WORK(console_work, console_callback);
从键盘输入ctrl_alt_fN 发生的dump_stack:
(关于键盘驱动可参考Linux input系统数据上报流程【转】 - sky-heaven - 博客园 (cnblogs.com))
- [ 754.930558] ===schedule_console_callback
- [ 754.930560] CPU: 6 PID: 1440 Comm: kworker/6:1 Not tainted 4.19.152+ #19
- [ 754.930561] Hardware name: PHYTIUM LTD D2000/D2000, BIOS
- [ 754.930563] Workqueue: events console_callback
- [ 754.930564] Call trace:
- [ 754.930565] dump_backtrace+0x0/0x198
- [ 754.930566] show_stack+0x24/0x30
- [ 754.930568] dump_stack+0x9c/0xd0
- [ 754.930569] schedule_console_callback+0x20/0x44
- [ 754.930570] kbd_event+0xc0/0x4b8
- [ 754.930572] input_to_handler+0xf0/0x118
- [ 754.930573] input_pass_values.part.2+0x130/0x148
- [ 754.930575] input_handle_event+0x114/0x548
- [ 754.930576] input_event+0x7c/0xb0
- [ 754.930578] hidinput_report_event+0x4c/0x68
- [ 754.930579] hid_report_raw_event+0x210/0x400
- [ 754.930581] hid_input_report+0x104/0x1b0
- [ 754.930582] hid_irq_in+0x94/0x230
- [ 754.930584] __usb_hcd_giveback_urb+0x7c/0x138
- [ 754.930585] usb_hcd_giveback_urb+0x168/0x188
- [ 754.930587] xhci_giveback_urb_in_irq.isra.22+0x98/0x160
- [ 754.930589] xhci_td_cleanup+0x118/0x1a8
- [ 754.930591] finish_td+0xf8/0x130
- [ 754.930592] handle_tx_event+0x24c/0x11b8
- [ 754.930594] xhci_irq+0x1fc/0x4a0
- [ 754.930596] xhci_msi_irq+0x20/0x118
- [ 754.930597] __handle_irq_event_percpu+0x78/0x248
- [ 754.930599] handle_irq_event_percpu+0x40/0x98
- [ 754.930601] handle_irq_event+0x50/0xd0
- [ 754.930602] handle_fasteoi_irq+0xd4/0x1a8
- [ 754.930604] generic_handle_irq+0x34/0x50
- [ 754.930606] __handle_domain_irq+0x6c/0xc0
- [ 754.930607] gic_handle_irq+0x84/0x180
- [ 754.930608] el1_irq+0xb0/0x140
- [ 754.930610] console_unlock+0x374/0x590
- [ 754.930611] console_callback+0xa4/0x158
- [ 754.930613] process_one_work+0x1ac/0x3e0
- [ 754.930614] worker_thread+0x44/0x448
- [ 754.930616] kthread+0x130/0x138
- [ 754.930617] ret_from_fork+0x10/0x18
后续内容和drm驱动相关的dump_stack:
1:创建agetty程序时通过console_callback,系统起来的时候没有agetty。切换的时候tty驱动会创建该进程:
- [ 220.466929] ===ast_primary_plane_helper_atomic_check
- [ 220.466935] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.466937] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.466950] Workqueue: events console_callback
- [ 220.466953] Call trace:
- [ 220.466958] dump_backtrace+0x0/0x210
- [ 220.466960] show_stack+0x20/0x68
- [ 220.466965] dump_stack+0xd8/0x130
- [ 220.466971] ast_primary_plane_helper_atomic_check+0x3c/0xa8 [ast]
- [ 220.467003] drm_atomic_helper_check_planes+0xe0/0x200 [drm_kms_helper]
- [ 220.467020] drm_atomic_helper_check+0x58/0xb0 [drm_kms_helper]
- [ 220.467077] drm_atomic_check_only+0x454/0x770 [drm]
- [ 220.467114] drm_atomic_commit+0x24/0x68 [drm]
- [ 220.467146] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.467175] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.467201] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.467205] fb_pan_display+0x94/0x108
- [ 220.467208] bit_update_start+0x28/0x50
- [ 220.467210] fbcon_switch+0x320/0x4b0
- [ 220.467212] redraw_screen+0x148/0x280
- [ 220.467215] complete_change_console+0x50/0xf0
- [ 220.467217] change_console+0x74/0xa8
- [ 220.467219] console_callback+0x158/0x170
- [ 220.467223] process_one_work+0x1c0/0x428
- [ 220.467224] worker_thread+0x158/0x510
- [ 220.467227] kthread+0x118/0x120
- [ 220.467230] ret_from_fork+0x10/0x18
- [ 220.467234] ===ast_crtc_helper_atomic_check
- [ 220.467237] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.467239] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.467246] Workqueue: events console_callback
- [ 220.467248] Call trace:
- [ 220.467250] dump_backtrace+0x0/0x210
- [ 220.467252] show_stack+0x20/0x68
- [ 220.467254] dump_stack+0xd8/0x130
- [ 220.467258] ast_crtc_helper_atomic_check+0x30/0x1454 [ast]
- [ 220.467275] drm_atomic_helper_check_planes+0x140/0x200 [drm_kms_helper]
- [ 220.467289] drm_atomic_helper_check+0x58/0xb0 [drm_kms_helper]
- [ 220.467326] drm_atomic_check_only+0x454/0x770 [drm]
- [ 220.467356] drm_atomic_commit+0x24/0x68 [drm]
- [ 220.467384] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.467414] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.467432] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.467434] fb_pan_display+0x94/0x108
- [ 220.467437] bit_update_start+0x28/0x50
- [ 220.467439] fbcon_switch+0x320/0x4b0
- [ 220.467441] redraw_screen+0x148/0x280
- [ 220.467444] complete_change_console+0x50/0xf0
- [ 220.467446] change_console+0x74/0xa8
- [ 220.467448] console_callback+0x158/0x170
- [ 220.467450] process_one_work+0x1c0/0x428
- [ 220.467451] worker_thread+0x158/0x510
- [ 220.467454] kthread+0x118/0x120
- [ 220.467456] ret_from_fork+0x10/0x18
- [ 220.467459] ===drm_atomic_helper_commit
- [ 220.467462] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.467463] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.467470] Workqueue: events console_callback
- [ 220.467472] Call trace:
- [ 220.467474] dump_backtrace+0x0/0x210
- [ 220.467475] show_stack+0x20/0x68
- [ 220.467477] dump_stack+0xd8/0x130
- [ 220.467492] drm_atomic_helper_commit+0x3c/0x14c [drm_kms_helper]
- [ 220.467524] drm_atomic_commit+0x54/0x68 [drm]
- [ 220.467554] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.467584] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.467600] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.467603] fb_pan_display+0x94/0x108
- [ 220.467605] bit_update_start+0x28/0x50
- [ 220.467607] fbcon_switch+0x320/0x4b0
- [ 220.467610] redraw_screen+0x148/0x280
- [ 220.467612] complete_change_console+0x50/0xf0
- [ 220.467614] change_console+0x74/0xa8
- [ 220.467616] console_callback+0x158/0x170
- [ 220.467618] process_one_work+0x1c0/0x428
- [ 220.467620] worker_thread+0x158/0x510
- [ 220.467622] kthread+0x118/0x120
- [ 220.467624] ret_from_fork+0x10/0x18
- [ 220.467635] ===drm_atomic_helper_commit_tail_rpm
- [ 220.467638] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.467639] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.467646] Workqueue: events console_callback
- [ 220.467648] Call trace:
- [ 220.467650] dump_backtrace+0x0/0x210
- [ 220.467651] show_stack+0x20/0x68
- [ 220.467654] dump_stack+0xd8/0x130
- [ 220.467669] drm_atomic_helper_commit_tail_rpm+0x30/0x98 [drm_kms_helper]
- [ 220.467683] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 220.467697] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 220.467731] drm_atomic_commit+0x54/0x68 [drm]
- [ 220.467762] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.467791] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.467809] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.467811] fb_pan_display+0x94/0x108
- [ 220.467814] bit_update_start+0x28/0x50
- [ 220.467816] fbcon_switch+0x320/0x4b0
- [ 220.467818] redraw_screen+0x148/0x280
- [ 220.467820] complete_change_console+0x50/0xf0
- [ 220.467822] change_console+0x74/0xa8
- [ 220.467824] console_callback+0x158/0x170
- [ 220.467827] process_one_work+0x1c0/0x428
- [ 220.467828] worker_thread+0x158/0x510
- [ 220.467830] kthread+0x118/0x120
- [ 220.467832] ret_from_fork+0x10/0x18
- [ 220.467836] ===ast_primary_plane_helper_atomic_update gpu_addr 0 comm kworker/5:3
- [ 220.467838] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.467840] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.467847] Workqueue: events console_callback
- [ 220.467849] Call trace:
- [ 220.467851] dump_backtrace+0x0/0x210
- [ 220.467852] show_stack+0x20/0x68
- [ 220.467855] dump_stack+0xd8/0x130
- [ 220.467859] ast_primary_plane_helper_atomic_update+0x188/0x2b0 [ast]
- [ 220.467875] drm_atomic_helper_commit_planes+0xf0/0x218 [drm_kms_helper]
- [ 220.467888] drm_atomic_helper_commit_tail_rpm+0x58/0x98 [drm_kms_helper]
- [ 220.467902] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 220.467915] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 220.467949] drm_atomic_commit+0x54/0x68 [drm]
- [ 220.467979] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.468007] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.468022] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.468024] fb_pan_display+0x94/0x108
- [ 220.468027] bit_update_start+0x28/0x50
- [ 220.468029] fbcon_switch+0x320/0x4b0
- [ 220.468031] redraw_screen+0x148/0x280
- [ 220.468033] complete_change_console+0x50/0xf0
- [ 220.468035] change_console+0x74/0xa8
- [ 220.468037] console_callback+0x158/0x170
- [ 220.468040] process_one_work+0x1c0/0x428
- [ 220.468041] worker_thread+0x158/0x510
- [ 220.468043] kthread+0x118/0x120
- [ 220.468045] ret_from_fork+0x10/0x18
- [ 220.468059] ===ast_crtc_helper_atomic_flush
- [ 220.468062] CPU: 5 PID: 1941 Comm: kworker/5:3 Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 220.468063] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 220.468070] Workqueue: events console_callback
- [ 220.468072] Call trace:
- [ 220.468073] dump_backtrace+0x0/0x210
- [ 220.468075] show_stack+0x20/0x68
- [ 220.468077] dump_stack+0xd8/0x130
- [ 220.468081] ast_crtc_helper_atomic_flush+0x3c/0x160 [ast]
- [ 220.468097] drm_atomic_helper_commit_planes+0x15c/0x218 [drm_kms_helper]
- [ 220.468112] drm_atomic_helper_commit_tail_rpm+0x58/0x98 [drm_kms_helper]
- [ 220.468125] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 220.468139] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 220.468175] drm_atomic_commit+0x54/0x68 [drm]
- [ 220.468206] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 220.468237] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 220.468256] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 220.468258] fb_pan_display+0x94/0x108
- [ 220.468261] bit_update_start+0x28/0x50
- [ 220.468263] fbcon_switch+0x320/0x4b0
- [ 220.468265] redraw_screen+0x148/0x280
- [ 220.468268] complete_change_console+0x50/0xf0
- [ 220.468270] change_console+0x74/0xa8
- [ 220.468272] console_callback+0x158/0x170
- [ 220.468275] process_one_work+0x1c0/0x428
- [ 220.468276] worker_thread+0x158/0x510
- [ 220.468278] kthread+0x118/0x120
- [ 220.468280] ret_from_fork+0x10/0x18
总结流程:
- console_callback
- change_console
- complete_change_console
- redraw_screen
- fbcon_switch
- bit_update_start
- fb_pan_display
- drm_fb_helper_pan_display
- drm_client_modeset_commit_locked
- drm_client_modeset_commit_atomic
- drm_atomic_commit
- drm_atomic_check_only
- drm_atomic_helper_check
- drm_atomic_helper_check_planes //调用drm_xx_helper_funcs->atomic_check
- ast_primary_plane_helper_atomic_check //plane
- ast_crtc_helper_atomic_check //crtc
-
- drm_atomic_helper_commit
- commit_tail
- drm_atomic_helper_commit_tail_rpm
- drm_atomic_helper_commit_planes //调用crtc的atomic_begin。plane的atomic_update,crtc的atomic_flush
- ast_primary_plane_helper_atomic_update
- ast_crtc_helper_atomic_flush
上面是ctrl+alt+Fx 后 直到agetty程序启动前。下面是agetty启动后字符界面出现内容,如果之前以及切换过,也就是agetty起来了,则不会走下面的了。
2:agetty程序启动后tty_write
- [ 221.249372] ===ast_primary_plane_helper_atomic_check
- [ 221.249386] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.249389] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.249393] Call trace:
- [ 221.249409] dump_backtrace+0x0/0x210
- [ 221.249412] show_stack+0x20/0x68
- [ 221.249423] dump_stack+0xd8/0x130
- [ 221.249436] ast_primary_plane_helper_atomic_check+0x3c/0xa8 [ast]
- [ 221.249503] drm_atomic_helper_check_planes+0xe0/0x200 [drm_kms_helper]
- [ 221.249522] drm_atomic_helper_check+0x58/0xb0 [drm_kms_helper]
- [ 221.249635] drm_atomic_check_only+0x454/0x770 [drm]
- [ 221.249678] drm_atomic_commit+0x24/0x68 [drm]
- [ 221.249708] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.249736] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.249774] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.249785] fb_pan_display+0x94/0x108
- [ 221.249802] bit_update_start+0x28/0x50
- [ 221.249805] fbcon_switch+0x320/0x4b0
- [ 221.249814] csi_J+0x1c8/0x1d8
- [ 221.249819] do_con_trol+0x1388/0x1478
- [ 221.249821] do_con_write+0x208/0x930
- [ 221.249823] con_write+0x20/0x70
- [ 221.249831] n_tty_write+0x19c/0x468
- [ 221.249835] tty_write+0x184/0x340
- [ 221.249842] vfs_write+0xc8/0x2b8
- [ 221.249844] ksys_write+0x70/0xf8
- [ 221.249846] __arm64_sys_write+0x24/0x30
- [ 221.249854] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.249857] do_el0_svc+0x2c/0x98
- [ 221.249862] el0_svc+0x28/0x68
- [ 221.249864] el0_sync_handler+0x90/0xb8
- [ 221.249868] el0_sync+0x158/0x180
- [ 221.249875] ===ast_crtc_helper_atomic_check
- [ 221.249878] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.249881] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.249883] Call trace:
- [ 221.249885] dump_backtrace+0x0/0x210
- [ 221.249887] show_stack+0x20/0x68
- [ 221.249889] dump_stack+0xd8/0x130
- [ 221.249895] ast_crtc_helper_atomic_check+0x30/0x1454 [ast]
- [ 221.249915] drm_atomic_helper_check_planes+0x140/0x200 [drm_kms_helper]
- [ 221.249929] drm_atomic_helper_check+0x58/0xb0 [drm_kms_helper]
- [ 221.249975] drm_atomic_check_only+0x454/0x770 [drm]
- [ 221.250016] drm_atomic_commit+0x24/0x68 [drm]
- [ 221.250047] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.250089] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.250125] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.250129] fb_pan_display+0x94/0x108
- [ 221.250134] bit_update_start+0x28/0x50
- [ 221.250136] fbcon_switch+0x320/0x4b0
- [ 221.250140] csi_J+0x1c8/0x1d8
- [ 221.250143] do_con_trol+0x1388/0x1478
- [ 221.250145] do_con_write+0x208/0x930
- [ 221.250147] con_write+0x20/0x70
- [ 221.250151] n_tty_write+0x19c/0x468
- [ 221.250154] tty_write+0x184/0x340
- [ 221.250157] vfs_write+0xc8/0x2b8
- [ 221.250159] ksys_write+0x70/0xf8
- [ 221.250161] __arm64_sys_write+0x24/0x30
- [ 221.250166] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.250169] do_el0_svc+0x2c/0x98
- [ 221.250176] el0_svc+0x28/0x68
- [ 221.250178] el0_sync_handler+0x90/0xb8
- [ 221.250181] el0_sync+0x158/0x180
- [ 221.250278] ===drm_atomic_helper_commit
- [ 221.250288] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.250290] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.250292] Call trace:
- [ 221.250298] dump_backtrace+0x0/0x210
- [ 221.250300] show_stack+0x20/0x68
- [ 221.250304] dump_stack+0xd8/0x130
- [ 221.250345] drm_atomic_helper_commit+0x3c/0x14c [drm_kms_helper]
- [ 221.250438] drm_atomic_commit+0x54/0x68 [drm]
- [ 221.250487] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.250535] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.250567] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.250572] fb_pan_display+0x94/0x108
- [ 221.250576] bit_update_start+0x28/0x50
- [ 221.250578] fbcon_switch+0x320/0x4b0
- [ 221.250583] csi_J+0x1c8/0x1d8
- [ 221.250585] do_con_trol+0x1388/0x1478
- [ 221.250587] do_con_write+0x208/0x930
- [ 221.250590] con_write+0x20/0x70
- [ 221.250596] n_tty_write+0x19c/0x468
- [ 221.250600] tty_write+0x184/0x340
- [ 221.250606] vfs_write+0xc8/0x2b8
- [ 221.250608] ksys_write+0x70/0xf8
- [ 221.250610] __arm64_sys_write+0x24/0x30
- [ 221.250619] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.250621] do_el0_svc+0x2c/0x98
- [ 221.250624] el0_svc+0x28/0x68
- [ 221.250626] el0_sync_handler+0x90/0xb8
- [ 221.250629] el0_sync+0x158/0x180
- [ 221.250653] ===drm_atomic_helper_commit_tail_rpm
- [ 221.250656] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.250658] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.250659] Call trace:
- [ 221.250662] dump_backtrace+0x0/0x210
- [ 221.250664] show_stack+0x20/0x68
- [ 221.250668] dump_stack+0xd8/0x130
- [ 221.250692] drm_atomic_helper_commit_tail_rpm+0x30/0x98 [drm_kms_helper]
- [ 221.250708] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 221.250726] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 221.250798] drm_atomic_commit+0x54/0x68 [drm]
- [ 221.250840] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.250881] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.250917] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.250919] fb_pan_display+0x94/0x108
- [ 221.250922] bit_update_start+0x28/0x50
- [ 221.250924] fbcon_switch+0x320/0x4b0
- [ 221.250927] csi_J+0x1c8/0x1d8
- [ 221.250930] do_con_trol+0x1388/0x1478
- [ 221.250932] do_con_write+0x208/0x930
- [ 221.250935] con_write+0x20/0x70
- [ 221.250940] n_tty_write+0x19c/0x468
- [ 221.250942] tty_write+0x184/0x340
- [ 221.250946] vfs_write+0xc8/0x2b8
- [ 221.250947] ksys_write+0x70/0xf8
- [ 221.250949] __arm64_sys_write+0x24/0x30
- [ 221.250954] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.250956] do_el0_svc+0x2c/0x98
- [ 221.250961] el0_svc+0x28/0x68
- [ 221.250967] el0_sync_handler+0x90/0xb8
- [ 221.250969] el0_sync+0x158/0x180
- [ 221.250979] ===ast_primary_plane_helper_atomic_update gpu_addr 0 comm (agetty)
- [ 221.250982] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.250984] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.250986] Call trace:
- [ 221.250987] dump_backtrace+0x0/0x210
- [ 221.250989] show_stack+0x20/0x68
- [ 221.250993] dump_stack+0xd8/0x130
- [ 221.251002] ast_primary_plane_helper_atomic_update+0x188/0x2b0 [ast]
- [ 221.251024] drm_atomic_helper_commit_planes+0xf0/0x218 [drm_kms_helper]
- [ 221.251038] drm_atomic_helper_commit_tail_rpm+0x58/0x98 [drm_kms_helper]
- [ 221.251051] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 221.251065] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 221.251122] drm_atomic_commit+0x54/0x68 [drm]
- [ 221.251159] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.251187] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.251205] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.251207] fb_pan_display+0x94/0x108
- [ 221.251211] bit_update_start+0x28/0x50
- [ 221.251217] fbcon_switch+0x320/0x4b0
- [ 221.251220] csi_J+0x1c8/0x1d8
- [ 221.251222] do_con_trol+0x1388/0x1478
- [ 221.251223] do_con_write+0x208/0x930
- [ 221.251232] con_write+0x20/0x70
- [ 221.251235] n_tty_write+0x19c/0x468
- [ 221.251237] tty_write+0x184/0x340
- [ 221.251240] vfs_write+0xc8/0x2b8
- [ 221.251242] ksys_write+0x70/0xf8
- [ 221.251244] __arm64_sys_write+0x24/0x30
- [ 221.251248] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.251250] do_el0_svc+0x2c/0x98
- [ 221.251252] el0_svc+0x28/0x68
- [ 221.251254] el0_sync_handler+0x90/0xb8
- [ 221.251257] el0_sync+0x158/0x180
- [ 221.251509] ===ast_crtc_helper_atomic_flush
- [ 221.251513] CPU: 105 PID: 3477 Comm: (agetty) Kdump: loaded Tainted: G E 5.10.0.anolis+ #8
- [ 221.251514] Hardware name: PHYTIUM LTD Phytium S2500/64/Phytium S2500/64, BIOS V2.2 Feb 9 2021
- [ 221.251515] Call trace:
- [ 221.251517] dump_backtrace+0x0/0x210
- [ 221.251519] show_stack+0x20/0x68
- [ 221.251521] dump_stack+0xd8/0x130
- [ 221.251526] ast_crtc_helper_atomic_flush+0x3c/0x160 [ast]
- [ 221.251552] drm_atomic_helper_commit_planes+0x15c/0x218 [drm_kms_helper]
- [ 221.251569] drm_atomic_helper_commit_tail_rpm+0x58/0x98 [drm_kms_helper]
- [ 221.251590] commit_tail+0xac/0x1a8 [drm_kms_helper]
- [ 221.251612] drm_atomic_helper_commit+0x120/0x14c [drm_kms_helper]
- [ 221.251677] drm_atomic_commit+0x54/0x68 [drm]
- [ 221.251718] drm_client_modeset_commit_atomic.isra.14+0x1ec/0x290 [drm]
- [ 221.251755] drm_client_modeset_commit_locked+0x68/0x1a8 [drm]
- [ 221.251782] drm_fb_helper_pan_display+0xc0/0x1e0 [drm_kms_helper]
- [ 221.251786] fb_pan_display+0x94/0x108
- [ 221.251789] bit_update_start+0x28/0x50
- [ 221.251792] fbcon_switch+0x320/0x4b0
- [ 221.251795] csi_J+0x1c8/0x1d8
- [ 221.251798] do_con_trol+0x1388/0x1478
- [ 221.251800] do_con_write+0x208/0x930
- [ 221.251807] con_write+0x20/0x70
- [ 221.251810] n_tty_write+0x19c/0x468
- [ 221.251818] tty_write+0x184/0x340
- [ 221.251821] vfs_write+0xc8/0x2b8
- [ 221.251823] ksys_write+0x70/0xf8
- [ 221.251825] __arm64_sys_write+0x24/0x30
- [ 221.251829] el0_svc_common.constprop.3+0xa4/0x1f8
- [ 221.251831] do_el0_svc+0x2c/0x98
- [ 221.251835] el0_svc+0x28/0x68
- [ 221.251838] el0_sync_handler+0x90/0xb8
- [ 221.251840] el0_sync+0x158/0x180
tty参考:Linux 终端初始化 console_init 及 tty 驱动框架 - 腾讯云开发者社区-腾讯云 (tencent.com)
printk打印:【转载】从printk到framebuff - hydah - 博客园 (cnblogs.com)
- static int __init con_init(void)
- {
- ...
- #ifdef CONFIG_VT_CONSOLE
- register_console(&vt_console_driver);
- #endif
- return 0;
- }
-
-
- static struct console vt_console_driver = {
- .name = "tty",
- .write = vt_console_print, //printk调用这个写函数
- .device = vt_console_device,
- .unblank = unblank_screen,
- .flags = CON_PRINTBUFFER,
- .index = -1,
- };
-
-
- static void vt_console_print(struct console *co, const char *b, unsigned count)
- {
- struct vc_data *vc = vc_cons[fg_console].d;
-
- vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x); //调用consw 的con_putc函数
-
- }
drivers/video 下提供console的有多个:
其中我们如果是framebuffer的话,在fbdev下面。通过register_framebuffer通用注册。efifb和drm都是一样。
- [ 12.653736] do_take_over_console+0x158/0x240 //drivers/tty/vt/vt.c
- [ 12.653739] do_fbcon_takeover+0x74/0xe0 //drivers/tty/vt/vt.c
- [ 12.653741] fbcon_event_notify+0x858/0x8c8
- [ 12.653744] notifier_call_chain+0x5c/0x98
- [ 12.653746] blocking_notifier_call_chain+0x64/0xa0
- [ 12.653748] fb_notifier_call_chain+0x30/0x40
- [ 12.653750] register_framebuffer+0x2b4/0x340 //drivers/video/fbdev/core/fbmem.c
但如果是framebuffer的话 (在fbdev下面),只能支持一个(efifb或者显卡驱动注册的register_framebuffer)。因为vt.c中的registered_con_driver总共16个且不能重复。意味着如果efifb注册了。后面的将无法注册。除非将efifb干掉。因此。通过drm启动后efifb会被移除。参考后面的do_take_over_console
可以博客写了tty的显示过程。
(126条消息) tty0 显示的过程_tiantao2012的博客-CSDN博客
显示控制台的驱动是:drivers/tty/vt/vt.c:
-
- static DECLARE_WORK(console_work, console_callback); //work工作项
-
- console_callback是其工作函数。每次切换终端将调用: 对应了前面的dump_stack
-
- void schedule_console_callback(void)
- {
- schedule_work(&console_work); //调用
- }
-
-
- static void console_callback(struct work_struct *ignored)
- {
- console_lock();
-
- if (want_console >= 0) {
- if (want_console != fg_console &&
- vc_cons_allocated(want_console)) {
- hide_cursor(vc_cons[fg_console].d);
- change_console(vc_cons[want_console].d); //执行切换。
- /* we only changed when the console had already
- been allocated - a new console is not created
- in an interrupt routine */
- }
- want_console = -1;
- }
- if (do_poke_blanked_console) { /* do not unblank for a LED change */
- do_poke_blanked_console = 0;
- poke_blanked_console();
- }
- if (scrollback_delta) {
- struct vc_data *vc = vc_cons[fg_console].d;
- clear_selection();
- if (vc->vc_mode == KD_TEXT && vc->vc_sw->con_scrolldelta)
- vc->vc_sw->con_scrolldelta(vc, scrollback_delta);
- scrollback_delta = 0;
- }
- if (blank_timer_expired) {
- do_blank_screen(0);
- blank_timer_expired = 0;
- }
- notify_update(vc_cons[fg_console].d);
-
- console_unlock();
- }
-
-
vc_cons:
struct vc vc_cons [MAX_NR_CONSOLES]; 总共63个从tty1->tty63
- #define MIN_NR_CONSOLES 1 /* must be at least 1 */
- #define MAX_NR_CONSOLES 63 /* serial lines start at 64 */
其中tty和tty0 是特殊用。Ctrl+alt+fx 对应ttyx
下面是/dev/目录下的ttyX。 drivers/vt/vt.c对应的是ttyX
再看一下drivers/vt/vt.c 中的
- #define MAX_NR_CON_DRIVER 16
-
- struct con_driver {
- const struct consw *con;
- const char *desc;
- struct device *dev;
- int node;
- int first;
- int last;
- int flag;
- };
-
- static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER]; //总共可以注册的consw为16个。且需要不同。比如fb_con。sti_con,mda_con,newport_con,dummy_con等等
- const struct consw *conswitchp;
-
-
-
- struct vc vc_cons [MAX_NR_CONSOLES]; //总共的终端时63个。
-
- #ifndef VT_SINGLE_DRIVER
- static const struct consw *con_driver_map[MAX_NR_CONSOLES]; //总共63个,在do_bind_con_driver函数中会预先设置consw。参考 do_bind_con_driver
- #endif
do_take_over_console 注册:
- int do_take_over_console(const struct consw *csw, int first, int last, int deflt)
- {
- int err;
-
- err = do_register_con_driver(csw, first, last); // 注册consw。如果已经有相同的consw将返回失败。
- /*
- * If we get an busy error we still want to bind the console driver
- * and return success, as we may have unbound the console driver
- * but not unregistered it.
- */
- if (err == -EBUSY)
- err = 0;
- if (!err)
- do_bind_con_driver(csw, first, last, deflt);
-
- return err;
- }
do_register_con_driver:注册consw到 registered_con_driver中。无法重复注册(register_framebuffer背后使用的consw是一个fb_con)。
- static int do_register_con_driver(const struct consw *csw, int first, int last)
- {
- struct module *owner = csw->owner;
- struct con_driver *con_driver;
- const char *desc;
- int i, retval;
-
- WARN_CONSOLE_UNLOCKED();
-
- if (!try_module_get(owner))
- return -ENODEV;
-
- for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
- con_driver = ®istered_con_driver[i];
-
- /* already registered */
- if (con_driver->con == csw) { //如果已经存在。。。。这返回。
- retval = -EBUSY;
- goto err;
- }
- }
-
- desc = csw->con_startup();
- if (!desc) {
- retval = -ENODEV;
- goto err;
- }
-
- retval = -EINVAL;
-
- for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
- con_driver = ®istered_con_driver[i];
-
- if (con_driver->con == NULL &&
- !(con_driver->flag & CON_DRIVER_FLAG_ZOMBIE)) {
- con_driver->con = csw;
- con_driver->desc = desc;
- con_driver->node = i;
- con_driver->flag = CON_DRIVER_FLAG_MODULE |
- CON_DRIVER_FLAG_INIT;
- con_driver->first = first;
- con_driver->last = last;
- retval = 0;
- break;
- }
- }
-
- if (retval)
- goto err;
-
- con_driver->dev =
- device_create_with_groups(vtconsole_class, NULL,
- MKDEV(0, con_driver->node),
- con_driver, con_dev_groups,
- "vtcon%i", con_driver->node);
- if (IS_ERR(con_driver->dev)) {
- pr_warn("Unable to create device for %s; errno = %ld\n",
- con_driver->desc, PTR_ERR(con_driver->dev));
- con_driver->dev = NULL;
- } else {
- vtconsole_init_device(con_driver);
- }
-
- err:
- module_put(owner);
- return retval;
- }
do_bind_con_driver:绑定从first到last范围内的所有ttyX设备的consw。当然前提是该设备已经创建。
- static int do_bind_con_driver(const struct consw *csw, int first, int last,
- int deflt) //deflt是否为默认consw。通常注册的都是,比如fb_con
- {
- struct module *owner = csw->owner;
- const char *desc = NULL;
- struct con_driver *con_driver;
- int i, j = -1, k = -1, retval = -ENODEV;
-
- if (!try_module_get(owner))
- return -ENODEV;
-
- WARN_CONSOLE_UNLOCKED();
-
- /* check if driver is registered */
- for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
- con_driver = ®istered_con_driver[i];
-
- if (con_driver->con == csw) {
- desc = con_driver->desc;
- retval = 0;
- break;
- }
- }
-
- if (retval)
- goto err;
-
- if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
- csw->con_startup();
- con_driver->flag |= CON_DRIVER_FLAG_INIT;
- }
-
- if (deflt) {
- if (conswitchp)
- module_put(conswitchp->owner);
-
- __module_get(owner);
- conswitchp = csw; //替换为默认
- }
-
- first = max(first, con_driver->first);
- last = min(last, con_driver->last);
-
- for (i = first; i <= last; i++) {
- int old_was_color;
- struct vc_data *vc = vc_cons[i].d; //为63个ttyX 初始化数据
-
- if (con_driver_map[i])
- module_put(con_driver_map[i]->owner);
- __module_get(owner);
- con_driver_map[i] = csw;
-
- if (!vc || !vc->vc_sw) //如果对应的ttyX没有创建,则不需要,一般系统并不会创建全部。
- continue;
-
- j = i;
-
- if (con_is_visible(vc)) {
- k = i;
- save_screen(vc);
- }
-
- old_was_color = vc->vc_can_do_color;
- vc->vc_sw->con_deinit(vc);
- vc->vc_origin = (unsigned long)vc->vc_screenbuf;
- visual_init(vc, i, 0); //配置
- set_origin(vc);
- update_attr(vc);
-
- /* If the console changed between mono <-> color, then
- * the attributes in the screenbuf will be wrong. The
- * following resets all attributes to something sane.
- */
- if (old_was_color != vc->vc_can_do_color)
- clear_buffer_attributes(vc);
- }
-
- pr_info("Console: switching ");
- if (!deflt)
- pr_cont("consoles %d-%d ", first + 1, last + 1);
- if (j >= 0) {
- struct vc_data *vc = vc_cons[j].d;
-
- pr_cont("to %s %s %dx%d\n",
- vc->vc_can_do_color ? "colour" : "mono",
- desc, vc->vc_cols, vc->vc_rows);
-
- if (k >= 0) {
- vc = vc_cons[k].d;
- update_screen(vc);
- }
- } else {
- pr_cont("to %s\n", desc);
- }
-
- retval = 0;
- err:
- module_put(owner);
- return retval;
- };
do_bind_con_driver后谁最后调用,将使用谁的consw,如果通过register_framebuffer注册的consw是用一个,因此如果efifb先注册,则使用efifb,drm注册的可能用不到。
打印:do_bind_con_driver
- [ 17.211099] ===fbcon_fb_registered idx 0 info_idx -1
- [ 17.211210] ===do_bind_con_driver ffff800010e15818 first 0 last 62
- [ 17.211212] ===visual_init vc->vc_num 0 vc->vc_sw ffff800010e15818
- [ 17.211221] ===fbcon_init
- [ 21.177371] ===do_bind_con_driver ffff800010e14368 first 0 last 62
- [ 21.177376] ===visual_init vc->vc_num 0 vc->vc_sw ffff800010e14368
- [ 22.140147] ===fbcon_fb_registered idx 0 info_idx -1
- [ 22.141070] ===do_bind_con_driver ffff800010e15818 first 0 last 62
- [ 22.141073] ===visual_init vc->vc_num 0 vc->vc_sw ffff800010e15818
- [ 22.141074] ===fbcon_init
- [ 108.158192] ===visual_init vc->vc_num 1 vc->vc_sw ffff800010e15818
- [ 108.158194] ===fbcon_init
- [ 108.265646] ===visual_init vc->vc_num 2 vc->vc_sw ffff800010e15818
- [ 108.265648] ===fbcon_init
- [ 108.374542] ===visual_init vc->vc_num 3 vc->vc_sw ffff800010e15818
- [ 108.374543] ===fbcon_init
- [ 108.477747] ===visual_init vc->vc_num 4 vc->vc_sw ffff800010e15818
- [ 108.477749] ===fbcon_init
- [ 108.585954] ===visual_init vc->vc_num 5 vc->vc_sw ffff800010e15818
- [ 108.585955] ===fbcon_init
上述两个consw:分别可以打印出来,其vc_num:中0-5的6个分别代表tty1-6.
- root@wzm-phytium-d2000:~# cat /proc/kallsyms |grep ffff800010e14368
- ffff800010e14368 D dummy_con
- root@wzm-phytium-d2000:~# cat /proc/kallsyms |grep ffff800010e15818
- ffff800010e15818 d fb_con
前面分析切换终端调用fbcon_switch:
- static int fbcon_switch(struct vc_data *vc)
- {
- struct fb_info *info, *old_info = NULL;
- struct fbcon_ops *ops;
- struct fbcon_display *p = &fb_display[vc->vc_num];
- struct fb_var_screeninfo var;
- int i, ret, prev_console, charcnt = 256;
-
- info = registered_fb[con2fb_map[vc->vc_num]]; //根据vc_num 计算出registered_fb。进而找出fbcon_ops
-
- 。。。。
- }
con2fb_map数组中的值在do_fbcon_takeover中设置。
- static int do_fbcon_takeover(int show_logo)
- {
- int err, i;
-
- if (!num_registered_fb)
- return -ENODEV;
-
- if (!show_logo)
- logo_shown = FBCON_LOGO_DONTSHOW;
-
- for (i = first_fb_vc; i <= last_fb_vc; i++) //0-62
- con2fb_map[i] = info_idx; //info_idx 的值通常就是0,在函数fbcon_fb_registered中先从-1 设置为0.
- err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
- fbcon_is_default);
- 。。。
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。