First commit, Vystem v0.1
This commit is contained in:
71
shelter/lib/include/memory/pez/pez.h
Normal file
71
shelter/lib/include/memory/pez/pez.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
#ifndef SH_LIB_PEZ_H
|
||||
#define SH_LIB_PEZ_H
|
||||
#include "std/type.h"
|
||||
#include "std/status.h"
|
||||
#include "memory/slabs/slab_reg_phys.h"
|
||||
#include "memory/slabs/slab_reg_virt.h"
|
||||
#include "memory/pez/radix.h"
|
||||
#define SH_PEZ_REGION_OBJECT_INDEX_SIZE_BYTES 3
|
||||
// Physical region object
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 start_page_index;
|
||||
sh_uint32 region_size_pages;
|
||||
sh_uint8 next_region_index[3];
|
||||
sh_uint8 flags;
|
||||
} sh_pez_REGION_PHYSICAL_OBJECT;
|
||||
#pragma pack()
|
||||
// Virtual region object
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 start_page_index;
|
||||
sh_uint32 region_size_pages;
|
||||
sh_uint32 next_region_index;
|
||||
} sh_pez_REGION_VIRTUAL_OBJECT;
|
||||
#pragma pack()
|
||||
// Physical plane structure
|
||||
typedef struct {
|
||||
sh_uint32 free_pages;
|
||||
sh_uint32 used_pages;
|
||||
sh_radix_TREE region_radix_tree;
|
||||
sh_radix_TREE boundary_radix_tree;
|
||||
sh_slab_reg_phys_SLAB_ALLOCATOR *slab_reg_phys;
|
||||
struct sh_slab_radix_node_SLAB_ALLOCATOR *slab_radix_node;
|
||||
sh_page_PAGE_TABLE_POOL *kernel_ptp;
|
||||
sh_uint8 *physical_bitmap;
|
||||
sh_uint64 physical_page_count;
|
||||
} sh_pez_PHYSICAL_PLANE;
|
||||
// Virtual plane structure
|
||||
typedef struct {
|
||||
sh_uint32 free_pages;
|
||||
sh_uint32 used_pages;
|
||||
sh_radix_TREE region_radix_tree;
|
||||
sh_radix_TREE boundary_radix_tree;
|
||||
sh_slab_reg_virt_SLAB_ALLOCATOR *slab_reg_virt;
|
||||
struct sh_slab_radix_node_SLAB_ALLOCATOR *slab_radix_node;
|
||||
sh_page_PAGE_TABLE_POOL *kernel_ptp;
|
||||
sh_page_PAGE_TABLE_POOL *reference_ptp;
|
||||
sh_page_VIRTUAL_ADDRESS plane_offset;
|
||||
} sh_pez_VIRTUAL_PLANE;
|
||||
// Set Pez state to true
|
||||
void sh_pez_set_available();
|
||||
// Return current state of Pez
|
||||
sh_bool sh_pez_is_available();
|
||||
// Return reference Pez physical plane
|
||||
sh_pez_PHYSICAL_PLANE* sh_pez_get_reference_phys_plane();
|
||||
// Initialize a physical plane
|
||||
SH_STATUS sh_pez_init_physical_plane(sh_uint8 *physical_bitmap,sh_uint64 physical_page_count,sh_slab_reg_phys_SLAB_ALLOCATOR *slab_reg_phys,struct sh_slab_radix_node_SLAB_ALLOCATOR *slab_radix_node,sh_page_PAGE_TABLE_POOL *kernel_ptp,sh_pez_PHYSICAL_PLANE *phys_plane);
|
||||
// Allocate physical pages from the physical plane
|
||||
SH_STATUS sh_pez_alloc_physical_pages(sh_pez_PHYSICAL_PLANE *phys_plane,sh_uint32 pages_count,sh_page_PHYSICAL_ADDRESS *address);
|
||||
// Free physical pages from the physical plane
|
||||
SH_STATUS sh_pez_free_physical_pages(sh_pez_PHYSICAL_PLANE *phys_plane,sh_page_PHYSICAL_ADDRESS *address,sh_uint32 pages_count);
|
||||
// Debug Pez Physical
|
||||
SH_STATUS sh_pez_debug_physical(sh_pez_PHYSICAL_PLANE *phys_plane);
|
||||
// Initialize a virtual plane
|
||||
SH_STATUS sh_pez_init_virtual_plane(sh_page_VIRTUAL_ADDRESS plane_offset,sh_slab_reg_virt_SLAB_ALLOCATOR *slab_reg_virt,struct sh_slab_radix_node_SLAB_ALLOCATOR *slab_radix_node,sh_page_PAGE_TABLE_POOL *kernel_ptp,sh_page_PAGE_TABLE_POOL *reference_ptp,sh_pez_VIRTUAL_PLANE *virt_plane);
|
||||
// Allocate virtual space from the virtual plane
|
||||
SH_STATUS sh_pez_alloc_virtual_pages(sh_pez_VIRTUAL_PLANE *virt_plane,sh_uint32 pages_count,sh_page_VIRTUAL_ADDRESS *address);
|
||||
// Free virtual space from the virtual plane
|
||||
SH_STATUS sh_pez_free_virtual_pages(sh_pez_VIRTUAL_PLANE *virt_plane,sh_page_VIRTUAL_ADDRESS *address,sh_uint32 pages_count);
|
||||
#endif
|
||||
103
shelter/lib/include/memory/pez/pez_debug.h
Normal file
103
shelter/lib/include/memory/pez/pez_debug.h
Normal file
@@ -0,0 +1,103 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
#ifndef SH_LIB_PEZ_DEBUG_H
|
||||
#define SH_LIB_PEZ_DEBUG_H
|
||||
#include "std/type.h"
|
||||
#include "std/status.h"
|
||||
#define SH_PEZ_DEBUG_ALLOC_HEADER 0
|
||||
#define SH_PEZ_DEBUG_FREE_HEADER 1
|
||||
#define SH_PEZ_DEBUG_SIZE_LIST_HEADER 2
|
||||
#define SH_PEZ_DEBUG_BOUNDARY_RADIX_HEADER 3
|
||||
#define SH_PEZ_DEBUG_BITMAP_REGIONS_HEADER 4
|
||||
#define SH_PEZ_DEBUG_SIZE_LIST_BLOCK_HEADER 5
|
||||
// Struct for Pez alloc
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 size_asked;
|
||||
sh_uint32 found_region_start_index;
|
||||
sh_uint32 found_region_size;
|
||||
sh_bool is_exact_fit;
|
||||
sh_uint32 remaining_size;
|
||||
sh_uint32 new_start;
|
||||
sh_uint32 reg_idx;
|
||||
} sh_pez_debug_ALLOC;
|
||||
#pragma pack()
|
||||
// Struct for Pez free
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 region_start_freeed;
|
||||
sh_uint32 size_freeed;
|
||||
sh_uint32 left_region_idx;
|
||||
sh_uint32 right_region_idx;
|
||||
sh_uint32 left_region_size;
|
||||
sh_uint32 right_region_size;
|
||||
sh_uint32 left_region_start;
|
||||
sh_uint32 right_region_start;
|
||||
sh_uint32 final_inserted_region_idx;
|
||||
sh_uint32 final_inserted_region_start;
|
||||
sh_uint32 final_inserted_region_size;
|
||||
sh_bool was_right_region_object_freeed;
|
||||
sh_bool was_new_region_object_allocated;
|
||||
sh_uint32 new_reg_obj_start;
|
||||
sh_uint32 new_reg_obj_size;
|
||||
} sh_pez_debug_FREE;
|
||||
#pragma pack()
|
||||
// Struct for Pez regions from size list
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 start;
|
||||
sh_uint32 size;
|
||||
sh_uint32 idx;
|
||||
sh_uint32 next_idx;
|
||||
} sh_pez_debug_REGION_SIZE_LIST;
|
||||
#pragma pack()
|
||||
// Struct for Pez size list
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 size;
|
||||
sh_uint32 count;
|
||||
sh_pez_debug_REGION_SIZE_LIST regions[512];
|
||||
} sh_pez_debug_SIZE_LIST;
|
||||
#pragma pack()
|
||||
// Struct for Pez region from boundary
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 pos_start;
|
||||
sh_uint32 idx_start;
|
||||
sh_uint32 prev_start;
|
||||
sh_uint32 pos_end;
|
||||
sh_uint32 idx_end;
|
||||
sh_uint32 prev_end;
|
||||
} sh_pez_debug_REGION_BOUNDARY;
|
||||
#pragma pack()
|
||||
// Struct for Pez boundary radix
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 count;
|
||||
sh_pez_debug_REGION_BOUNDARY regions[512];
|
||||
} sh_pez_debug_BOUNDARY_RADIX;
|
||||
#pragma pack()
|
||||
// Struct for Pez regions from bitmap
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 start;
|
||||
sh_uint32 size;
|
||||
} sh_pez_debug_REGION_BITMAP;
|
||||
#pragma pack()
|
||||
// Struct for Pez bitmap
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
sh_uint32 count;
|
||||
sh_pez_debug_REGION_BITMAP regions[512];
|
||||
} sh_pez_debug_BITMAP;
|
||||
#pragma pack()
|
||||
#endif
|
||||
// Send an alloc payload
|
||||
SH_STATUS sh_pez_debug_send_alloc(sh_pez_debug_ALLOC *alloc);
|
||||
// Send a free payload
|
||||
SH_STATUS sh_pez_debug_send_free(sh_pez_debug_FREE *free);
|
||||
// Send a size list payload. Sending size list radix header must be done prior to any size list being send. It consist of SH_PEZ_DEBUG_SIZE_LIST_BLOCK_HEADER and the count of sizes list
|
||||
SH_STATUS sh_pez_debug_send_size_list(sh_pez_debug_SIZE_LIST *size_list);
|
||||
// Send a boundary radix payload
|
||||
SH_STATUS sh_pez_debug_send_boundary_radix(sh_pez_debug_BOUNDARY_RADIX *boundary_radix);
|
||||
// Send a bitmap payload
|
||||
SH_STATUS sh_pez_debug_send_bitmap(sh_pez_debug_BITMAP *bitmap);
|
||||
31
shelter/lib/include/memory/pez/radix.h
Normal file
31
shelter/lib/include/memory/pez/radix.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
#ifndef SH_LIB_RADIX_H
|
||||
#define SH_LIB_RADIX_H
|
||||
#include "std/type.h"
|
||||
#include "memory/page.h"
|
||||
struct sh_slab_radix_node_SLAB_ALLOCATOR;
|
||||
#define SH_RADIX_NODE_SIZE_BYTES 128
|
||||
// Radix node structure
|
||||
typedef struct {
|
||||
sh_page_VIRTUAL_ADDRESS ptr[16];
|
||||
} sh_radix_NODE;
|
||||
// Radix tree structure
|
||||
typedef struct {
|
||||
sh_radix_NODE *root_node;
|
||||
sh_uint8 depth;
|
||||
} sh_radix_TREE;
|
||||
// Return the value at the indicated index. Return SH_STATUS_NOT_FOUND if index indicate an empty ptr. Automatically fill the 16 higher bits in the returned value if index=0, no matter that provided node is a intermediary node or a leaf
|
||||
SH_STATUS sh_radix_node_read_value(sh_radix_NODE *node,sh_uint8 index,sh_page_VIRTUAL_ADDRESS* value);
|
||||
// Modify the value at the indicated index. Update the bitmap accordingly, all non-zero value corresponding to 1 in the bitmap, otherwise 0.
|
||||
SH_STATUS sh_radix_node_set_value(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_radix_NODE *node,sh_uint8 index,sh_page_VIRTUAL_ADDRESS value);
|
||||
// Initialize a radix tree. Fail if depth is greater than 16
|
||||
SH_STATUS sh_radix_tree_init(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp,sh_radix_TREE *tree,sh_uint8 depth);
|
||||
// Search in a straight line for a key inside the tree. Stop and return SH_STATUS_NOT_FOUND as soon as it hit a empty ptr where there should be one
|
||||
SH_STATUS sh_radix_tree_get_value(sh_radix_TREE *tree,sh_uint64 key,sh_page_VIRTUAL_ADDRESS *value);
|
||||
// Insert a value inside the tree. Can allocate new nodes if necessary. Will overwrite previous value if there was one already inserted. Automatically update bitmap on his path
|
||||
SH_STATUS sh_radix_tree_insert_value(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_page_PAGE_TABLE_POOL *ptp,sh_radix_TREE *tree,sh_uint64 key,sh_page_VIRTUAL_ADDRESS value);
|
||||
// Delete a value and deallocates all nodes (including leaf) that form a path to it if this deletion make them empty
|
||||
SH_STATUS sh_radix_tree_delete_value(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_radix_TREE *tree,sh_uint64 key);
|
||||
// Return the value that has the smallest key equal or greater than the provided key. Can't allocate new nodes.
|
||||
SH_STATUS sh_radix_tree_search_smallest_min_bound(struct sh_slab_radix_node_SLAB_ALLOCATOR *alloc,sh_radix_TREE *tree,sh_uint64 lower_bound_key,sh_page_VIRTUAL_ADDRESS *value);
|
||||
#endif
|
||||
Reference in New Issue
Block a user