Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
53289a6d
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
53289a6d
编写于
9月 02, 2022
作者:
Y
Yifan Wu
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merged PR #87
上级
a2f3dc34
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
52 deletion
+66
-52
os/src/drivers/block/virtio_blk.rs
os/src/drivers/block/virtio_blk.rs
+3
-48
os/src/drivers/bus/mod.rs
os/src/drivers/bus/mod.rs
+1
-0
os/src/drivers/bus/virtio.rs
os/src/drivers/bus/virtio.rs
+52
-0
os/src/drivers/gpu/mod.rs
os/src/drivers/gpu/mod.rs
+3
-2
os/src/drivers/input/mod.rs
os/src/drivers/input/mod.rs
+3
-2
os/src/drivers/mod.rs
os/src/drivers/mod.rs
+4
-0
未找到文件。
os/src/drivers/block/virtio_blk.rs
浏览文件 @
53289a6d
use
super
::
BlockDevice
;
use
crate
::
mm
::{
frame_alloc
,
frame_dealloc
,
kernel_token
,
FrameTracker
,
PageTable
,
PhysAddr
,
PhysPageNum
,
StepByOne
,
VirtAddr
,
};
use
crate
::
sync
::{
Condvar
,
UPIntrFreeCell
};
use
crate
::
task
::
schedule
;
use
crate
::
DEV_NON_BLOCKING_ACCESS
;
use
alloc
::
collections
::
BTreeMap
;
use
alloc
::
vec
::
Vec
;
use
lazy_static
::
*
;
use
virtio_drivers
::{
BlkResp
,
RespStatus
,
VirtIOBlk
,
VirtIOHeader
};
use
crate
::
drivers
::
bus
::
virtio
::
VirtioHal
;
#[allow(unused)]
const
VIRTIO0
:
usize
=
0x10008000
;
pub
struct
VirtIOBlock
{
virtio_blk
:
UPIntrFreeCell
<
VirtIOBlk
<
'static
>>
,
virtio_blk
:
UPIntrFreeCell
<
VirtIOBlk
<
'static
,
VirtioHal
>>
,
condvars
:
BTreeMap
<
u16
,
Condvar
>
,
}
lazy_static!
{
static
ref
QUEUE_FRAMES
:
UPIntrFreeCell
<
Vec
<
FrameTracker
>>
=
unsafe
{
UPIntrFreeCell
::
new
(
Vec
::
new
())
};
}
impl
BlockDevice
for
VirtIOBlock
{
fn
read_block
(
&
self
,
block_id
:
usize
,
buf
:
&
mut
[
u8
])
{
let
nb
=
*
DEV_NON_BLOCKING_ACCESS
.exclusive_access
();
...
...
@@ -79,7 +69,7 @@ impl BlockDevice for VirtIOBlock {
impl
VirtIOBlock
{
pub
fn
new
()
->
Self
{
let
virtio_blk
=
unsafe
{
UPIntrFreeCell
::
new
(
VirtIOBlk
::
new
(
&
mut
*
(
VIRTIO0
as
*
mut
VirtIOHeader
))
.unwrap
())
UPIntrFreeCell
::
new
(
VirtIOBlk
::
<
VirtioHal
>
::
new
(
&
mut
*
(
VIRTIO0
as
*
mut
VirtIOHeader
))
.unwrap
())
};
let
mut
condvars
=
BTreeMap
::
new
();
let
channels
=
virtio_blk
.exclusive_access
()
.virt_queue_size
();
...
...
@@ -94,38 +84,3 @@ impl VirtIOBlock {
}
}
#[no_mangle]
pub
extern
"C"
fn
virtio_dma_alloc
(
pages
:
usize
)
->
PhysAddr
{
let
mut
ppn_base
=
PhysPageNum
(
0
);
for
i
in
0
..
pages
{
let
frame
=
frame_alloc
()
.unwrap
();
if
i
==
0
{
ppn_base
=
frame
.ppn
;
}
assert_eq!
(
frame
.ppn
.0
,
ppn_base
.0
+
i
);
QUEUE_FRAMES
.exclusive_access
()
.push
(
frame
);
}
ppn_base
.into
()
}
#[no_mangle]
pub
extern
"C"
fn
virtio_dma_dealloc
(
pa
:
PhysAddr
,
pages
:
usize
)
->
i32
{
let
mut
ppn_base
:
PhysPageNum
=
pa
.into
();
for
_
in
0
..
pages
{
frame_dealloc
(
ppn_base
);
ppn_base
.step
();
}
0
}
#[no_mangle]
pub
extern
"C"
fn
virtio_phys_to_virt
(
paddr
:
PhysAddr
)
->
VirtAddr
{
VirtAddr
(
paddr
.0
)
}
#[no_mangle]
pub
extern
"C"
fn
virtio_virt_to_phys
(
vaddr
:
VirtAddr
)
->
PhysAddr
{
PageTable
::
from_token
(
kernel_token
())
.translate_va
(
vaddr
)
.unwrap
()
}
os/src/drivers/bus/mod.rs
0 → 100644
浏览文件 @
53289a6d
pub
mod
virtio
;
\ No newline at end of file
os/src/drivers/bus/virtio.rs
0 → 100644
浏览文件 @
53289a6d
use
alloc
::
vec
::
Vec
;
use
crate
::
mm
::{
frame_alloc
,
frame_dealloc
,
kernel_token
,
FrameTracker
,
PageTable
,
PhysAddr
,
PhysPageNum
,
StepByOne
,
VirtAddr
,
};
use
crate
::
sync
::
UPIntrFreeCell
;
use
lazy_static
::
*
;
use
virtio_drivers
::
Hal
;
lazy_static!
{
static
ref
QUEUE_FRAMES
:
UPIntrFreeCell
<
Vec
<
FrameTracker
>>
=
unsafe
{
UPIntrFreeCell
::
new
(
Vec
::
new
())
};
}
pub
struct
VirtioHal
;
impl
Hal
for
VirtioHal
{
fn
dma_alloc
(
pages
:
usize
)
->
usize
{
let
mut
ppn_base
=
PhysPageNum
(
0
);
for
i
in
0
..
pages
{
let
frame
=
frame_alloc
()
.unwrap
();
if
i
==
0
{
ppn_base
=
frame
.ppn
;
}
assert_eq!
(
frame
.ppn
.0
,
ppn_base
.0
+
i
);
QUEUE_FRAMES
.exclusive_access
()
.push
(
frame
);
}
let
pa
:
PhysAddr
=
ppn_base
.into
();
pa
.0
}
fn
dma_dealloc
(
pa
:
usize
,
pages
:
usize
)
->
i32
{
let
pa
=
PhysAddr
::
from
(
pa
);
let
mut
ppn_base
:
PhysPageNum
=
pa
.into
();
for
_
in
0
..
pages
{
frame_dealloc
(
ppn_base
);
ppn_base
.step
();
}
0
}
fn
phys_to_virt
(
addr
:
usize
)
->
usize
{
addr
}
fn
virt_to_phys
(
vaddr
:
usize
)
->
usize
{
PageTable
::
from_token
(
kernel_token
())
.translate_va
(
VirtAddr
::
from
(
vaddr
))
.unwrap
()
.0
}
}
\ No newline at end of file
os/src/drivers/gpu/mod.rs
浏览文件 @
53289a6d
...
...
@@ -4,6 +4,7 @@ use core::any::Any;
use
embedded_graphics
::
pixelcolor
::
Rgb888
;
use
tinybmp
::
Bmp
;
use
virtio_drivers
::{
VirtIOGpu
,
VirtIOHeader
};
use
crate
::
drivers
::
bus
::
virtio
::
VirtioHal
;
const
VIRTIO7
:
usize
=
0x10007000
;
pub
trait
GPUDevice
:
Send
+
Sync
+
Any
{
fn
update_cursor
(
&
self
);
...
...
@@ -16,14 +17,14 @@ lazy_static::lazy_static!(
);
pub
struct
VirtIOGPU
{
gpu
:
UPIntrFreeCell
<
VirtIOGpu
<
'static
>>
,
gpu
:
UPIntrFreeCell
<
VirtIOGpu
<
'static
,
VirtioHal
>>
,
fb
:
&
'static
[
u8
],
}
static
BMP_DATA
:
&
[
u8
]
=
include_bytes!
(
"../../assert/mouse.bmp"
);
impl
VirtIOGPU
{
pub
fn
new
()
->
Self
{
unsafe
{
let
mut
virtio
=
VirtIOGpu
::
new
(
&
mut
*
(
VIRTIO7
as
*
mut
VirtIOHeader
))
.unwrap
();
let
mut
virtio
=
VirtIOGpu
::
<
VirtioHal
>
::
new
(
&
mut
*
(
VIRTIO7
as
*
mut
VirtIOHeader
))
.unwrap
();
let
fbuffer
=
virtio
.setup_framebuffer
()
.unwrap
();
let
len
=
fbuffer
.len
();
...
...
os/src/drivers/input/mod.rs
浏览文件 @
53289a6d
...
...
@@ -11,6 +11,7 @@ use embedded_graphics::{
};
use
k210_hal
::
cache
::
Uncache
;
use
virtio_drivers
::{
VirtIOHeader
,
VirtIOInput
};
use
crate
::
drivers
::
bus
::
virtio
::
VirtioHal
;
use
virtio_input_decoder
::{
Decoder
,
Key
,
KeyType
};
use
super
::
GPU_DEVICE
;
...
...
@@ -18,7 +19,7 @@ use super::GPU_DEVICE;
const
VIRTIO5
:
usize
=
0x10005000
;
const
VIRTIO6
:
usize
=
0x10006000
;
struct
VirtIOINPUT
(
UPIntrFreeCell
<
VirtIOInput
<
'static
>>
);
struct
VirtIOINPUT
(
UPIntrFreeCell
<
VirtIOInput
<
'static
,
VirtioHal
>>
);
pub
trait
INPUTDevice
:
Send
+
Sync
+
Any
{
fn
handle_irq
(
&
self
);
...
...
@@ -32,7 +33,7 @@ lazy_static::lazy_static!(
impl
VirtIOINPUT
{
pub
fn
new
(
addr
:
usize
)
->
Self
{
Self
(
unsafe
{
UPIntrFreeCell
::
new
(
VirtIOInput
::
new
(
&
mut
*
(
addr
as
*
mut
VirtIOHeader
))
.unwrap
())
UPIntrFreeCell
::
new
(
VirtIOInput
::
<
VirtioHal
>
::
new
(
&
mut
*
(
addr
as
*
mut
VirtIOHeader
))
.unwrap
())
})
}
}
...
...
os/src/drivers/mod.rs
浏览文件 @
53289a6d
...
...
@@ -4,6 +4,8 @@ pub mod chardev;
pub
mod
gpu
;
#[cfg(feature
=
"board_qemu"
)]
pub
mod
input
;
#[cfg(feature
=
"board_qemu"
)]
pub
mod
bus
;
pub
mod
plic
;
pub
use
block
::
BLOCK_DEVICE
;
#[cfg(feature
=
"board_qemu"
)]
...
...
@@ -12,3 +14,5 @@ pub use chardev::UART;
pub
use
gpu
::
*
;
#[cfg(feature
=
"board_qemu"
)]
pub
use
input
::
*
;
#[cfg(feature
=
"board_qemu"
)]
pub
use
bus
::
*
;
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
4b919f01
·
9月 05, 2022
mentioned in commit
4b919f01
mentioned in commit 4b919f01d26d04bf26f7354ee7a7236bb0c9a28e
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录