[d630139] | 1 | /*
|
---|
[999efa9] | 2 | * Copyright (c) 2007 Pavel Jancik
|
---|
| 3 | * Copyright (c) 2007 Michal Kebrt
|
---|
[d630139] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[e49e234] | 30 | /** @addtogroup arm32mm
|
---|
[d630139] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
[6b781c0] | 34 | * @brief Frame related functions.
|
---|
[d630139] | 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <mm/frame.h>
|
---|
[6b781c0] | 38 | #include <arch/mm/frame.h>
|
---|
[5ac77cc] | 39 | #include <arch/machine_func.h>
|
---|
[6b781c0] | 40 | #include <config.h>
|
---|
[d7ef14b] | 41 | #include <align.h>
|
---|
[ddcc8a0] | 42 | #include <macros.h>
|
---|
[d630139] | 43 |
|
---|
[2686705] | 44 | static void frame_common_arch_init(bool low)
|
---|
| 45 | {
|
---|
| 46 | uintptr_t base;
|
---|
| 47 | size_t size;
|
---|
| 48 |
|
---|
| 49 | machine_get_memory_extents(&base, &size);
|
---|
| 50 | base = ALIGN_UP(base, FRAME_SIZE);
|
---|
| 51 | size = ALIGN_DOWN(size, FRAME_SIZE);
|
---|
| 52 |
|
---|
| 53 | if (!frame_adjust_zone_bounds(low, &base, &size))
|
---|
| 54 | return;
|
---|
| 55 |
|
---|
| 56 | if (low) {
|
---|
| 57 | zone_create(ADDR2PFN(base), SIZE2FRAMES(size),
|
---|
| 58 | BOOT_PAGE_TABLE_START_FRAME +
|
---|
| 59 | BOOT_PAGE_TABLE_SIZE_IN_FRAMES,
|
---|
| 60 | ZONE_AVAILABLE | ZONE_LOWMEM);
|
---|
| 61 | } else {
|
---|
| 62 | pfn_t conf = zone_external_conf_alloc(SIZE2FRAMES(size));
|
---|
[7852625] | 63 | if (conf != 0)
|
---|
| 64 | zone_create(ADDR2PFN(base), SIZE2FRAMES(size), conf,
|
---|
| 65 | ZONE_AVAILABLE | ZONE_HIGHMEM);
|
---|
[2686705] | 66 | }
|
---|
| 67 |
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[c6f1908e] | 70 | /** Create low memory zones. */
|
---|
[ddcc8a0] | 71 | void frame_low_arch_init(void)
|
---|
[d630139] | 72 | {
|
---|
[2686705] | 73 | frame_common_arch_init(true);
|
---|
[c6f1908e] | 74 |
|
---|
[6b781c0] | 75 | /* blacklist boot page table */
|
---|
| 76 | frame_mark_unavailable(BOOT_PAGE_TABLE_START_FRAME,
|
---|
| 77 | BOOT_PAGE_TABLE_SIZE_IN_FRAMES);
|
---|
[6ac14a70] | 78 |
|
---|
| 79 | machine_frame_init();
|
---|
[6b781c0] | 80 | }
|
---|
| 81 |
|
---|
[c6f1908e] | 82 | /** Create high memory zones. */
|
---|
[ddcc8a0] | 83 | void frame_high_arch_init(void)
|
---|
| 84 | {
|
---|
[2686705] | 85 | frame_common_arch_init(false);
|
---|
[ddcc8a0] | 86 | }
|
---|
| 87 |
|
---|
[6b781c0] | 88 | /** Frees the boot page table. */
|
---|
| 89 | void boot_page_table_free(void)
|
---|
| 90 | {
|
---|
[43dd8028] | 91 | frame_free(BOOT_PAGE_TABLE_ADDRESS,
|
---|
| 92 | BOOT_PAGE_TABLE_SIZE_IN_FRAMES);
|
---|
[d630139] | 93 | }
|
---|
| 94 |
|
---|
| 95 | /** @}
|
---|
| 96 | */
|
---|