summaryrefslogtreecommitdiff
path: root/sos-code-article6.75/sos/kmem_vmm.h
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-03-28 17:16:09 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-03-28 17:16:09 +0100
commitacb5161d7384e6b6352c0a9f3cc067621fbf28ad (patch)
tree6b66a66927e98b84d53f97da411b58c1b7ad3c53 /sos-code-article6.75/sos/kmem_vmm.h
parenta8968330aff45e0b8cf278f49fa337d5fcb9bfd8 (diff)
downloadSOS-acb5161d7384e6b6352c0a9f3cc067621fbf28ad.tar.gz
SOS-acb5161d7384e6b6352c0a9f3cc067621fbf28ad.zip
Import and compile article 6.75HEADmaster
Diffstat (limited to 'sos-code-article6.75/sos/kmem_vmm.h')
-rw-r--r--sos-code-article6.75/sos/kmem_vmm.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/sos-code-article6.75/sos/kmem_vmm.h b/sos-code-article6.75/sos/kmem_vmm.h
new file mode 100644
index 0000000..49b262d
--- /dev/null
+++ b/sos-code-article6.75/sos/kmem_vmm.h
@@ -0,0 +1,113 @@
+/* Copyright (C) 2000 Thomas Petazzoni
+ Copyright (C) 2004 David Decotigny
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA.
+*/
+#ifndef _SOS_KMEM_VMM_H_
+#define _SOS_KMEM_VMM_H_
+
+/**
+ * @file kmem_vmm.h
+ *
+ * Kernel Memory Allocator for multiple-page-sized objects residing in
+ * the kernel (virtual memory) space. Relies on the slab cache
+ * allocator to allocate its (internal) "range" data structure.
+ */
+
+#include <hwcore/paging.h>
+
+/* The base and top virtual addresses covered by the kernel allocator */
+#define SOS_KMEM_VMM_BASE 0x4000 /* 16kB */
+#define SOS_KMEM_VMM_TOP SOS_PAGING_MIRROR_VADDR /* 1GB - 4MB */
+
+/** Opaque structure used internally and declared here for physmem.h */
+struct sos_kmem_range;
+
+#include <sos/kmem_slab.h>
+
+/**
+ * Mark the areas belonging to SOS_KMEM_VMM_BASE and SOS_KMEM_VMM_TOP
+ * are either used or free. Those that are already mapped are marked
+ * as "used", and the 0..SOS_KMEM_VMM_BASE virtual addresses as marked
+ * as "used" too (to detect incorrect pointer dereferences).
+ */
+sos_ret_t
+sos_kmem_vmm_subsystem_setup(sos_vaddr_t kernel_core_base_vaddr,
+ sos_vaddr_t kernel_core_top_vaddr,
+ sos_vaddr_t bootstrap_stack_bottom_vaddr,
+ sos_vaddr_t bootstrap_stack_top_vaddr);
+
+
+/*
+ * Flags for kmem_vmm_new_range and kmem_vmm_alloc
+ */
+/** Physical pages should be immediately mapped */
+#define SOS_KMEM_VMM_MAP (1<<0)
+/** Allocation should either success or fail, without blocking */
+#define SOS_KMEM_VMM_ATOMIC (1<<1)
+
+/**
+ * Allocate a new kernel area spanning one or multiple pages.
+ *
+ * @param range_base_vaddr If not NULL, the start address of the range
+ * is stored in this location
+ * @eturn a new range structure
+ */
+struct sos_kmem_range *sos_kmem_vmm_new_range(sos_size_t nb_pages,
+ sos_ui32_t flags,
+ sos_vaddr_t *range_base_vaddr);
+sos_ret_t sos_kmem_vmm_del_range(struct sos_kmem_range *range);
+
+
+/**
+ * Straighforward variant of sos_kmem_vmm_new_range() returning the
+ * range's start address instead of the range structure
+ */
+sos_vaddr_t sos_kmem_vmm_alloc(sos_size_t nb_pages,
+ sos_ui32_t flags);
+
+/**
+ * @note you are perfectly allowed to give the address of the
+ * kernel image, or the address of the bios area here, it will work:
+ * the kernel/bios WILL be "deallocated". But if you really want to do
+ * this, well..., do expect some "surprises" ;)
+ */
+sos_ret_t sos_kmem_vmm_free(sos_vaddr_t vaddr);
+
+
+/**
+ * @return TRUE when vaddr is covered by any (used) kernel range
+ */
+sos_bool_t sos_kmem_vmm_is_valid_vaddr(sos_vaddr_t vaddr);
+
+
+/* *****************************
+ * Reserved to kmem_slab.c ONLY.
+ */
+/**
+ * Associate the range with the given slab.
+ */
+sos_ret_t sos_kmem_vmm_set_slab(struct sos_kmem_range *range,
+ struct sos_kslab *slab);
+
+/**
+ * Retrieve the (used) slab associated with the range covering vaddr.
+ *
+ * @return NULL if the range is not associated with a KMEM range
+ */
+struct sos_kslab *sos_kmem_vmm_resolve_slab(sos_vaddr_t vaddr);
+
+#endif /* _SOS_KMEM_VMM_H_ */