Skip to content

Commit 320b591

Browse files
author
deployBot
committed
Deploy at Thu Apr 11 02:40:08 UTC 2024
1 parent a1744aa commit 320b591

36 files changed

+202
-234
lines changed
Lines changed: 58 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,83 @@
11
==========================
2-
Assignment 2 - Driver UART
2+
作业 2——驱动 UART
33
==========================
44

5-
- Deadline: :command:`Sunday, 30 April 2023, 23:00`
6-
- The assigment is individual
5+
- 截止日期: :command:`2023 年 4 月 30 日,23:00`
6+
- 此作业为个人完成
77

8-
Assignment's Objectives
8+
作业目标
99
=======================
1010

11-
* consolidating the knowledge of device drivers
12-
* read hardware documentation and track the desired functionality in the documentation
13-
* work with interrupts; use of non-blocking functions in interrupt context
14-
* use of buffers; synchronization
15-
* kernel modules with parameters
11+
* 巩固设备驱动的知识
12+
* 阅读硬件文档并在文档中追踪所需功能
13+
* 使用中断;在中断上下文中使用非阻塞函数
14+
* 使用缓冲区;同步
15+
* 带参数的内核模块
1616

17-
Statement
17+
任务描述
1818
=========
1919

20-
Write a kernel module that implements a driver for the serial port (`UART16550`).
21-
The device driver must support the two standard serial ports in a PC, `COM1` and `COM2` (`0x3f8` and `0x2f8`,
22-
in fact the entire range of `8` addresses `0x3f8-0x3ff` and `0x2f8-0x2ff` specific to the two ports).
23-
In addition to the standard routines (`open`, `read`, `write`, `close`),
24-
the driver must also have support for changing communication parameters using an `ioctl` operation (`UART16550_IOCTL_SET_LINE`).
20+
编写一个内核模块,实现串口 (`UART16550`) 的驱动程序。该设备驱动程序必须支持计算机中的两个标准串口, `COM1` 和 `COM2` (`0x3f8` 和 `0x2f8`,实际上是两个串口的整个 `8` 地址范围 `0x3f8-0x3ff` 和 `0x2f8-0x2ff`)。除了标准例程 (`open`, `read`, `write`, `close`) 外,驱动程序还必须支持使用 `ioctl` 操作 (`UART16550_IOCTL_SET_LINE`) 更改通信参数。
2521

26-
The driver must use interrupts for both reception and transmission to reduce latency and CPU usage time.
27-
`Read` and `write` calls must also be blocking. :command:`Assignments that do not meet these requirements will not be considered.`
28-
It is recommended that you use a buffer for the read routine and another buffer for the write routine for each serial port in the driver.
22+
驱动程序必须使用中断来进行接收和发送,以减少延迟和 CPU 使用时间。 `read` 和 `write` 调用也必须是阻塞的。 :command:`不符合这些要求的作业将不予考虑。` 建议你为驱动程序中每个串行端口的读取例程使用一个缓冲区,并为写入例程使用另一个缓冲区。
2923

30-
A blocking read call means that the read routine called from the user-space will be blocked until :command:`at least` one byte is read
31-
(the read buffer in the kernel is empty and no data can be read).
32-
A blocking write call means that the write routine called from the user-space will be blocked until :command:`at least` one byte is written
33-
(the write buffer in the kernel is full and no data can be written).
24+
当用户空间发起读取操作时,如果内核的读缓冲区为空,没有数据可读,那么阻塞读调用将会等待,直到 :command:`至少` 有一个字节被读取。同样,当用户空间发起写入操作时,如果内核的写缓冲区已满,没有空间可写,那么阻塞写调用也将会等待,直到 :command:`至少` 有一个字节被写入。
3425

35-
Buffers Scheme
26+
缓冲区方案
3627
--------------
3728

3829
.. image:: ../img/buffers-scheme.png
3930

40-
Data transfer between the various buffers is a `Producer-Consumer <https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem>`__ problem. Example:
31+
各个缓冲区之间的数据传输是 `生产者-消费者 <https://zh.wikipedia.org/zh-cn/生产者消费者问题>`__ 问题。例如:
4132

42-
- The process is the producer and the device is the consumer if it is written from the process to the device; the process will block until there is at least one free space in the consumer's buffer
33+
- 如果从进程写入设备,则进程是生产者,设备是消费者;如果消费者缓冲区没有剩余空间,则进程将被阻塞,直到消费者缓冲区至少有一个空闲空间为止。
4334

44-
- The process is the consumer and the device is the producer if it is read from a process from the device; the process will block until there is at least one element in the producer's buffer.
35+
- 如果从设备读取数据到进程中,则进程是消费者,设备是生产者;如果生产者缓冲区没有内容,进程将被阻塞,直到生产者的缓冲区中至少有一个元素为止。
4536

46-
Implementation Details
37+
实现细节
4738
======================
4839

49-
- the driver will be implemented as a kernel module named :command:`uart16550.ko`
50-
- the driver will be accessed as a character device driver, with different functions depending on the parameters transmitted to the load module:
40+
- 该驱动程序以名为 :command:`uart16550.ko` 的内核模块形式实现。
41+
- 该驱动程序是字符设备驱动,会根据传递给加载模块的参数,提供不同的功能操作。
5142

52-
- the `major` parameter will specify the major with which the device must be registered
53-
- the `option` parameter will specify how it works:
43+
- `major` 参数指定设备必须注册的主设备号。
44+
- `option` 参数指定驱动程序的工作方式:
5445

55-
- OPTION_BOTH: will also register COM1 and COM2, with the major given by the `major` parameter and the minors 0 (for COM1) and 1 (for COM2);
56-
- OPTION_COM1: will only register COM1, with the major `major` and minor 0;
57-
- OPTION_COM2: will only register COM2, with the major `major` and minor 1;
58-
- to learn how to pass parameters in Linux, see `tldp <https://tldp.org/LDP/lkmpg/2.6/html/x323.html>`__
59-
- the default values are `major=42` and `option=OPTION_BOTH`.
60-
- the interrupt number associated with COM1 is 4 (`IRQ_COM1`) and the interrupt number associated with COM2 is 3 (`IRQ_COM2`)
61-
- `the header <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/src/uart16550.h>`__ with the definitions needed for special operations;
62-
- a starting point in implementing read / write routines is the `example <https://ocw.cs.pub.ro/courses/so2/laboratoare/lab04?&#sincronizare_-_cozi_de_asteptare>`__ of uppercase / lowercase character device driver; the only difference is that you have to use two buffers, one for read and one for write;
63-
- you can use `kfifo <https://lwn.net/Articles/347619/>`__ for buffers;
64-
- you do not have to use deferred functions to read / write data from / to ports (you can do everything from interrupt context);
65-
- you will need to synchronize the read / write routines with the interrupt handling routine for the routines to be blocking; it is recommended to use `synchronization with waiting queues <https://ocw.cs.pub.ro/courses/so2/laboratoare/lab04?&#sincronizare_-_cozi_de_asteptare>`__
66-
- In order for the assigment to work, the `default serial driver` must be disabled:
46+
- OPTION_BOTH:还会注册 COM1 COM2,主设备号由 `major` 参数给出,次设备号为 0(对应 COM1)和 1(对应 COM2);
47+
- OPTION_COM1:仅注册 COM1,主设备号为 `major`,次设备号为 0。
48+
- OPTION_COM2:仅注册 COM2,主设备号为 `major`,次设备号为 1。
49+
- 如果你不熟悉如何在 Linux 中传递参数,请参阅 `tldp <https://tldp.org/LDP/lkmpg/2.6/html/x323.html>`__
50+
- 默认值为 `major=42` `option=OPTION_BOTH`
51+
- COM1 关联的中断号为 4 (`IRQ_COM1`)COM2 关联的中断号为 3 (`IRQ_COM2`)
52+
- 需要使用 `header <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/src/uart16550.h>`__ 中的定义来进行特殊操作。
53+
- 在实现读/写例程时,可以参考大写/小写字符设备驱动程序的 `示例 <https://ocw.cs.pub.ro/courses/so2/laboratoare/lab04?&#sincronizare_-_cozi_de_asteptare>`__;唯一的区别是你需要使用两个缓冲区,一个用于读取,另一个用于写入。
54+
- 可以使用 `kfifo <https://lwn.net/Articles/347619/>`__ 作为缓冲区。
55+
- 不需要使用延迟函数从端口读取/写入数据(可以在中断上下文中完成所有操作)。
56+
- 需要在读/写例程与中断处理例程之间进行同步,以使例程成为阻塞例程;建议使用 `等待队列进行同步 <https://ocw.cs.pub.ro/courses/so2/laboratoare/lab04?&#sincronizare_-_cozi_de_asteptare>`__
57+
- 为了使作业正常工作,必须禁用 `默认串口驱动程序`:
6758

68-
- `cat /proc/ioports | grep serial` will detect the presence of the default driver on the regions where COM1 and COM2 are defined
69-
- in order to deactivate it, the kernel must be recompiled, either by setting the serial driver as the module, or by deactivating it completely (this modification is already made on the virtual machine)
59+
- `cat /proc/ioports | grep serial` 可以检测到默认驱动程序是否存在于定义 COM1 COM2 的区域。
60+
- 为了停用它,必须重新编译内核,可以将串口驱动程序设置为模块,或者完全停用它(虚拟机上已经进行了这个修改)。
7061

7162
- `Device Drivers -> Character devices -> Serial driver -> 8250/16550 and compatible serial support.`
7263

73-
Testing
64+
测试
7465
=======
75-
In order to simplify the assignment evaluation process, but also to reduce the mistakes of the submitted assignments,
76-
the assignment evaluation will be done automatically with the help of a
77-
`test script <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/checker/2-uart-checker/_checker>`__ called `_checker`.
78-
The test script assumes that the kernel module is called `uart16550.ko`.
7966

80-
QuickStart
67+
为了简化作业评估过程,同时也为了减少提交作业时的错误,作业评估将通过一个名为 `_checker` 的 `测试脚本 <https://github.com/linux-kernel-labs/linux/blob/master/tools/labs/templates/assignments/2-uart-checker/checker/_checker>`__ 自动进行。测试脚本假定内核模块名为 `uart16550.ko`。
68+
69+
快速开始
8170
==========
8271

83-
It is mandatory to start the implementation of the assignment from the code skeleton found in the `src <https://gitlab.cs.pub.ro/so2/2-uart/-/tree/master/src>`__ directory.
84-
There is only one header in the skeleton called `uart16550.h <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/src/uart16550.h>`__.
85-
You will provide the rest of the implementation. You can add as many `*.c`` sources and additional `*.h`` headers.
86-
You should also provide a Kbuild file that will compile the kernel module called `uart16550.ko`.
87-
Follow the instructions in the `README.md file <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__ of the `assignment's repo <https://gitlab.cs.pub.ro/so2/2-uart>`__.
72+
你必须从 `src <https://gitlab.cs.pub.ro/so2/2-uart/-/tree/master/src>`__ 目录中的代码模板开始实现作业。模板中只有一个名为 `uart16550.h <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/src/uart16550.h>`__ 的头文件。你需要提供其余的实现。你可以添加任意数量的 `*.c` 源文件和额外的 `*.h` 头文件。你还应该提供一个名为 `uart16550.ko` 的 Kbuild 文件来编译内核模块。请按照 `作业仓库 <https://gitlab.cs.pub.ro/so2/2-uart>`__ 的 `README.md 文件 <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__ 中的说明进行操作。
8873

8974

90-
Tips
75+
提示
9176
----
9277

93-
To increase your chances of getting the highest grade, read and follow the Linux kernel
94-
coding style described in the `Coding Style document <https://elixir.bootlin.com/linux/v4.19.19/source/Documentation/process/coding-style.rst>`__.
78+
要想增加获得最高分的机会,请阅读并遵循 Linux 内核中描述的 `编码风格规范 <https://elixir.bootlin.com/linux/v4.19.19/source/Documentation/process/coding-style.rst>`__。
9579

96-
Also, use the following static analysis tools to verify the code:
80+
此外,使用以下静态分析工具来验证代码:
9781

9882
- checkpatch.pl
9983

@@ -116,37 +100,31 @@ Also, use the following static analysis tools to verify the code:
116100
$ sudo apt-get install cppcheck
117101
$ cppcheck /path/to/your/list.c
118102
119-
Penalties
120-
---------
103+
扣分规则
104+
----------
121105

122-
Information about assigments penalties can be found on the
123-
`General Directions page <https://ocw.cs.pub.ro/courses/so2/teme/general>`__.
106+
有关作业扣分的信息可以在“基本说明页面 <https://ocw.cs.pub.ro/courses/so2/teme/general>`__ 上找到。
124107

125-
In exceptional cases (the assigment passes the tests by not complying with the requirements)
126-
and if the assigment does not pass all the tests, the grade will may decrease more than mentioned above.
108+
在特殊情况下(作业通过了测试但不符合要求),以及如果作业未全部通过测试,成绩可能会降低得更多。
127109

128-
Submitting the assigment
110+
提交作业
129111
------------------------
130112

131-
The assignment will be graded automatically using the `vmchecker-next <https://github.com/systems-cs-pub-ro/vmchecker-next/wiki/Student-Handbook>`__ infrastructure.
132-
The submission will be made on moodle on the `course's page <https://curs.upb.ro/2022/course/view.php?id=5121>`__ to the related assignment.
133-
You will find the submission details in the `README.md file <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__ of the `repo <https://gitlab.cs.pub.ro/so2/2-uart>`__.
113+
作业将由 `vmchecker-next <https://github.com/systems-cs-pub-ro/vmchecker-next/wiki/Student-Handbook>`__ 基础设施自动评分。提交作业将在 moodle 的 `课程页面 <https://curs.upb.ro/2022/course/view.php?id=5121>`__ 上与相关作业相关联。你可以在 `仓库 <https://gitlab.cs.pub.ro/so2/2-uart>`__ 的 `README.md 文件 <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__ 中找到提交详细信息。
134114

135115

136-
Resources
116+
资源
137117
=========
138118

139-
- serial port documentation can be found on `tldp <https://tldp.org/HOWTO/Serial-HOWTO-19.html>`__
140-
- `table with registers <http://www.byterunner.com/16550.html>`__
141-
- `datasheet 16550 <https://pdf1.alldatasheet.com/datasheet-pdf/view/9301/NSC/PC16550D.html>`__
142-
- `alternative documentation <https://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming>`__
119+
- 串口文档可以在 `tldp <https://tldp.org/HOWTO/Serial-HOWTO-19.html>`__ 上找到。
120+
- `寄存器表 <http://www.byterunner.com/16550.html>`__
121+
- `16550 数据手册 <https://pdf1.alldatasheet.com/datasheet-pdf/view/9301/NSC/PC16550D.html>`__
122+
- `备选文档 <https://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming>`__
143123

144-
We recommend that you use gitlab to store your homework. Follow the directions in
145-
`README <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__.
124+
我们建议你使用 GitLab 存储作业。请按照 `README <https://gitlab.cs.pub.ro/so2/2-uart/-/blob/master/README.md>`__ 中的说明操作。
146125

147126

148-
Questions
127+
问题
149128
=========
150129

151-
For questions about the topic, you can consult the mailing `list archives <http://cursuri.cs.pub.ro/pipermail/so2/>`__
152-
or you can write a question on the dedicated Teams channel.
130+
如有相关问题,你可以参考邮件 `列表存档 <http://cursuri.cs.pub.ro/pipermail/so2/>`__ 或在专用的 Teams 频道上提问。

index.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -962,22 +962,22 @@ <h1>Linux 内核教学<a class="headerlink" href="#linux" title="永久链接至
962962
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-10">问题</a></li>
963963
</ul>
964964
</li>
965-
<li class="toctree-l2"><a class="reference internal" href="so2/assign2-driver-uart.html">Assignment 2 - Driver UART</a><ul>
966-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#assignment-s-objectives">Assignment's Objectives</a></li>
967-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#statement">Statement</a><ul>
968-
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#buffers-scheme">Buffers Scheme</a></li>
965+
<li class="toctree-l2"><a class="reference internal" href="so2/assign2-driver-uart.html">作业 2——驱动 UART</a><ul>
966+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-1">作业目标</a></li>
967+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-2">任务描述</a><ul>
968+
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#section-3">缓冲区方案</a></li>
969969
</ul>
970970
</li>
971-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#implementation-details">Implementation Details</a></li>
972-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#testing">Testing</a></li>
973-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#quickstart">QuickStart</a><ul>
974-
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#tips">Tips</a></li>
975-
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#penalties">Penalties</a></li>
976-
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#submitting-the-assigment">Submitting the assigment</a></li>
971+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-4">实现细节</a></li>
972+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-5">测试</a></li>
973+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-6">快速开始</a><ul>
974+
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#section-7">提示</a></li>
975+
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#section-8">扣分规则</a></li>
976+
<li class="toctree-l4"><a class="reference internal" href="so2/assign2-driver-uart.html#section-9">提交作业</a></li>
977977
</ul>
978978
</li>
979-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#resources">Resources</a></li>
980-
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#questions">Questions</a></li>
979+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-10">资源</a></li>
980+
<li class="toctree-l3"><a class="reference internal" href="so2/assign2-driver-uart.html#section-11">问题</a></li>
981981
</ul>
982982
</li>
983983
<li class="toctree-l2"><a class="reference internal" href="so2/assign3-software-raid.html">Assignment 3 - Software RAID</a><ul>

objects.inv

-11 Bytes
Binary file not shown.

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

so2/assign-collaboration.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</li>
9494
<li class="toctree-l2"><a class="reference internal" href="assign0-kernel-api.html">作业 0——内核 API</a></li>
9595
<li class="toctree-l2"><a class="reference internal" href="assign1-kprobe-based-tracer.html">作业 1——基于 Kprobe 的跟踪器</a></li>
96-
<li class="toctree-l2"><a class="reference internal" href="assign2-driver-uart.html">Assignment 2 - Driver UART</a></li>
96+
<li class="toctree-l2"><a class="reference internal" href="assign2-driver-uart.html">作业 2——驱动 UART</a></li>
9797
<li class="toctree-l2"><a class="reference internal" href="assign3-software-raid.html">Assignment 3 - Software RAID</a></li>
9898
<li class="toctree-l2"><a class="reference internal" href="assign4-transport-protocol.html">Assignment 4 - SO2 Transport Protocol</a></li>
9999
<li class="toctree-l2"><a class="reference internal" href="assign7-kvm-vmm.html">Assignment 7 - SO2 Virtual Machine Manager with KVM</a></li>

so2/assign0-kernel-api.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
</ul>
9999
</li>
100100
<li class="toctree-l2"><a class="reference internal" href="assign1-kprobe-based-tracer.html">作业 1——基于 Kprobe 的跟踪器</a></li>
101-
<li class="toctree-l2"><a class="reference internal" href="assign2-driver-uart.html">Assignment 2 - Driver UART</a></li>
101+
<li class="toctree-l2"><a class="reference internal" href="assign2-driver-uart.html">作业 2——驱动 UART</a></li>
102102
<li class="toctree-l2"><a class="reference internal" href="assign3-software-raid.html">Assignment 3 - Software RAID</a></li>
103103
<li class="toctree-l2"><a class="reference internal" href="assign4-transport-protocol.html">Assignment 4 - SO2 Transport Protocol</a></li>
104104
<li class="toctree-l2"><a class="reference internal" href="assign7-kvm-vmm.html">Assignment 7 - SO2 Virtual Machine Manager with KVM</a></li>

0 commit comments

Comments
 (0)