source: mainline/kernel/generic/src/mm/page.c@ e5dbbe5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e5dbbe5 was 7cb567cd, checked in by Martin Decky <martin@…>, 18 years ago

map kernel pages explicitly as writable (this solves compatibility issues with Intel Core 2)
make VESA framebuffer initialization more robust

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[f761f1eb]1/*
[df4ed85]2 * Copyright (c) 2001-2006 Jakub Jermar
[f761f1eb]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
[cc73a8a1]29/** @addtogroup genericmm
[b45c443]30 * @{
31 */
32
[9179d0a]33/**
[b45c443]34 * @file
[9179d0a]35 * @brief Virtual Address Translation subsystem.
36 *
37 * This file contains code for creating, destroying and searching
38 * mappings between virtual addresses and physical addresses.
39 * Functions here are mere wrappers that call the real implementation.
40 * They however, define the single interface.
[20d50a1]41 */
42
[f761f1eb]43#include <mm/page.h>
44#include <arch/mm/page.h>
[677a6d5]45#include <arch/mm/asid.h>
[fc1e4f6]46#include <mm/as.h>
[677a6d5]47#include <mm/frame.h>
[74df77d]48#include <arch/types.h>
[ff9f858]49#include <arch/asm.h>
[9c0a9b3]50#include <memstr.h>
[6d7ffa65]51#include <debug.h>
[677a6d5]52#include <arch.h>
[6d7ffa65]53
54/** Virtual operations for page subsystem. */
[f5935ed]55page_mapping_operations_t *page_mapping_operations = NULL;
[9c0a9b3]56
[f761f1eb]57void page_init(void)
[db3341e]58{
[f761f1eb]59 page_arch_init();
60}
[74df77d]61
62/** Map memory structure
63 *
64 * Identity-map memory structure
65 * considering possible crossings
66 * of page boundaries.
67 *
68 * @param s Address of the structure.
69 * @param size Size of the structure.
70 */
[7f1c620]71void map_structure(uintptr_t s, size_t size)
[74df77d]72{
73 int i, cnt, length;
74
[cf85e24c]75 length = size + (s - (s & ~(PAGE_SIZE - 1)));
76 cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
[74df77d]77
[76cec1e]78 for (i = 0; i < cnt; i++)
[7cb567cd]79 page_mapping_insert(AS_KERNEL, s + i * PAGE_SIZE, s + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
[74df77d]80
81}
[ff9f858]82
[8f00329]83/** Insert mapping of page to frame.
[ff9f858]84 *
[9179d0a]85 * Map virtual address page to physical address frame
86 * using flags. Allocate and setup any missing page tables.
[ff9f858]87 *
[2299914]88 * The page table must be locked and interrupts must be disabled.
[ef67bab]89 *
[8f00329]90 * @param as Address space to wich page belongs.
[ff9f858]91 * @param page Virtual address of the page to be mapped.
92 * @param frame Physical address of memory frame to which the mapping is done.
93 * @param flags Flags to be used for mapping.
94 */
[7f1c620]95void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
[ff9f858]96{
[f5935ed]97 ASSERT(page_mapping_operations);
98 ASSERT(page_mapping_operations->mapping_insert);
[6d7ffa65]99
[f5935ed]100 page_mapping_operations->mapping_insert(as, page, frame, flags);
[ff9f858]101}
[1084a784]102
[8f00329]103/** Remove mapping of page.
104 *
[9179d0a]105 * Remove any mapping of page within address space as.
[8f00329]106 * TLB shootdown should follow in order to make effects of
107 * this call visible.
108 *
[2299914]109 * The page table must be locked and interrupts must be disabled.
[8f00329]110 *
111 * @param as Address space to wich page belongs.
112 * @param page Virtual address of the page to be demapped.
113 */
[7f1c620]114void page_mapping_remove(as_t *as, uintptr_t page)
[8f00329]115{
116 ASSERT(page_mapping_operations);
117 ASSERT(page_mapping_operations->mapping_remove);
118
119 page_mapping_operations->mapping_remove(as, page);
120}
121
[1084a784]122/** Find mapping for virtual page
123 *
124 * Find mapping for virtual page.
125 *
[2299914]126 * The page table must be locked and interrupts must be disabled.
[ef67bab]127 *
128 * @param as Address space to wich page belongs.
[1084a784]129 * @param page Virtual page.
130 *
[0c0410b]131 * @return NULL if there is no such mapping; requested mapping otherwise.
[1084a784]132 */
[7f1c620]133pte_t *page_mapping_find(as_t *as, uintptr_t page)
[1084a784]134{
[f5935ed]135 ASSERT(page_mapping_operations);
136 ASSERT(page_mapping_operations->mapping_find);
[1084a784]137
[f5935ed]138 return page_mapping_operations->mapping_find(as, page);
[1084a784]139}
[b45c443]140
[cc73a8a1]141/** @}
[b45c443]142 */
Note: See TracBrowser for help on using the repository browser.