@@ -400,35 +400,33 @@ <h3>1. 将连续的物理内存映射到用户空间<a class="headerlink" href="
400
400
</ div >
401
401
< div class ="section " id ="section-9 ">
402
402
< h3 > 2. 将非连续的物理内存映射到用户空间< a class ="headerlink " href ="#section-9 " title ="Permalink to this headline "> ¶</ a > </ h3 >
403
- < p > 实现一个设备驱动程序,将非连续的物理内存(例如通过:c:func: < a href =" #system-message-1 "> < span class ="problematic " id =" problematic-1 " > ` </ span > </ a > vmalloc` 获得的内存)映射到用户空间。</ p >
404
- < p > 查看`设备驱动程序内存映射`_部分 ,生成名为** vmmap** 的任务的框架,并填写标有** TODO 1** 的区域。</ p >
405
- < p > 使用:c:func: < a href =" #system-message-2 "> < span class ="problematic " id =" problematic-2 " > ` </ span > </ a > vmalloc`分配一个NPAGES大小的内存区域 。</ p >
403
+ < p > 实现一个设备驱动程序,将非连续的物理内存(例如通过 < code class =" xref c c-func docutils literal "> < span class ="pre " > vmalloc() </ span > </ code > 获得的内存)映射到用户空间。</ p >
404
+ < p > 查看 < a class =" reference internal " href =" #section-5 " > 设备驱动程序的内存映射 </ a > 部分 ,生成名为 < strong > vmmap</ strong > 的任务的框架,并填写标有 < strong > TODO 1</ strong > 的区域。</ p >
405
+ < p > 使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > vmalloc() </ span > </ code > 分配一个 NPAGES 大小的内存区域 。</ p >
406
406
< div class ="admonition hint ">
407
407
< p class ="first admonition-title "> Hint</ p >
408
- < p class ="last "> 一个页面的大小为*PAGE_SIZE*。
409
- 将分配的区域存储在*vmalloc_area*中。
410
- 由:c:func:< a href ="#system-message-3 "> < span class ="problematic " id ="problematic-3 "> `</ span > </ a > vmalloc`分配的内存是按页对齐的。</ p >
408
+ < p class ="last "> 一个页面的大小为 < em > PAGE_SIZE</ em > 。将分配的区域存储在 < em > vmalloc_area</ em > 中。由 < code class ="xref c c-func docutils literal "> < span class ="pre "> vmalloc()</ span > </ code > 分配的内存是按页对齐的。</ p >
411
409
</ div >
412
- < p > 使用:c:func: < a href =" #system-message-4 "> < span class ="problematic " id =" problematic-4 " > ` </ span > </ a > SetPageReserved`将每个页面的PG_reserved位设置为启用状态 。在释放内存之前,使用:c:func: < a href =" #system-message-5 "> < span class ="problematic " id =" problematic-5 " > ` </ span > </ a > ClearPageReserved` 清除该位。</ p >
410
+ < p > 使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > SetPageReserved() </ span > </ code > 将每个页面的 PG_reserved 位设置为启用状态 。在释放内存之前,使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > ClearPageReserved() </ span > </ code > 清除该位。</ p >
413
411
< div class ="admonition hint ">
414
412
< p class ="first admonition-title "> Hint</ p >
415
- < p class ="last "> 使用:c:func: < a href =" #system-message-6 "> < span class ="problematic " id =" problematic-6 " > ` </ span > </ a > vmalloc_to_page` 将虚拟页转换为物理页,用于:c:func: < a href =" #system-message-7 "> < span class ="problematic " id =" problematic-7 " > ` </ span > </ a > SetPageReserved`和:c:func: < a href =" #system-message-8 "> < span class ="problematic " id =" problematic-8 " > ` </ span > </ a > ClearPageReserved`函数 。</ p >
413
+ < p class ="last "> 使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > vmalloc_to_page() </ span > </ code > 将虚拟页转换为物理页,以供 < code class =" xref c c-func docutils literal "> < span class ="pre " > SetPageReserved() </ span > </ code > 和 < code class =" xref c c-func docutils literal "> < span class ="pre " > ClearPageReserved() </ span > </ code > 函数使用 。</ p >
416
414
</ div >
417
- < p > 为了验证目的(使用下面的测试),在每个页面的前4个字节中填入以下值 :0xaa、0xbb、0xcc、 0xdd。</ p >
418
- < p > 实现:mmap驱动程序函数 。</ p >
415
+ < p > 为了验证目的(使用下面的测试),在每个页面的前 4 个字节中填入以下值 :0xaa、0xbb、0xcc 以及 0xdd。</ p >
416
+ < p > 实现 mmap 驱动程序函数 。</ p >
419
417
< div class ="admonition hint ">
420
418
< p class ="first admonition-title "> Hint</ p >
421
- < p class ="last "> 要将虚拟vmalloc地址转换为物理地址 ,使用:c:func: < a href =" #system-message-9 "> < span class ="problematic " id =" problematic-9 " > ` </ span > </ a > vmalloc_to_pfn`直接返回PFN 。</ p >
419
+ < p class ="last "> 要将虚拟 vmalloc 地址转换为物理地址 ,使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > vmalloc_to_pfn() </ span > </ code > 直接返回 PFN 。</ p >
422
420
</ div >
423
421
< div class ="admonition attention ">
424
422
< p class ="first admonition-title "> Attention</ p >
425
- < p > vmalloc页面不是物理连续的,因此需要为每个页面使用:c: func: < cite > remap_pfn_range</ cite > 。</ p >
423
+ < p > vmalloc 页面不是物理连续的,因此需要为每个页面单独使用 < code class =" xref c c- func docutils literal " > < span class =" pre " > remap_pfn_range() </ span > </ code > 。</ p >
426
424
< p > 遍历所有虚拟页面,并对于每个页面:
427
425
* 确定物理地址
428
- * 使用:c:func: < a href =" #system-message-10 "> < span class ="problematic " id =" problematic-10 " > ` </ span > </ a > remap_pfn_range` 进行映射</ p >
429
- < p class ="last "> 确保每次都确定物理地址,并且使用一个页面范围进行映射 。</ p >
426
+ * 使用 < code class =" xref c c-func docutils literal "> < span class ="pre " > remap_pfn_range() </ span > </ code > 进行映射</ p >
427
+ < p class ="last "> 确保每次都确定物理地址,并且使用同一个页面范围进行映射 。</ p >
430
428
</ div >
431
- < p > 用于测试的方法是 ,加载内核模块并运行:</ p >
429
+ < p > 测试的方法是 ,加载内核模块并运行:</ p >
432
430
< div class ="highlight-shell "> < div class ="highlight "> < pre > < span > </ span > root@qemux86:~# skels/memory_mapping/test/mmap-test < span class ="m "> 1</ span >
433
431
</ pre > </ div >
434
432
</ div >
0 commit comments