source: mainline/kernel/arch/riscv64/src/mm/frame.c

Last change on this file was bab75df6, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Let kernel code get printf via the standard stdio header. Clean up unused includes.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2016 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_riscv64_mm
30 * @{
31 */
32
33#include <mm/frame.h>
34#include <arch/boot/boot.h>
35#include <arch/mm/frame.h>
36#include <arch/drivers/ucb.h>
37#include <mm/as.h>
38#include <config.h>
39#include <panic.h>
40#include <debug.h>
41#include <align.h>
42#include <macros.h>
43
44uintptr_t physmem_start;
45uintptr_t htif_frame;
46uintptr_t pt_frame;
47memmap_t memmap;
48
49void physmem_print(void)
50{
51}
52
53static void frame_common_arch_init(bool low)
54{
55 pfn_t minconf =
56 max3(ADDR2PFN(physmem_start), htif_frame + 1, pt_frame + 1);
57
58 for (size_t i = 0; i < memmap.cnt; i++) {
59 /* To be safe, make the available zone possibly smaller */
60 uintptr_t base = ALIGN_UP((uintptr_t) memmap.zones[i].start,
61 FRAME_SIZE);
62 size_t size = ALIGN_DOWN(memmap.zones[i].size -
63 (base - ((uintptr_t) memmap.zones[i].start)), FRAME_SIZE);
64
65 if (!frame_adjust_zone_bounds(low, &base, &size))
66 return;
67
68 pfn_t pfn = ADDR2PFN(base);
69 size_t count = SIZE2FRAMES(size);
70 pfn_t conf;
71
72 if (low) {
73 if ((minconf < pfn) || (minconf >= pfn + count))
74 conf = pfn;
75 else
76 conf = minconf;
77
78 zone_create(pfn, count, conf,
79 ZONE_AVAILABLE | ZONE_LOWMEM);
80 } else {
81 conf = zone_external_conf_alloc(count);
82 if (conf != 0)
83 zone_create(pfn, count, conf,
84 ZONE_AVAILABLE | ZONE_HIGHMEM);
85 }
86 }
87}
88
89void frame_low_arch_init(void)
90{
91 frame_common_arch_init(true);
92
93 frame_mark_unavailable(htif_frame, 1);
94 frame_mark_unavailable(pt_frame, 1);
95}
96
97void frame_high_arch_init(void)
98{
99 frame_common_arch_init(false);
100}
101
102/** @}
103 */
Note: See TracBrowser for help on using the repository browser.