通常在虚拟 guest 中可用的第一个虚拟串口设备 hvc 应该是hvc0,为什么我们在 RISCV 平台上测试中发现第一个 guest 能用的 hvc 设备是 hvc1 而不是 hvc0 呢? 当guest 系统设置 bootargs = "console=hvc1,115200“ ,才有虚拟串口可用。
通过debug虚拟串口分配函数 hvc_alloc,我们发现hvc0已经被opensbi给申请了,
struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
const struct hv_ops *ops,
int outbuf_size)
{
...
list_add_tail(&(hp->next), &hvc_structs);
mutex_unlock(&hvc_structs_mutex);
/* check if we need to re-register the kernel console */
hvc_check_console(i);
// debug code
dump_stack();
printk(">>> vtermnos[%d] = %d\n", i, vtermon);
return hp;
}
EXPORT_SYMBOL_GPL(hvc_alloc);