90 lines
2.2 KiB
C
90 lines
2.2 KiB
C
/*
|
|
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
|
|
* RWTH Aachen University
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* This file is part of MetalSVM.
|
|
*/
|
|
|
|
/**
|
|
* @author Stefan Lankes
|
|
* @file include/metalsvm/mmu.h
|
|
* @brief Memory management related
|
|
*
|
|
* This file contains memory management related
|
|
* functions for use in kernel space
|
|
*/
|
|
|
|
#ifndef __MMU_H__
|
|
#define __MMU_H__
|
|
|
|
#include <metalsvm/stddef.h>
|
|
#include <asm/atomic.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern atomic_int32_t total_pages;
|
|
extern atomic_int32_t total_allocated_pages;
|
|
extern atomic_int32_t total_available_pages;
|
|
|
|
/** @brief Initialize MMU subsystem
|
|
*
|
|
* This function finds out which pageframes are
|
|
* used by the kernel already before the paging
|
|
* was initialized, marks it as used and starts
|
|
* the paging subsystem.
|
|
*/
|
|
int mmu_init(void);
|
|
|
|
/** @brief Get continuous pages
|
|
*
|
|
* Use first fit algorithm to find a suitable, continous physical memory region
|
|
*
|
|
* @param npages Desired number of pages
|
|
* @return
|
|
* - physical address on success
|
|
* - 0 on failure
|
|
*/
|
|
size_t get_pages(uint32_t npages);
|
|
|
|
/** @brief Get a single page
|
|
*
|
|
* Convenience function: uses get_pages(1);
|
|
*/
|
|
static inline size_t get_page(void) { return get_pages(1); }
|
|
|
|
/** @brief Put back a sequence of continous pages
|
|
*
|
|
* @param phyaddr Physical address of the first page
|
|
* @param npages Number of pages
|
|
*
|
|
* @return
|
|
* - 0 on success
|
|
* - -EINVAL (-22) on failure
|
|
*/
|
|
int put_pages(size_t phyaddr, size_t npages);
|
|
|
|
/** @brief Put a single page
|
|
*
|
|
* Convenience function: uses put_pages(1);
|
|
*/
|
|
static inline int put_page(size_t phyaddr) { return put_pages(phyaddr, 1); }
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|