Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
星回༄༅白马
rt-thread
提交
07a2e8c3
R
rt-thread
项目概览
星回༄༅白马
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
07a2e8c3
编写于
7月 08, 2022
作者:
G
GUI
提交者:
GitHub
7月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp/qemu-virt64-aarch64] Add VirtIO-Console and GPIO driver (#6150)
上级
b01c2b8a
变更
24
展开全部
显示空白变更内容
内联
并排
Showing
24 changed file
with
1417 addition
and
35 deletion
+1417
-35
bsp/qemu-virt64-aarch64/.config
bsp/qemu-virt64-aarch64/.config
+4
-9
bsp/qemu-virt64-aarch64/README.md
bsp/qemu-virt64-aarch64/README.md
+7
-0
bsp/qemu-virt64-aarch64/README_zh.md
bsp/qemu-virt64-aarch64/README_zh.md
+7
-0
bsp/qemu-virt64-aarch64/applications/console.c
bsp/qemu-virt64-aarch64/applications/console.c
+65
-0
bsp/qemu-virt64-aarch64/applications/pin.c
bsp/qemu-virt64-aarch64/applications/pin.c
+33
-0
bsp/qemu-virt64-aarch64/driver/Kconfig
bsp/qemu-virt64-aarch64/driver/Kconfig
+9
-0
bsp/qemu-virt64-aarch64/driver/board.c
bsp/qemu-virt64-aarch64/driver/board.c
+8
-0
bsp/qemu-virt64-aarch64/driver/drv_gpio.c
bsp/qemu-virt64-aarch64/driver/drv_gpio.c
+314
-0
bsp/qemu-virt64-aarch64/driver/drv_gpio.h
bsp/qemu-virt64-aarch64/driver/drv_gpio.h
+16
-0
bsp/qemu-virt64-aarch64/driver/drv_virtio.c
bsp/qemu-virt64-aarch64/driver/drv_virtio.c
+6
-0
bsp/qemu-virt64-aarch64/driver/virt.h
bsp/qemu-virt64-aarch64/driver/virt.h
+5
-0
bsp/qemu-virt64-aarch64/driver/virtio/virtio.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio.c
+37
-7
bsp/qemu-virt64-aarch64/driver/virtio/virtio.h
bsp/qemu-virt64-aarch64/driver/virtio/virtio.h
+6
-5
bsp/qemu-virt64-aarch64/driver/virtio/virtio_blk.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio_blk.c
+23
-4
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.c
+734
-0
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.h
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.h
+96
-0
bsp/qemu-virt64-aarch64/driver/virtio/virtio_gpu.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio_gpu.c
+25
-3
bsp/qemu-virt64-aarch64/driver/virtio/virtio_input.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio_input.c
+6
-0
bsp/qemu-virt64-aarch64/driver/virtio/virtio_net.c
bsp/qemu-virt64-aarch64/driver/virtio/virtio_net.c
+6
-0
bsp/qemu-virt64-aarch64/qemu-graphic.bat
bsp/qemu-virt64-aarch64/qemu-graphic.bat
+2
-1
bsp/qemu-virt64-aarch64/qemu-graphic.sh
bsp/qemu-virt64-aarch64/qemu-graphic.sh
+2
-1
bsp/qemu-virt64-aarch64/qemu.bat
bsp/qemu-virt64-aarch64/qemu.bat
+2
-1
bsp/qemu-virt64-aarch64/qemu.sh
bsp/qemu-virt64-aarch64/qemu.sh
+2
-1
bsp/qemu-virt64-aarch64/rtconfig.h
bsp/qemu-virt64-aarch64/rtconfig.h
+2
-3
未找到文件。
bsp/qemu-virt64-aarch64/.config
浏览文件 @
07a2e8c3
...
@@ -435,6 +435,7 @@ CONFIG_RT_LWIP_USING_PING=y
...
@@ -435,6 +435,7 @@ CONFIG_RT_LWIP_USING_PING=y
# CONFIG_PKG_USING_RAPIDJSON is not set
# CONFIG_PKG_USING_RAPIDJSON is not set
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_PARSON is not set
#
#
# XML: Extensible Markup Language
# XML: Extensible Markup Language
...
@@ -548,15 +549,6 @@ CONFIG_RT_LWIP_USING_PING=y
...
@@ -548,15 +549,6 @@ CONFIG_RT_LWIP_USING_PING=y
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
#
# POSIX extension functions
#
# CONFIG_PKG_USING_POSIX_GETLINE is not set
# CONFIG_PKG_USING_POSIX_WCWIDTH is not set
# CONFIG_PKG_USING_POSIX_ITOA is not set
# CONFIG_PKG_USING_POSIX_STRINGS is not set
# CONFIG_PKG_USING_POSIX_CTYPES is not set
#
#
# acceleration: Assembly language or algorithmic acceleration packages
# acceleration: Assembly language or algorithmic acceleration packages
#
#
...
@@ -622,6 +614,7 @@ CONFIG_RT_LWIP_USING_PING=y
...
@@ -622,6 +614,7 @@ CONFIG_RT_LWIP_USING_PING=y
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT3X is not set
# CONFIG_PKG_USING_SHT3X is not set
# CONFIG_PKG_USING_ADT74XX is not set
# CONFIG_PKG_USING_AS7341 is not set
# CONFIG_PKG_USING_AS7341 is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_ICM20608 is not set
# CONFIG_PKG_USING_ICM20608 is not set
...
@@ -779,8 +772,10 @@ CONFIG_BSP_USING_UART=y
...
@@ -779,8 +772,10 @@ CONFIG_BSP_USING_UART=y
CONFIG_RT_USING_UART0
=
y
CONFIG_RT_USING_UART0
=
y
CONFIG_BSP_USING_RTC
=
y
CONFIG_BSP_USING_RTC
=
y
CONFIG_BSP_USING_ALARM
=
y
CONFIG_BSP_USING_ALARM
=
y
CONFIG_BSP_USING_PIN
=
y
CONFIG_BSP_USING_VIRTIO_BLK
=
y
CONFIG_BSP_USING_VIRTIO_BLK
=
y
CONFIG_BSP_USING_VIRTIO_NET
=
y
CONFIG_BSP_USING_VIRTIO_NET
=
y
CONFIG_BSP_USING_VIRTIO_CONSOLE
=
y
CONFIG_BSP_USING_VIRTIO_GPU
=
y
CONFIG_BSP_USING_VIRTIO_GPU
=
y
CONFIG_BSP_USING_VIRTIO_INPUT
=
y
CONFIG_BSP_USING_VIRTIO_INPUT
=
y
CONFIG_BSP_USING_GIC
=
y
CONFIG_BSP_USING_GIC
=
y
...
...
bsp/qemu-virt64-aarch64/README.md
浏览文件 @
07a2e8c3
...
@@ -45,13 +45,20 @@ Hi, this is RT-Thread!!
...
@@ -45,13 +45,20 @@ Hi, this is RT-Thread!!
msh />
msh />
```
```
Use VirtIO-Console in new terminal by:
````
telnet 127.0.0.1 4321
````
## 4. Condition
## 4. Condition
| Driver | Condition | Remark |
| Driver | Condition | Remark |
| ------ | --------- | ------ |
| ------ | --------- | ------ |
| UART | Support | UART0 |
| UART | Support | UART0 |
| RTC | Support | - |
| RTC | Support | - |
| GPIO | Support | - |
| VIRTIO BLK | Support | - |
| VIRTIO BLK | Support | - |
| VIRTIO NET | Support | - |
| VIRTIO NET | Support | - |
| VIRTIO Console | Support | - |
| VIRTIO GPU | Support | 2D |
| VIRTIO GPU | Support | 2D |
| VIRTIO Input | Support | Keyboard, Mouse, Tablet |
| VIRTIO Input | Support | Keyboard, Mouse, Tablet |
\ No newline at end of file
bsp/qemu-virt64-aarch64/README_zh.md
浏览文件 @
07a2e8c3
...
@@ -46,13 +46,20 @@ Hi, this is RT-Thread!!
...
@@ -46,13 +46,20 @@ Hi, this is RT-Thread!!
msh />
msh />
```
```
如果需要使用VirtIO-Console,请在新终端使用以下命令连接控制台:
```
telnet 127.0.0.1 4321
```
## 4.支持情况
## 4.支持情况
| 驱动 | 支持情况 | 备注 |
| 驱动 | 支持情况 | 备注 |
| ------ | ---- | :------: |
| ------ | ---- | :------: |
| UART | 支持 | UART0 |
| UART | 支持 | UART0 |
| RTC | 支持 | - |
| RTC | 支持 | - |
| GPIO | 支持 | - |
| VIRTIO BLK | 支持 | - |
| VIRTIO BLK | 支持 | - |
| VIRTIO NET | 支持 | - |
| VIRTIO NET | 支持 | - |
| VIRTIO Console | 支持 | - |
| VIRTIO GPU | 支持 | 2D |
| VIRTIO GPU | 支持 | 2D |
| VIRTIO Input | 支持 | Keyboard, Mouse, Tablet |
| VIRTIO Input | 支持 | Keyboard, Mouse, Tablet |
\ No newline at end of file
bsp/qemu-virt64-aarch64/applications/console.c
0 → 100644
浏览文件 @
07a2e8c3
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-11 GuEe-GUI the first version
*/
#include <rtthread.h>
#include <virtio_console.h>
int
console_init
()
{
rt_err_t
status
=
RT_EOK
;
rt_device_t
device
=
rt_device_find
(
"virtio-console0"
);
if
(
device
!=
RT_NULL
&&
rt_device_open
(
device
,
0
)
==
RT_EOK
)
{
/* Create vport0p1 */
status
=
rt_device_control
(
device
,
VIRTIO_DEVICE_CTRL_CONSOLE_PORT_CREATE
,
RT_NULL
);
}
if
(
device
!=
RT_NULL
)
{
rt_device_close
(
device
);
}
return
status
;
}
INIT_ENV_EXPORT
(
console_init
);
#ifdef FINSH_USING_MSH
static
int
console
(
int
argc
,
char
**
argv
)
{
rt_err_t
result
=
RT_EOK
;
if
(
argc
>
1
)
{
if
(
!
rt_strcmp
(
argv
[
1
],
"set"
))
{
rt_kprintf
(
"console change to %s
\n
"
,
argv
[
2
]);
rt_console_set_device
(
argv
[
2
]);
finsh_set_device
(
argv
[
2
]);
}
else
{
rt_kprintf
(
"Unknown command. Please enter 'console' for help
\n
"
);
result
=
-
RT_ERROR
;
}
}
else
{
rt_kprintf
(
"Usage:
\n
"
);
rt_kprintf
(
"console set <name> - change console by name
\n
"
);
result
=
-
RT_ERROR
;
}
return
result
;
}
MSH_CMD_EXPORT
(
console
,
set
console
name
);
#endif
/* FINSH_USING_MSH */
bsp/qemu-virt64-aarch64/applications/pin.c
0 → 100644
浏览文件 @
07a2e8c3
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-6-30 GuEe-GUI first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_PIN
void
qemu_gpio3_key_poweroff
(
void
*
args
)
{
rt_kprintf
(
"
\n
You power off the machine.
\n
"
);
rt_hw_cpu_shutdown
();
}
int
pin_init
()
{
rt_pin_attach_irq
(
3
,
PIN_IRQ_MODE_FALLING
,
qemu_gpio3_key_poweroff
,
RT_NULL
);
rt_pin_irq_enable
(
3
,
RT_TRUE
);
return
0
;
}
INIT_ENV_EXPORT
(
pin_init
);
#endif
/* RT_USING_PIN */
bsp/qemu-virt64-aarch64/driver/Kconfig
浏览文件 @
07a2e8c3
...
@@ -24,6 +24,11 @@ menu "AARCH64 qemu virt64 configs"
...
@@ -24,6 +24,11 @@ menu "AARCH64 qemu virt64 configs"
default n
default n
endif
endif
config BSP_USING_PIN
bool "Using PIN"
select RT_USING_PIN
default y
config BSP_USING_VIRTIO_BLK
config BSP_USING_VIRTIO_BLK
bool "Using VirtIO BLK"
bool "Using VirtIO BLK"
default y
default y
...
@@ -32,6 +37,10 @@ menu "AARCH64 qemu virt64 configs"
...
@@ -32,6 +37,10 @@ menu "AARCH64 qemu virt64 configs"
bool "Using VirtIO NET"
bool "Using VirtIO NET"
default y
default y
config BSP_USING_VIRTIO_CONSOLE
bool "Using VirtIO Console"
default y
config BSP_USING_VIRTIO_GPU
config BSP_USING_VIRTIO_GPU
bool "Using VirtIO GPU"
bool "Using VirtIO GPU"
default y
default y
...
...
bsp/qemu-virt64-aarch64/driver/board.c
浏览文件 @
07a2e8c3
...
@@ -29,6 +29,7 @@ struct mem_desc platform_mem_desc[] =
...
@@ -29,6 +29,7 @@ struct mem_desc platform_mem_desc[] =
{
{
{
0x40000000
,
0x80000000
,
0x40000000
,
NORMAL_MEM
},
{
0x40000000
,
0x80000000
,
0x40000000
,
NORMAL_MEM
},
{
PL031_RTC_BASE
,
PL031_RTC_BASE
+
0x1000
,
PL031_RTC_BASE
,
DEVICE_MEM
},
{
PL031_RTC_BASE
,
PL031_RTC_BASE
+
0x1000
,
PL031_RTC_BASE
,
DEVICE_MEM
},
{
PL061_GPIO_BASE
,
PL061_GPIO_BASE
+
0x1000
,
PL061_GPIO_BASE
,
DEVICE_MEM
},
{
PL011_UART0_BASE
,
PL011_UART0_BASE
+
0x1000
,
PL011_UART0_BASE
,
DEVICE_MEM
},
{
PL011_UART0_BASE
,
PL011_UART0_BASE
+
0x1000
,
PL011_UART0_BASE
,
DEVICE_MEM
},
{
VIRTIO_MMIO_BASE
,
VIRTIO_MMIO_BASE
+
VIRTIO_MAX_NR
*
VIRTIO_MMIO_SIZE
,
VIRTIO_MMIO_BASE
,
DEVICE_MEM
},
{
VIRTIO_MMIO_BASE
,
VIRTIO_MMIO_BASE
+
VIRTIO_MAX_NR
*
VIRTIO_MMIO_SIZE
,
VIRTIO_MMIO_BASE
,
DEVICE_MEM
},
#ifdef BSP_USING_GICV2
#ifdef BSP_USING_GICV2
...
@@ -95,6 +96,13 @@ void poweroff(void)
...
@@ -95,6 +96,13 @@ void poweroff(void)
}
}
MSH_CMD_EXPORT
(
poweroff
,
poweroff
...);
MSH_CMD_EXPORT
(
poweroff
,
poweroff
...);
void
rt_hw_cpu_shutdown
()
{
rt_kprintf
(
"shutdown...
\n
"
);
poweroff
();
}
void
reboot
(
void
)
void
reboot
(
void
)
{
{
arm_psci_system_reboot
();
arm_psci_system_reboot
();
...
...
bsp/qemu-virt64-aarch64/driver/drv_gpio.c
0 → 100644
浏览文件 @
07a2e8c3
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-6-30 GuEe-GUI first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "drv_gpio.h"
#ifdef BSP_USING_PIN
#define GPIODIR 0x400
#define GPIOIS 0x404
#define GPIOIBE 0x408
#define GPIOIEV 0x40c
#define GPIOIE 0x410
#define GPIORIS 0x414
#define GPIOMIS 0x418
#define GPIOIC 0x41c
#define BIT(x) (1 << (x))
#define PL061_GPIO_NR 8
static
struct
pl061
{
#ifdef RT_USING_SMP
struct
rt_spinlock
spinlock
;
#endif
void
(
*
(
hdr
[
PL061_GPIO_NR
]))(
void
*
args
);
void
*
args
[
PL061_GPIO_NR
];
}
_pl061
;
rt_inline
rt_uint8_t
pl061_read8
(
rt_ubase_t
offset
)
{
return
HWREG8
(
PL061_GPIO_BASE
+
offset
);
}
rt_inline
void
pl061_write8
(
rt_ubase_t
offset
,
rt_uint8_t
value
)
{
HWREG8
(
PL061_GPIO_BASE
+
offset
)
=
value
;
}
static
void
pl061_pin_mode
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
mode
)
{
int
value
;
rt_uint8_t
gpiodir
;
#ifdef RT_USING_SMP
rt_base_t
level
;
#endif
if
(
pin
<
0
||
pin
>=
PL061_GPIO_NR
)
{
return
;
}
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
_pl061
.
spinlock
);
#endif
switch
(
mode
)
{
case
PIN_MODE_OUTPUT
:
value
=
!!
pl061_read8
((
BIT
(
pin
+
2
)));
pl061_write8
(
BIT
(
pin
+
2
),
0
<<
pin
);
gpiodir
=
pl061_read8
(
GPIODIR
);
gpiodir
|=
BIT
(
pin
);
pl061_write8
(
GPIODIR
,
gpiodir
);
/*
* gpio value is set again, because pl061 doesn't allow to set value of
* a gpio pin before configuring it in OUT mode.
*/
pl061_write8
((
BIT
(
pin
+
2
)),
value
<<
pin
);
break
;
case
PIN_MODE_INPUT
:
gpiodir
=
pl061_read8
(
GPIODIR
);
gpiodir
&=
~
(
BIT
(
pin
));
pl061_write8
(
GPIODIR
,
gpiodir
);
break
;
}
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
_pl061
.
spinlock
,
level
);
#endif
}
static
void
pl061_pin_write
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
value
)
{
pl061_write8
(
BIT
(
pin
+
2
),
!!
value
<<
pin
);
}
static
int
pl061_pin_read
(
struct
rt_device
*
device
,
rt_base_t
pin
)
{
return
!!
pl061_read8
((
BIT
(
pin
+
2
)));
}
static
rt_err_t
pl061_pin_attach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
,
rt_uint32_t
mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
)
{
rt_uint8_t
gpiois
,
gpioibe
,
gpioiev
;
rt_uint8_t
bit
=
BIT
(
mode
);
#ifdef RT_USING_SMP
rt_base_t
level
;
#endif
if
(
pin
<
0
||
pin
>=
PL061_GPIO_NR
)
{
return
-
RT_EINVAL
;
}
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
_pl061
.
spinlock
);
#endif
gpioiev
=
pl061_read8
(
GPIOIEV
);
gpiois
=
pl061_read8
(
GPIOIS
);
gpioibe
=
pl061_read8
(
GPIOIBE
);
if
(
mode
==
PIN_IRQ_MODE_HIGH_LEVEL
||
pin
==
PIN_IRQ_MODE_LOW_LEVEL
)
{
rt_bool_t
polarity
=
(
mode
==
PIN_IRQ_MODE_HIGH_LEVEL
);
/* Disable edge detection */
gpioibe
&=
~
bit
;
/* Enable level detection */
gpiois
|=
bit
;
/* Select polarity */
if
(
polarity
)
{
gpioiev
|=
bit
;
}
else
{
gpioiev
&=
~
bit
;
}
}
else
if
(
mode
==
PIN_IRQ_MODE_RISING_FALLING
)
{
/* Disable level detection */
gpiois
&=
~
bit
;
/* Select both edges, setting this makes GPIOEV be ignored */
gpioibe
|=
bit
;
}
else
if
(
mode
==
PIN_IRQ_MODE_RISING
||
mode
==
PIN_IRQ_MODE_FALLING
)
{
rt_bool_t
rising
=
(
mode
==
PIN_IRQ_MODE_RISING
);
/* Disable level detection */
gpiois
&=
~
bit
;
/* Clear detection on both edges */
gpioibe
&=
~
bit
;
/* Select edge */
if
(
rising
)
{
gpioiev
|=
bit
;
}
else
{
gpioiev
&=
~
bit
;
}
}
else
{
/* No trigger: disable everything */
gpiois
&=
~
bit
;
gpioibe
&=
~
bit
;
gpioiev
&=
~
bit
;
}
pl061_write8
(
GPIOIS
,
gpiois
);
pl061_write8
(
GPIOIBE
,
gpioibe
);
pl061_write8
(
GPIOIEV
,
gpioiev
);
_pl061
.
hdr
[
pin
]
=
hdr
;
_pl061
.
args
[
pin
]
=
args
;
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
_pl061
.
spinlock
,
level
);
#endif
return
RT_EOK
;
}
static
rt_err_t
pl061_pin_detach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
)
{
if
(
pin
<
0
||
pin
>=
PL061_GPIO_NR
)
{
return
-
RT_EINVAL
;
}
_pl061
.
hdr
[
pin
]
=
RT_NULL
;
_pl061
.
args
[
pin
]
=
RT_NULL
;
return
RT_EOK
;
}
static
rt_err_t
pl061_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
)
{
rt_uint8_t
mask
=
BIT
(
pin
);
rt_uint8_t
gpioie
;
#ifdef RT_USING_SMP
rt_base_t
level
;
#endif
if
(
pin
<
0
||
pin
>=
PL061_GPIO_NR
)
{
return
-
RT_EINVAL
;
}
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
_pl061
.
spinlock
);
#endif
if
(
enabled
)
{
gpioie
=
pl061_read8
(
GPIOIE
)
|
mask
;
}
else
{
gpioie
=
pl061_read8
(
GPIOIE
)
&
~
mask
;
}
pl061_write8
(
GPIOIE
,
gpioie
);
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
_pl061
.
spinlock
,
level
);
#endif
return
RT_EOK
;
}
static
const
struct
rt_pin_ops
ops
=
{
pl061_pin_mode
,
pl061_pin_write
,
pl061_pin_read
,
pl061_pin_attach_irq
,
pl061_pin_detach_irq
,
pl061_pin_irq_enable
,
RT_NULL
,
};
static
void
rt_hw_gpio_isr
(
int
irqno
,
void
*
param
)
{
rt_uint8_t
mask
;
unsigned
long
pending
;
#ifdef RT_USING_SMP
rt_base_t
level
;
#endif
pending
=
pl061_read8
(
GPIOMIS
);
if
(
pending
)
{
rt_base_t
pin
;
for
(
pin
=
0
;
pin
<
PL061_GPIO_NR
;
++
pin
)
{
if
(
pending
&
BIT
(
pin
))
{
mask
|=
BIT
(
pin
);
if
(
_pl061
.
hdr
[
pin
]
!=
RT_NULL
)
{
_pl061
.
hdr
[
pin
](
_pl061
.
args
[
pin
]);
}
}
}
}
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
_pl061
.
spinlock
);
#endif
pl061_write8
(
GPIOIC
,
mask
);
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
_pl061
.
spinlock
,
level
);
#endif
}
int
rt_hw_gpio_init
(
void
)
{
#ifdef RT_USING_SMP
rt_spin_lock_init
(
&
_pl061
.
spinlock
);
#endif
rt_device_pin_register
(
"gpio"
,
&
ops
,
RT_NULL
);
rt_hw_interrupt_install
(
PL061_GPIO_IRQNUM
,
rt_hw_gpio_isr
,
RT_NULL
,
"gpio"
);
rt_hw_interrupt_umask
(
PL061_GPIO_IRQNUM
);
return
0
;
}
INIT_DEVICE_EXPORT
(
rt_hw_gpio_init
);
#endif
/* BSP_USING_PIN */
bsp/qemu-virt64-aarch64/driver/drv_gpio.h
0 → 100644
浏览文件 @
07a2e8c3
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-6-30 GuEe-GUI first version
*/
#ifndef DRV_GPIO_H__
#define DRV_GPIO_H__
int
rt_hw_gpio_init
(
void
);
#endif
bsp/qemu-virt64-aarch64/driver/drv_virtio.c
浏览文件 @
07a2e8c3
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
#ifdef BSP_USING_VIRTIO_NET
#ifdef BSP_USING_VIRTIO_NET
#include <virtio_net.h>
#include <virtio_net.h>
#endif
#endif
#ifdef BSP_USING_VIRTIO_CONSOLE
#include <virtio_console.h>
#endif
#ifdef BSP_USING_VIRTIO_GPU
#ifdef BSP_USING_VIRTIO_GPU
#include <virtio_gpu.h>
#include <virtio_gpu.h>
#endif
#endif
...
@@ -34,6 +37,9 @@ static virtio_device_init_handler virtio_device_init_handlers[] =
...
@@ -34,6 +37,9 @@ static virtio_device_init_handler virtio_device_init_handlers[] =
#ifdef BSP_USING_VIRTIO_NET
#ifdef BSP_USING_VIRTIO_NET
[
VIRTIO_DEVICE_ID_NET
]
=
rt_virtio_net_init
,
[
VIRTIO_DEVICE_ID_NET
]
=
rt_virtio_net_init
,
#endif
#endif
#ifdef BSP_USING_VIRTIO_CONSOLE
[
VIRTIO_DEVICE_ID_CONSOLE
]
=
rt_virtio_console_init
,
#endif
#ifdef BSP_USING_VIRTIO_GPU
#ifdef BSP_USING_VIRTIO_GPU
[
VIRTIO_DEVICE_ID_GPU
]
=
rt_virtio_gpu_init
,
[
VIRTIO_DEVICE_ID_GPU
]
=
rt_virtio_gpu_init
,
#endif
#endif
...
...
bsp/qemu-virt64-aarch64/driver/virt.h
浏览文件 @
07a2e8c3
...
@@ -23,6 +23,11 @@
...
@@ -23,6 +23,11 @@
#define PL031_RTC_SIZE 0x00001000
#define PL031_RTC_SIZE 0x00001000
#define PL031_RTC_IRQNUM (32 + 2)
#define PL031_RTC_IRQNUM (32 + 2)
/* GPIO */
#define PL061_GPIO_BASE 0x09030000
#define PL061_GPIO_SIZE 0x00001000
#define PL061_GPIO_IRQNUM (32 + 7)
/* VirtIO */
/* VirtIO */
#define VIRTIO_MMIO_BASE 0x0a000000
#define VIRTIO_MMIO_BASE 0x0a000000
#define VIRTIO_MMIO_SIZE 0x00000200
#define VIRTIO_MMIO_SIZE 0x00000200
...
...
bsp/qemu-virt64-aarch64/driver/virtio/virtio.c
浏览文件 @
07a2e8c3
...
@@ -54,11 +54,42 @@ void virtio_interrupt_ack(struct virtio_device *dev)
...
@@ -54,11 +54,42 @@ void virtio_interrupt_ack(struct virtio_device *dev)
}
}
}
}
rt_bool_t
virtio_has_feature
(
struct
virtio_device
*
dev
,
rt_uint32_t
feature_bit
)
{
_virtio_dev_check
(
dev
);
return
!!
(
dev
->
mmio_config
->
device_features
&
(
1UL
<<
feature_bit
));
}
rt_err_t
virtio_queues_alloc
(
struct
virtio_device
*
dev
,
rt_size_t
queues_num
)
{
_virtio_dev_check
(
dev
);
dev
->
queues
=
rt_malloc
(
sizeof
(
struct
virtq
)
*
queues_num
);
if
(
dev
->
queues
!=
RT_NULL
)
{
dev
->
queues_num
=
queues_num
;
return
RT_EOK
;
}
return
-
RT_ENOMEM
;
}
void
virtio_queues_free
(
struct
virtio_device
*
dev
)
{
if
(
dev
->
queues
!=
RT_NULL
)
{
dev
->
queues_num
=
0
;
rt_free
(
dev
->
queues
);
}
}
rt_err_t
virtio_queue_init
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
,
rt_size_t
ring_size
)
rt_err_t
virtio_queue_init
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
,
rt_size_t
ring_size
)
{
{
int
i
;
int
i
;
void
*
pages
;
void
*
pages
;
rt_ubase_t
pages_paddr
;
rt_size_t
pages_total_size
;
rt_size_t
pages_total_size
;
struct
virtq
*
queue
;
struct
virtq
*
queue
;
...
@@ -90,17 +121,16 @@ rt_err_t virtio_queue_init(struct virtio_device *dev, rt_uint32_t queue_index, r
...
@@ -90,17 +121,16 @@ rt_err_t virtio_queue_init(struct virtio_device *dev, rt_uint32_t queue_index, r
}
}
rt_memset
(
pages
,
0
,
pages_total_size
);
rt_memset
(
pages
,
0
,
pages_total_size
);
pages_paddr
=
VIRTIO_VA2PA
(
pages
);
dev
->
mmio_config
->
guest_page_size
=
VIRTIO_PAGE_SIZE
;
dev
->
mmio_config
->
guest_page_size
=
VIRTIO_PAGE_SIZE
;
dev
->
mmio_config
->
queue_sel
=
queue_index
;
dev
->
mmio_config
->
queue_sel
=
queue_index
;
dev
->
mmio_config
->
queue_num
=
ring_size
;
dev
->
mmio_config
->
queue_num
=
ring_size
;
dev
->
mmio_config
->
queue_align
=
VIRTIO_PAGE_SIZE
;
dev
->
mmio_config
->
queue_align
=
VIRTIO_PAGE_SIZE
;
dev
->
mmio_config
->
queue_pfn
=
pages_paddr
>>
VIRTIO_PAGE_SHIFT
;
dev
->
mmio_config
->
queue_pfn
=
VIRTIO_VA2PA
(
pages
)
>>
VIRTIO_PAGE_SHIFT
;
queue
->
num
=
ring_size
;
queue
->
num
=
ring_size
;
queue
->
desc
=
(
struct
virtq_desc
*
)
pages_paddr
;
queue
->
desc
=
(
struct
virtq_desc
*
)
((
rt_ubase_t
)
pages
)
;
queue
->
avail
=
(
struct
virtq_avail
*
)(
pages_paddr
+
VIRTQ_DESC_TOTAL_SIZE
(
ring_size
));
queue
->
avail
=
(
struct
virtq_avail
*
)(
((
rt_ubase_t
)
pages
)
+
VIRTQ_DESC_TOTAL_SIZE
(
ring_size
));
queue
->
used
=
(
struct
virtq_used
*
)
VIRTIO_PAGE_ALIGN
(
queue
->
used
=
(
struct
virtq_used
*
)
VIRTIO_PAGE_ALIGN
(
(
rt_ubase_t
)
&
queue
->
avail
->
ring
[
ring_size
]
+
VIRTQ_AVAIL_RES_SIZE
);
(
rt_ubase_t
)
&
queue
->
avail
->
ring
[
ring_size
]
+
VIRTQ_AVAIL_RES_SIZE
);
...
@@ -175,7 +205,7 @@ rt_uint16_t virtio_alloc_desc(struct virtio_device *dev, rt_uint32_t queue_index
...
@@ -175,7 +205,7 @@ rt_uint16_t virtio_alloc_desc(struct virtio_device *dev, rt_uint32_t queue_index
_virtio_dev_check
(
dev
);
_virtio_dev_check
(
dev
);
RT_ASSERT
(
queue_index
<
RT_USING_VIRTIO_QUEUE_MAX_NR
);
RT_ASSERT
(
queue_index
<
dev
->
queues_num
);
queue
=
&
dev
->
queues
[
queue_index
];
queue
=
&
dev
->
queues
[
queue_index
];
...
@@ -206,7 +236,7 @@ void virtio_free_desc(struct virtio_device *dev, rt_uint32_t queue_index, rt_uin
...
@@ -206,7 +236,7 @@ void virtio_free_desc(struct virtio_device *dev, rt_uint32_t queue_index, rt_uin
queue
=
&
dev
->
queues
[
queue_index
];
queue
=
&
dev
->
queues
[
queue_index
];
RT_ASSERT
(
queue_index
+
1
<
RT_USING_VIRTIO_QUEUE_MAX_NR
);
RT_ASSERT
(
queue_index
<
dev
->
queues_num
);
RT_ASSERT
(
!
queue
->
free
[
desc_index
]);
RT_ASSERT
(
!
queue
->
free
[
desc_index
]);
queue
->
desc
[
desc_index
].
addr
=
0
;
queue
->
desc
[
desc_index
].
addr
=
0
;
...
...
bsp/qemu-virt64-aarch64/driver/virtio/virtio.h
浏览文件 @
07a2e8c3
...
@@ -19,10 +19,6 @@
...
@@ -19,10 +19,6 @@
#define RT_USING_VIRTIO_VERSION 0x1
#define RT_USING_VIRTIO_VERSION 0x1
#endif
#endif
#ifndef RT_USING_VIRTIO_QUEUE_MAX_NR
#define RT_USING_VIRTIO_QUEUE_MAX_NR 4
#endif
#include <virtio_mmio.h>
#include <virtio_mmio.h>
#include <virtio_queue.h>
#include <virtio_queue.h>
...
@@ -102,7 +98,9 @@ struct virtio_device
...
@@ -102,7 +98,9 @@ struct virtio_device
{
{
rt_uint32_t
irq
;
rt_uint32_t
irq
;
struct
virtq
queues
[
RT_USING_VIRTIO_QUEUE_MAX_NR
];
struct
virtq
*
queues
;
rt_size_t
queues_num
;
union
union
{
{
rt_ubase_t
*
mmio_base
;
rt_ubase_t
*
mmio_base
;
...
@@ -122,7 +120,10 @@ void virtio_reset_device(struct virtio_device *dev);
...
@@ -122,7 +120,10 @@ void virtio_reset_device(struct virtio_device *dev);
void
virtio_status_acknowledge_driver
(
struct
virtio_device
*
dev
);
void
virtio_status_acknowledge_driver
(
struct
virtio_device
*
dev
);
void
virtio_status_driver_ok
(
struct
virtio_device
*
dev
);
void
virtio_status_driver_ok
(
struct
virtio_device
*
dev
);
void
virtio_interrupt_ack
(
struct
virtio_device
*
dev
);
void
virtio_interrupt_ack
(
struct
virtio_device
*
dev
);
rt_bool_t
virtio_has_feature
(
struct
virtio_device
*
dev
,
rt_uint32_t
feature_bit
);
rt_err_t
virtio_queues_alloc
(
struct
virtio_device
*
dev
,
rt_size_t
queues_num
);
void
virtio_queues_free
(
struct
virtio_device
*
dev
);
rt_err_t
virtio_queue_init
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
,
rt_size_t
ring_size
);
rt_err_t
virtio_queue_init
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
,
rt_size_t
ring_size
);
void
virtio_queue_destroy
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
);
void
virtio_queue_destroy
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
);
void
virtio_queue_notify
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
);
void
virtio_queue_notify
(
struct
virtio_device
*
dev
,
rt_uint32_t
queue_index
);
...
...
bsp/qemu-virt64-aarch64/driver/virtio/virtio_blk.c
浏览文件 @
07a2e8c3
...
@@ -29,6 +29,14 @@ static void virtio_blk_rw(struct virtio_blk_device *virtio_blk_dev, rt_off_t pos
...
@@ -29,6 +29,14 @@ static void virtio_blk_rw(struct virtio_blk_device *virtio_blk_dev, rt_off_t pos
/* Allocate 3 descriptors */
/* Allocate 3 descriptors */
while
(
virtio_alloc_desc_chain
(
virtio_dev
,
0
,
3
,
idx
))
while
(
virtio_alloc_desc_chain
(
virtio_dev
,
0
,
3
,
idx
))
{
{
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
virtio_dev
->
spinlock
,
level
);
#endif
rt_thread_yield
();
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
virtio_dev
->
spinlock
);
#endif
}
}
virtio_blk_dev
->
info
[
idx
[
0
]].
status
=
0xff
;
virtio_blk_dev
->
info
[
idx
[
0
]].
status
=
0xff
;
...
@@ -150,7 +158,6 @@ static void virtio_blk_isr(int irqno, void *param)
...
@@ -150,7 +158,6 @@ static void virtio_blk_isr(int irqno, void *param)
/* Done with buffer */
/* Done with buffer */
virtio_blk_dev
->
info
[
id
].
valid
=
RT_FALSE
;
virtio_blk_dev
->
info
[
id
].
valid
=
RT_FALSE
;
rt_thread_yield
();
queue
->
used_idx
++
;
queue
->
used_idx
++
;
}
}
...
@@ -200,12 +207,15 @@ rt_err_t rt_virtio_blk_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
...
@@ -200,12 +207,15 @@ rt_err_t rt_virtio_blk_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
/* Tell device that feature negotiation is complete and we're completely ready */
/* Tell device that feature negotiation is complete and we're completely ready */
virtio_status_driver_ok
(
virtio_dev
);
virtio_status_driver_ok
(
virtio_dev
);
if
(
virtio_queues_alloc
(
virtio_dev
,
1
)
!=
RT_EOK
)
{
goto
_alloc_fail
;
}
/* Initialize queue 0 */
/* Initialize queue 0 */
if
(
virtio_queue_init
(
virtio_dev
,
0
,
VIRTIO_BLK_QUEUE_RING_SIZE
)
!=
RT_EOK
)
if
(
virtio_queue_init
(
virtio_dev
,
0
,
VIRTIO_BLK_QUEUE_RING_SIZE
)
!=
RT_EOK
)
{
{
rt_free
(
virtio_blk_dev
);
goto
_alloc_fail
;
return
-
RT_ENOMEM
;
}
}
virtio_blk_dev
->
parent
.
type
=
RT_Device_Class_Block
;
virtio_blk_dev
->
parent
.
type
=
RT_Device_Class_Block
;
...
@@ -217,5 +227,14 @@ rt_err_t rt_virtio_blk_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
...
@@ -217,5 +227,14 @@ rt_err_t rt_virtio_blk_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
rt_hw_interrupt_umask
(
irq
);
rt_hw_interrupt_umask
(
irq
);
return
rt_device_register
((
rt_device_t
)
virtio_blk_dev
,
dev_name
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_REMOVABLE
);
return
rt_device_register
((
rt_device_t
)
virtio_blk_dev
,
dev_name
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_REMOVABLE
);
_alloc_fail:
if
(
virtio_blk_dev
!=
RT_NULL
)
{
virtio_queues_free
(
virtio_dev
);
rt_free
(
virtio_blk_dev
);
}
return
-
RT_ENOMEM
;
}
}
#endif
/* BSP_USING_VIRTIO_BLK */
#endif
/* BSP_USING_VIRTIO_BLK */
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.c
0 → 100644
浏览文件 @
07a2e8c3
此差异已折叠。
点击以展开。
bsp/qemu-virt64-aarch64/driver/virtio/virtio_console.h
0 → 100644
浏览文件 @
07a2e8c3
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-11 GuEe-GUI the first version
*/
#ifndef __VIRTIO_CONSOLE_H__
#define __VIRTIO_CONSOLE_H__
#include <rtdef.h>
#include <virtio.h>
#ifndef RT_USING_VIRTIO_CONSOLE_PORT_MAX_NR
#define RT_USING_VIRTIO_CONSOLE_PORT_MAX_NR 4
#endif
#define VIRTIO_CONSOLE_QUEUE_DATA_RX 0
#define VIRTIO_CONSOLE_QUEUE_DATA_TX 1
#define VIRTIO_CONSOLE_QUEUE_CTRL_RX 2
#define VIRTIO_CONSOLE_QUEUE_CTRL_TX 3
#define VIRTIO_CONSOLE_QUEUE_SIZE 64
/* Every port has data rx & tx, and port0 has ctrl rx & tx in multiport */
#define VIRTIO_CONSOLE_PORT_QUEUE_INDEX(id, queue) ((id) * 2 + (!!(id)) * 2 + (queue))
#define VIRTIO_CONSOLE_PORT_BAD_ID (~(rt_uint32_t)0)
#define VIRTIO_CONSOLE_F_SIZE 0
/* Does host provide console size? */
#define VIRTIO_CONSOLE_F_MULTIPORT 1
/* Does host provide multiple ports? */
#define VIRTIO_CONSOLE_F_EMERG_WRITE 2
/* Does host support emergency write? */
struct
virtio_console_config
{
rt_uint16_t
cols
;
rt_uint16_t
rows
;
rt_uint32_t
max_nr_ports
;
rt_uint32_t
emerg_wr
;
}
__attribute__
((
packed
));
struct
virtio_console_control
{
rt_uint32_t
id
;
/* Port number */
rt_uint16_t
event
;
/* The kind of control event */
rt_uint16_t
value
;
/* Extra information for the event */
};
enum
virtio_console_control_event
{
VIRTIO_CONSOLE_DEVICE_READY
=
0
,
VIRTIO_CONSOLE_PORT_ADD
,
VIRTIO_CONSOLE_PORT_REMOVE
,
VIRTIO_CONSOLE_PORT_READY
,
VIRTIO_CONSOLE_CONSOLE_PORT
,
VIRTIO_CONSOLE_RESIZE
,
VIRTIO_CONSOLE_PORT_OPEN
,
VIRTIO_CONSOLE_PORT_NAME
,
};
struct
virtio_console_resize
{
rt_uint16_t
cols
;
rt_uint16_t
rows
;
};
struct
virtio_console_device
{
struct
rt_device
parent
;
struct
virtio_device
virtio_dev
;
rt_uint32_t
console_id
;
rt_size_t
port_nr
;
rt_size_t
max_port_nr
;
rt_list_t
port_head
;
struct
virtio_console_config
*
config
;
struct
{
struct
virtio_console_control
rx_ctrl
,
tx_ctrl
;
}
info
[
VIRTIO_CONSOLE_QUEUE_SIZE
];
};
rt_err_t
rt_virtio_console_init
(
rt_ubase_t
*
mmio_base
,
rt_uint32_t
irq
);
enum
{
VIRTIO_DEVICE_CTRL_CONSOLE_PORT_CREATE
=
0x20
,
VIRTIO_DEVICE_CTRL_CONSOLE_PORT_DESTROY
,
};
#endif
/* __VIRTIO_CONSOLE_H__ */
bsp/qemu-virt64-aarch64/driver/virtio/virtio_gpu.c
浏览文件 @
07a2e8c3
...
@@ -74,6 +74,14 @@ static void virtio_gpu_ctrl_send_command(struct virtio_gpu_device *virtio_gpu_de
...
@@ -74,6 +74,14 @@ static void virtio_gpu_ctrl_send_command(struct virtio_gpu_device *virtio_gpu_de
while
(
virtio_alloc_desc_chain
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CTRL
,
2
,
idx
))
while
(
virtio_alloc_desc_chain
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CTRL
,
2
,
idx
))
{
{
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
virtio_dev
->
spinlock
,
level
);
#endif
rt_thread_yield
();
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
virtio_dev
->
spinlock
);
#endif
}
}
rt_hw_dsb
();
rt_hw_dsb
();
...
@@ -126,7 +134,17 @@ static void virtio_gpu_cursor_send_command(struct virtio_gpu_device *virtio_gpu_
...
@@ -126,7 +134,17 @@ static void virtio_gpu_cursor_send_command(struct virtio_gpu_device *virtio_gpu_
rt_base_t
level
=
rt_spin_lock_irqsave
(
&
virtio_dev
->
spinlock
);
rt_base_t
level
=
rt_spin_lock_irqsave
(
&
virtio_dev
->
spinlock
);
#endif
#endif
id
=
virtio_alloc_desc
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CURSOR
);
while
((
id
=
virtio_alloc_desc
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CURSOR
))
==
VIRTQ_INVALID_DESC_ID
)
{
#ifdef RT_USING_SMP
rt_spin_unlock_irqrestore
(
&
virtio_dev
->
spinlock
,
level
);
#endif
rt_thread_yield
();
#ifdef RT_USING_SMP
level
=
rt_spin_lock_irqsave
(
&
virtio_dev
->
spinlock
);
#endif
}
addr
=
&
virtio_gpu_dev
->
info
[
id
].
cursor_cmd
;
addr
=
&
virtio_gpu_dev
->
info
[
id
].
cursor_cmd
;
virtio_gpu_dev
->
info
[
id
].
cursor_valid
=
RT_TRUE
;
virtio_gpu_dev
->
info
[
id
].
cursor_valid
=
RT_TRUE
;
...
@@ -806,7 +824,6 @@ static void virtio_gpu_isr(int irqno, void *param)
...
@@ -806,7 +824,6 @@ static void virtio_gpu_isr(int irqno, void *param)
id
=
queue_ctrl
->
used
->
ring
[
queue_ctrl
->
used_idx
%
queue_ctrl
->
num
].
id
;
id
=
queue_ctrl
->
used
->
ring
[
queue_ctrl
->
used_idx
%
queue_ctrl
->
num
].
id
;
virtio_gpu_dev
->
info
[
id
].
ctrl_valid
=
RT_FALSE
;
virtio_gpu_dev
->
info
[
id
].
ctrl_valid
=
RT_FALSE
;
rt_thread_yield
();
queue_ctrl
->
used_idx
++
;
queue_ctrl
->
used_idx
++
;
}
}
...
@@ -817,7 +834,6 @@ static void virtio_gpu_isr(int irqno, void *param)
...
@@ -817,7 +834,6 @@ static void virtio_gpu_isr(int irqno, void *param)
id
=
queue_cursor
->
used
->
ring
[
queue_cursor
->
used_idx
%
queue_cursor
->
num
].
id
;
id
=
queue_cursor
->
used
->
ring
[
queue_cursor
->
used_idx
%
queue_cursor
->
num
].
id
;
virtio_gpu_dev
->
info
[
id
].
cursor_valid
=
RT_FALSE
;
virtio_gpu_dev
->
info
[
id
].
cursor_valid
=
RT_FALSE
;
rt_thread_yield
();
queue_cursor
->
used_idx
++
;
queue_cursor
->
used_idx
++
;
}
}
...
@@ -866,6 +882,11 @@ rt_err_t rt_virtio_gpu_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
...
@@ -866,6 +882,11 @@ rt_err_t rt_virtio_gpu_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
virtio_status_driver_ok
(
virtio_dev
);
virtio_status_driver_ok
(
virtio_dev
);
if
(
virtio_queues_alloc
(
virtio_dev
,
2
)
!=
RT_EOK
)
{
goto
_alloc_fail
;
}
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CTRL
,
VIRTIO_GPU_QUEUE_SIZE
)
!=
RT_EOK
)
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_GPU_QUEUE_CTRL
,
VIRTIO_GPU_QUEUE_SIZE
)
!=
RT_EOK
)
{
{
goto
_alloc_fail
;
goto
_alloc_fail
;
...
@@ -896,6 +917,7 @@ _alloc_fail:
...
@@ -896,6 +917,7 @@ _alloc_fail:
if
(
virtio_gpu_dev
!=
RT_NULL
)
if
(
virtio_gpu_dev
!=
RT_NULL
)
{
{
virtio_queues_free
(
virtio_dev
);
rt_free
(
virtio_gpu_dev
);
rt_free
(
virtio_gpu_dev
);
}
}
return
-
RT_ENOMEM
;
return
-
RT_ENOMEM
;
...
...
bsp/qemu-virt64-aarch64/driver/virtio/virtio_input.c
浏览文件 @
07a2e8c3
...
@@ -372,6 +372,11 @@ rt_err_t rt_virtio_input_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
...
@@ -372,6 +372,11 @@ rt_err_t rt_virtio_input_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
virtio_status_driver_ok
(
virtio_dev
);
virtio_status_driver_ok
(
virtio_dev
);
if
(
virtio_queues_alloc
(
virtio_dev
,
2
)
!=
RT_EOK
)
{
goto
_alloc_fail
;
}
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_INPUT_QUEUE_EVENT
,
VIRTIO_INPUT_EVENT_QUEUE_SIZE
)
!=
RT_EOK
)
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_INPUT_QUEUE_EVENT
,
VIRTIO_INPUT_EVENT_QUEUE_SIZE
)
!=
RT_EOK
)
{
{
goto
_alloc_fail
;
goto
_alloc_fail
;
...
@@ -425,6 +430,7 @@ _alloc_fail:
...
@@ -425,6 +430,7 @@ _alloc_fail:
if
(
virtio_input_dev
!=
RT_NULL
)
if
(
virtio_input_dev
!=
RT_NULL
)
{
{
virtio_queues_free
(
virtio_dev
);
rt_free
(
virtio_input_dev
);
rt_free
(
virtio_input_dev
);
}
}
return
-
RT_ENOMEM
;
return
-
RT_ENOMEM
;
...
...
bsp/qemu-virt64-aarch64/driver/virtio/virtio_net.c
浏览文件 @
07a2e8c3
...
@@ -269,6 +269,11 @@ rt_err_t rt_virtio_net_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
...
@@ -269,6 +269,11 @@ rt_err_t rt_virtio_net_init(rt_ubase_t *mmio_base, rt_uint32_t irq)
virtio_status_driver_ok
(
virtio_dev
);
virtio_status_driver_ok
(
virtio_dev
);
if
(
virtio_queues_alloc
(
virtio_dev
,
2
)
!=
RT_EOK
)
{
goto
_alloc_fail
;
}
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_NET_QUEUE_RX
,
VIRTIO_NET_RTX_QUEUE_SIZE
)
!=
RT_EOK
)
if
(
virtio_queue_init
(
virtio_dev
,
VIRTIO_NET_QUEUE_RX
,
VIRTIO_NET_RTX_QUEUE_SIZE
)
!=
RT_EOK
)
{
{
goto
_alloc_fail
;
goto
_alloc_fail
;
...
@@ -301,6 +306,7 @@ _alloc_fail:
...
@@ -301,6 +306,7 @@ _alloc_fail:
if
(
virtio_net_dev
!=
RT_NULL
)
if
(
virtio_net_dev
!=
RT_NULL
)
{
{
virtio_queues_free
(
virtio_dev
);
rt_free
(
virtio_net_dev
);
rt_free
(
virtio_net_dev
);
}
}
return
-
RT_ENOMEM
;
return
-
RT_ENOMEM
;
...
...
bsp/qemu-virt64-aarch64/qemu-graphic.bat
浏览文件 @
07a2e8c3
...
@@ -9,4 +9,5 @@ qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -smp 4 -kernel rtthrea
...
@@ -9,4 +9,5 @@ qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -smp 4 -kernel rtthrea
-device
virtio
-gpu-device
,
xres
=
800
,
yres
=
600
,
bus
=
virtio
-mmio-bus
.2
^
-device
virtio
-gpu-device
,
xres
=
800
,
yres
=
600
,
bus
=
virtio
-mmio-bus
.2
^
-device
virtio
-keyboard-device
,
bus
=
virtio
-mmio-bus
.3
^
-device
virtio
-keyboard-device
,
bus
=
virtio
-mmio-bus
.3
^
-device
virtio
-mouse-device
,
bus
=
virtio
-mmio-bus
.4
^
-device
virtio
-mouse-device
,
bus
=
virtio
-mmio-bus
.4
^
-device
virtio
-tablet-device
,
bus
=
virtio
-mmio-bus
.5
-device
virtio
-tablet-device
,
bus
=
virtio
-mmio-bus
.5
^
-device
virtio
-serial-device -chardev
socket
,
host
=
127
.0.0.1
,
port
=
4321
,
server
=
on
,
wait
=
off
,
telnet
=
on
,
id
=
console0
-device
virtserialport
,
chardev
=
console0
bsp/qemu-virt64-aarch64/qemu-graphic.sh
浏览文件 @
07a2e8c3
...
@@ -7,4 +7,5 @@ qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -smp 4 -kernel rtthrea
...
@@ -7,4 +7,5 @@ qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -smp 4 -kernel rtthrea
-device
virtio-gpu-device,xres
=
800,yres
=
600,bus
=
virtio-mmio-bus.2
\
-device
virtio-gpu-device,xres
=
800,yres
=
600,bus
=
virtio-mmio-bus.2
\
-device
virtio-keyboard-device,bus
=
virtio-mmio-bus.3
\
-device
virtio-keyboard-device,bus
=
virtio-mmio-bus.3
\
-device
virtio-mouse-device,bus
=
virtio-mmio-bus.4
\
-device
virtio-mouse-device,bus
=
virtio-mmio-bus.4
\
-device
virtio-tablet-device,bus
=
virtio-mmio-bus.5
-device
virtio-tablet-device,bus
=
virtio-mmio-bus.5
\
-device
virtio-serial-device
-chardev
socket,host
=
127.0.0.1,port
=
4321,server
=
on,wait
=
off,telnet
=
on,id
=
console0
-device
virtserialport,chardev
=
console0
bsp/qemu-virt64-aarch64/qemu.bat
浏览文件 @
07a2e8c3
...
@@ -5,4 +5,5 @@ qemu-img create -f raw sd.bin 64M
...
@@ -5,4 +5,5 @@ qemu-img create -f raw sd.bin 64M
:run
:run
qemu
-system-aarch
64
-M
virt
,
gic
-version
=
2
-cpu
cortex
-a
53
-smp
4
-kernel
rtthread
.elf
-nographic
^
qemu
-system-aarch
64
-M
virt
,
gic
-version
=
2
-cpu
cortex
-a
53
-smp
4
-kernel
rtthread
.elf
-nographic
^
-drive
if
=
none
,
file
=
sd
.bin
,
format
=
raw
,
id
=
blk0
-device
virtio
-blk-device
,
drive
=
blk0
,
bus
=
virtio
-mmio-bus
.0
^
-drive
if
=
none
,
file
=
sd
.bin
,
format
=
raw
,
id
=
blk0
-device
virtio
-blk-device
,
drive
=
blk0
,
bus
=
virtio
-mmio-bus
.0
^
-netdev
user
,
id
=
net0
-device
virtio
-net-device
,
netdev
=
net0
,
bus
=
virtio
-mmio-bus
.1
-netdev
user
,
id
=
net0
-device
virtio
-net-device
,
netdev
=
net0
,
bus
=
virtio
-mmio-bus
.1
^
-device
virtio
-serial-device -chardev
socket
,
host
=
127
.0.0.1
,
port
=
4321
,
server
=
on
,
wait
=
off
,
telnet
=
on
,
id
=
console0
-device
virtserialport
,
chardev
=
console0
bsp/qemu-virt64-aarch64/qemu.sh
浏览文件 @
07a2e8c3
...
@@ -3,4 +3,5 @@ dd if=/dev/zero of=sd.bin bs=1024 count=65536
...
@@ -3,4 +3,5 @@ dd if=/dev/zero of=sd.bin bs=1024 count=65536
fi
fi
qemu-system-aarch64
-M
virt,gic-version
=
2
-cpu
cortex-a53
-smp
4
-kernel
rtthread.elf
-nographic
\
qemu-system-aarch64
-M
virt,gic-version
=
2
-cpu
cortex-a53
-smp
4
-kernel
rtthread.elf
-nographic
\
-drive
if
=
none,file
=
sd.bin,format
=
raw,id
=
blk0
-device
virtio-blk-device,drive
=
blk0,bus
=
virtio-mmio-bus.0
\
-drive
if
=
none,file
=
sd.bin,format
=
raw,id
=
blk0
-device
virtio-blk-device,drive
=
blk0,bus
=
virtio-mmio-bus.0
\
-netdev
user,id
=
net0
-device
virtio-net-device,netdev
=
net0,bus
=
virtio-mmio-bus.1
-netdev
user,id
=
net0
-device
virtio-net-device,netdev
=
net0,bus
=
virtio-mmio-bus.1
\
-device
virtio-serial-device
-chardev
socket,host
=
127.0.0.1,port
=
4321,server
=
on,wait
=
off,telnet
=
on,id
=
console0
-device
virtserialport,chardev
=
console0
bsp/qemu-virt64-aarch64/rtconfig.h
浏览文件 @
07a2e8c3
...
@@ -241,9 +241,6 @@
...
@@ -241,9 +241,6 @@
/* enhanced kernel services */
/* enhanced kernel services */
/* POSIX extension functions */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* acceleration: Assembly language or algorithmic acceleration packages */
...
@@ -276,8 +273,10 @@
...
@@ -276,8 +273,10 @@
#define RT_USING_UART0
#define RT_USING_UART0
#define BSP_USING_RTC
#define BSP_USING_RTC
#define BSP_USING_ALARM
#define BSP_USING_ALARM
#define BSP_USING_PIN
#define BSP_USING_VIRTIO_BLK
#define BSP_USING_VIRTIO_BLK
#define BSP_USING_VIRTIO_NET
#define BSP_USING_VIRTIO_NET
#define BSP_USING_VIRTIO_CONSOLE
#define BSP_USING_VIRTIO_GPU
#define BSP_USING_VIRTIO_GPU
#define BSP_USING_VIRTIO_INPUT
#define BSP_USING_VIRTIO_INPUT
#define BSP_USING_GIC
#define BSP_USING_GIC
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录