source: mainline/kernel/arch/ia32/src/mm/frame.c@ ca62f86

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ca62f86 was aaceebc4, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

Create DMA zone.

use dma zone for dma_map_anonymous calls.
create non-available zone if all pages in that zone are used.
make occupying pages in non-available zones a no-op

This enables ISA DMA on configurations with more than 16 MB of ram

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
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 ia32mm
30 * @{
31 */
32/** @file
33 * @ingroup ia32mm, amd64mm
34 */
35
36#include <mm/frame.h>
37#include <arch/mm/frame.h>
38#include <mm/as.h>
39#include <config.h>
40#include <arch/boot/boot.h>
41#include <arch/boot/memmap.h>
42#include <panic.h>
43#include <debug.h>
44#include <align.h>
45#include <macros.h>
46#include <print.h>
47
48#define PHYSMEM_LIMIT32 UINT64_C(0x100000000)
49#define PHYSMEM_LIMIT_DMA UINT64_C(0x1000000)
50
51size_t hardcoded_unmapped_ktext_size = 0;
52size_t hardcoded_unmapped_kdata_size = 0;
53
54static void init_e820_memory(pfn_t minconf, bool low)
55{
56 unsigned int i;
57
58 for (i = 0; i < e820counter; i++) {
59 uint64_t base64 = e820table[i].base_address;
60 uint64_t size64 = e820table[i].size;
61
62#ifdef KARCH_ia32
63 /*
64 * Restrict the e820 table entries to 32-bits.
65 */
66 if (base64 >= PHYSMEM_LIMIT32)
67 continue;
68
69 if (base64 + size64 > PHYSMEM_LIMIT32)
70 size64 = PHYSMEM_LIMIT32 - base64;
71#endif
72
73 uintptr_t base = (uintptr_t) base64;
74 size_t size = (size_t) size64;
75
76 if (!frame_adjust_zone_bounds(low, &base, &size))
77 continue;
78
79 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
80 /* To be safe, make the available zone possibly smaller */
81 uint64_t new_base = ALIGN_UP(base, FRAME_SIZE);
82 uint64_t new_size = ALIGN_DOWN(size - (new_base - base),
83 FRAME_SIZE);
84
85 size_t count = SIZE2FRAMES(new_size);
86 pfn_t pfn = ADDR2PFN(new_base);
87 pfn_t conf;
88
89 if (low) {
90 if ((minconf < pfn) || (minconf >= pfn + count))
91 conf = pfn;
92 else
93 conf = minconf;
94
95 if ((pfn * PAGE_SIZE) < PHYSMEM_LIMIT_DMA) {
96 size_t dma_count = min(
97 PHYSMEM_LIMIT_DMA / PAGE_SIZE - pfn,
98 count);
99 zone_create(pfn, dma_count, conf,
100 ZONE_AVAILABLE | ZONE_DMA);
101 count -= dma_count;
102 pfn += dma_count;
103 }
104
105 conf = pfn;
106 if (count) {
107 zone_create(pfn, count, conf,
108 ZONE_AVAILABLE | ZONE_LOWMEM);
109 }
110 } else {
111 conf = zone_external_conf_alloc(count);
112 if (conf != 0) {
113 zone_create(pfn, count, conf,
114 ZONE_AVAILABLE | ZONE_HIGHMEM);
115 }
116 }
117 } else if ((e820table[i].type == MEMMAP_MEMORY_ACPI) ||
118 (e820table[i].type == MEMMAP_MEMORY_NVS)) {
119 /* To be safe, make the firmware zone possibly larger */
120 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
121 uint64_t new_size = ALIGN_UP(size + (base - new_base),
122 FRAME_SIZE);
123
124 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
125 ZONE_FIRMWARE);
126 } else {
127 /* To be safe, make the reserved zone possibly larger */
128 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
129 uint64_t new_size = ALIGN_UP(size + (base - new_base),
130 FRAME_SIZE);
131
132 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
133 ZONE_RESERVED);
134 }
135 }
136}
137
138static const char *e820names[] = {
139 "invalid",
140 "available",
141 "reserved",
142 "acpi",
143 "nvs",
144 "unusable"
145};
146
147void physmem_print(void)
148{
149 unsigned int i;
150 printf("[base ] [size ] [name ]\n");
151
152 for (i = 0; i < e820counter; i++) {
153 const char *name;
154
155 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
156 name = e820names[e820table[i].type];
157 else
158 name = "invalid";
159
160 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
161 e820table[i].size, name);
162 }
163}
164
165
166void frame_low_arch_init(void)
167{
168 pfn_t minconf;
169
170 if (config.cpu_active == 1) {
171 minconf = 1;
172
173#ifdef CONFIG_SMP
174 minconf = max(minconf,
175 ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
176 hardcoded_unmapped_kdata_size));
177#endif
178
179 init_e820_memory(minconf, true);
180
181 /* Reserve frame 0 (BIOS data) */
182 frame_mark_unavailable(0, 1);
183
184#ifdef CONFIG_SMP
185 /* Reserve AP real mode bootstrap memory */
186 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
187 (hardcoded_unmapped_ktext_size +
188 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
189#endif
190 }
191}
192
193void frame_high_arch_init(void)
194{
195 if (config.cpu_active == 1)
196 init_e820_memory(0, false);
197}
198
199/** @}
200 */
Note: See TracBrowser for help on using the repository browser.