Subversion Repositories HelenOS

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 766

/kernel/trunk/generic/include/mm/slab.h
0,0 → 1,111
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __SLAB_H__
#define __SLAB_H__
 
#include <list.h>
#include <synch/spinlock.h>
#include <arch/atomic.h>
 
/** Initial Magazine size (TODO: dynamically growing magazines) */
#define SLAB_MAG_SIZE 4
 
/** If object size is less, store control structure inside SLAB */
#define SLAB_INSIDE_SIZE (PAGE_SIZE >> 3)
 
/** Maximum wasted space we allow for cache */
#define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order >> 2))
 
/* slab_reclaim constants */
#define SLAB_RECLAIM_ALL 0x1 /**< Reclaim all possible memory, because
* we are in memory stress */
 
/* cache_create flags */
#define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */
#define SLAB_CACHE_SLINSIDE 0x2 /**< Have control structure inside SLAB */
 
typedef struct {
link_t link;
count_t busy; /**< Count of full slots in magazine */
count_t size; /**< Number of slots in magazine */
void *objs[0]; /**< Slots in magazine */
}slab_magazine_t;
 
typedef struct {
char *name;
 
SPINLOCK_DECLARE(lock);
link_t link;
/* Configuration */
size_t size; /**< Size of SLAB position - align_up(sizeof(obj)) */
int (*constructor)(void *obj, int kmflag);
void (*destructor)(void *obj);
int flags; /**< Flags changing behaviour of cache */
 
/* Computed values */
__u8 order; /**< Order of frames to be allocated */
int objects; /**< Number of objects that fit in */
 
/* Statistics */
atomic_t allocated_slabs;
atomic_t allocated_objs;
 
/* Slabs */
link_t full_slabs; /**< List of full slabs */
link_t partial_slabs; /**< List of partial slabs */
/* Magazines */
link_t magazines; /**< List o full magazines */
 
/** CPU cache */
struct {
slab_magazine_t *current;
slab_magazine_t *last;
SPINLOCK_DECLARE(lock);
}mag_cache[0];
}slab_cache_t;
 
extern slab_cache_t * slab_cache_create(char *name,
size_t size,
size_t align,
int (*constructor)(void *obj, int kmflag),
void (*destructor)(void *obj),
int flags);
extern void slab_cache_destroy(slab_cache_t *cache);
 
extern void * slab_alloc(slab_cache_t *cache, int flags);
extern void slab_free(slab_cache_t *cache, void *obj);
extern count_t slab_reclaim(int flags);
 
/** Initialize SLAB subsytem */
extern void slab_cache_init(void);
 
/* KConsole debug */
extern void slab_print_list(void);
 
#endif
/kernel/trunk/generic/include/mm/frame.h
0,0 → 1,133
/*
* Copyright (C) 2005 Jakub Jermar
* Copyright (C) 2005 Sergey Bondari
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __FRAME_H__
#define __FRAME_H__
 
#include <arch/types.h>
#include <typedefs.h>
#include <list.h>
#include <synch/spinlock.h>
#include <mm/buddy.h>
#include <mm/slab.h>
 
#define ONE_FRAME 0
 
#define FRAME_KA 0x1 /* skip frames conflicting with user address space */
#define FRAME_PANIC 0x2 /* panic on failure */
#define FRAME_ATOMIC 0x4 /* do not panic and do not sleep on failure */
#define FRAME_NO_RECLAIM 0x8 /* Do not start reclaiming when no free memory */
 
#define FRAME_OK 0 /* frame_alloc return status */
#define FRAME_NO_MEMORY 1 /* frame_alloc return status */
#define FRAME_ERROR 2 /* frame_alloc return status */
 
#define FRAME2ADDR(zone, frame) ((zone)->base + (((frame) - (zone)->frames) << FRAME_WIDTH))
#define ADDR2FRAME(zone, addr) (&((zone)->frames[(((addr) - (zone)->base) >> FRAME_WIDTH)]))
#define FRAME_INDEX(zone, frame) ((index_t)((frame) - (zone)->frames))
#define FRAME_INDEX_ABS(zone, frame) (((index_t)((frame) - (zone)->frames)) + (zone)->base_index)
#define FRAME_INDEX_VALID(zone, index) (((index) >= 0) && ((index) < ((zone)->free_count + (zone)->busy_count)))
#define IS_BUDDY_ORDER_OK(index, order) ((~(((__native) -1) << (order)) & (index)) == 0)
#define IS_BUDDY_LEFT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
#define IS_BUDDY_RIGHT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) (((FRAME_INDEX_ABS((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) (((FRAME_INDEX_ABS((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 
#define ZONE_BLACKLIST_SIZE 4
 
struct zone {
link_t link; /**< link to previous and next zone */
 
SPINLOCK_DECLARE(lock); /**< this lock protects everything below */
__address base; /**< physical address of the first frame in the frames array */
index_t base_index; /**< frame index offset of the zone base */
frame_t *frames; /**< array of frame_t structures in this zone */
count_t free_count; /**< number of free frame_t structures */
count_t busy_count; /**< number of busy frame_t structures */
buddy_system_t * buddy_system; /**< buddy system for the zone */
int flags;
};
 
struct frame {
count_t refcount; /**< tracking of shared frames */
__u8 buddy_order; /**< buddy system block order */
link_t buddy_link; /**< link to the next free block inside one order */
void *parent; /**< If allocated by slab, this points there */
};
 
struct region {
__address base;
size_t size;
};
 
extern region_t zone_blacklist[];
extern count_t zone_blacklist_count;
extern void frame_region_not_free(__address base, size_t size);
extern void zone_create_in_region(__address base, size_t size);
 
extern spinlock_t zone_head_lock; /**< this lock protects zone_head list */
extern link_t zone_head; /**< list of all zones in the system */
 
extern zone_t *zone_create(__address start, size_t size, int flags);
extern void zone_attach(zone_t *zone);
 
extern void frame_init(void);
extern void frame_initialize(frame_t *frame, zone_t *zone);
 
__address frame_alloc(int flags, __u8 order, int * status, zone_t **pzone);
extern void frame_free(__address addr);
 
zone_t * get_zone_by_frame(frame_t * frame);
 
/*
* Buddy system operations
*/
link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy);
link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block);
link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r);
void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order);
__u8 zone_buddy_get_order(buddy_system_t *b, link_t * block);
void zone_buddy_mark_busy(buddy_system_t *b, link_t * block);
extern frame_t * frame_addr2frame(__address addr);
 
/*
* TODO: Implement the following functions.
*/
extern frame_t *frame_reference(frame_t *frame);
extern void frame_release(frame_t *frame);
 
 
/*
* Console functions
*/
extern void zone_print_list(void);
extern void zone_print_one(__address base);
 
#endif
/kernel/trunk/generic/include/mm/page.h
0,0 → 1,77
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __PAGE_H__
#define __PAGE_H__
 
#include <arch/mm/asid.h>
#include <arch/types.h>
#include <typedefs.h>
 
#define PAGE_CACHEABLE_SHIFT 0
#define PAGE_NOT_CACHEABLE_SHIFT PAGE_CACHEABLE_SHIFT
#define PAGE_PRESENT_SHIFT 1
#define PAGE_NOT_PRESENT_SHIFT PAGE_PRESENT_SHIFT
#define PAGE_USER_SHIFT 2
#define PAGE_KERNEL_SHIFT PAGE_USER_SHIFT
#define PAGE_READ_SHIFT 3
#define PAGE_WRITE_SHIFT 4
#define PAGE_EXEC_SHIFT 5
#define PAGE_GLOBAL_SHIFT 6
 
#define PAGE_NOT_CACHEABLE (0<<PAGE_CACHEABLE_SHIFT)
#define PAGE_CACHEABLE (1<<PAGE_CACHEABLE_SHIFT)
 
#define PAGE_PRESENT (0<<PAGE_PRESENT_SHIFT)
#define PAGE_NOT_PRESENT (1<<PAGE_PRESENT_SHIFT)
 
#define PAGE_USER (1<<PAGE_USER_SHIFT)
#define PAGE_KERNEL (0<<PAGE_USER_SHIFT)
 
#define PAGE_READ (1<<PAGE_READ_SHIFT)
#define PAGE_WRITE (1<<PAGE_WRITE_SHIFT)
#define PAGE_EXEC (1<<PAGE_EXEC_SHIFT)
 
#define PAGE_GLOBAL (1<<PAGE_GLOBAL_SHIFT)
 
/** Operations to manipulate page mappings. */
struct page_operations {
void (* mapping_insert)(as_t *as, __address page, __address frame, int flags);
pte_t *(* mapping_find)(as_t *as, __address page);
};
typedef struct page_operations page_operations_t;
 
extern page_operations_t *page_operations;
 
extern void page_init(void);
extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags);
extern pte_t *page_mapping_find(as_t *as, __address page);
extern pte_t *page_table_create(int flags);
extern void map_structure(__address s, size_t size);
 
#endif
/kernel/trunk/generic/include/mm/as.h
0,0 → 1,111
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __AS_H__
#define __AS_H__
 
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/mm/asid.h>
#include <arch/types.h>
#include <typedefs.h>
#include <synch/spinlock.h>
#include <list.h>
 
#define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH
#define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH
#define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH
#define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH
 
#define IS_KA(addr) ((addr)>=KERNEL_ADDRESS_SPACE_START && (addr)<=KERNEL_ADDRESS_SPACE_END)
 
#define UTEXT_ADDRESS UTEXT_ADDRESS_ARCH
#define USTACK_ADDRESS USTACK_ADDRESS_ARCH
#define UDATA_ADDRESS UDATA_ADDRESS_ARCH
 
#define FLAG_AS_KERNEL (1<<0) /**< Kernel address space. */
 
enum as_area_type {
AS_AREA_TEXT = 1, AS_AREA_DATA, AS_AREA_STACK
};
 
/** Address space area structure.
*
* Each as_area_t structure describes one contiguous area of virtual memory.
* In the future, it should not be difficult to support shared areas.
*/
struct as_area {
SPINLOCK_DECLARE(lock);
link_t link;
as_area_type_t type;
size_t size; /**< Size of this area in multiples of PAGE_SIZE. */
__address base; /**< Base address of this area. */
};
 
/** Address space structure.
*
* as_t contains the list of as_areas of userspace accessible
* pages for one or more tasks. Ranges of kernel memory pages are not
* supposed to figure in the list as they are shared by all tasks and
* set up during system initialization.
*/
struct as {
/** Protected by asidlock. Must be acquired before as->lock. */
link_t as_with_asid_link;
 
SPINLOCK_DECLARE(lock);
link_t as_area_head;
 
/** Page table pointer. Constant on architectures that use global page hash table. */
pte_t *page_table;
 
/** Address space identifier. Constant on architectures that do not support ASIDs.*/
asid_t asid;
};
 
struct as_operations {
pte_t *(* page_table_create)(int flags);
};
typedef struct as_operations as_operations_t;
 
extern as_t *AS_KERNEL;
extern as_operations_t *as_operations;
 
extern void as_init(void);
extern as_t *as_create(int flags);
extern as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base);
extern void as_set_mapping(as_t *as, __address page, __address frame);
extern int as_page_fault(__address page);
extern void as_install(as_t *m);
 
/* Interface to be implemented by architectures. */
#ifndef as_install_arch
extern void as_install_arch(as_t *as);
#endif /* !def as_install_arch */
 
#endif
/kernel/trunk/generic/include/mm/buddy.h
0,0 → 1,60
/*
* Copyright (C) 2005 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __BUDDY_H__
#define __BUDDY_H__
 
#include <arch/types.h>
#include <typedefs.h>
 
#define BUDDY_SYSTEM_INNER_BLOCK 0xff
 
/** Buddy system operations to be implemented by each implementations. */
struct buddy_system_operations {
link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */
link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */
void (*set_order)(buddy_system_t *, link_t *, __u8); /**< Set order of block passed as argument. */
__u8 (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */
void (*mark_busy)(buddy_system_t *, link_t *); /**< Mark block as busy */
};
 
struct buddy_system {
__u8 max_order; /**< Maximal order of block which can be stored by buddy system. */
link_t *order;
buddy_system_operations_t *op;
void *data; /**< Pointer to be used by the implementation. */
};
 
extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data);
extern link_t *buddy_system_alloc(buddy_system_t *b, __u8 i);
extern bool buddy_system_can_alloc(buddy_system_t *b, __u8 order);
extern void buddy_system_free(buddy_system_t *b, link_t *block);
extern void buddy_system_structure_print(buddy_system_t *b, size_t elem_size);
 
#endif
/kernel/trunk/generic/include/mm/asid.h
0,0 → 1,65
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/*
* This is generic interface for managing
* Address Space IDentifiers (ASIDs).
*/
 
#ifndef __ASID_H__
#define __ASID_H__
 
#include <arch/mm/asid.h>
#include <typedefs.h>
 
#define ASID_KERNEL 0
#define ASID_INVALID 1
#define ASID_START 2
#define ASID_MAX ASID_MAX_ARCH
 
#define ASIDS_ALLOCABLE ((ASID_MAX+1)-ASID_START)
 
extern spinlock_t asidlock;
extern link_t as_with_asid_head;
 
extern asid_t asid_get(void);
extern void asid_put(asid_t asid);
 
#ifndef asid_install
extern void asid_install(as_t *as);
#endif /* !def asid_install */
 
#ifndef asid_find_free
extern asid_t asid_find_free(void);
#endif /* !def asid_find_free */
 
#ifndef asid_put_arch
extern void asid_put_arch(asid_t asid);
#endif /* !def asid_put_arch */
 
#endif
/kernel/trunk/generic/include/mm/tlb.h
0,0 → 1,76
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __TLB_H__
#define __TLB_H__
 
#include <arch/mm/asid.h>
#include <arch/types.h>
#include <typedefs.h>
 
/** Type of TLB shootdown message. */
enum tlb_invalidate_type {
TLB_INVL_INVALID = 0, /**< Invalid type. */
TLB_INVL_ALL, /**< Invalidate all entries in TLB. */
TLB_INVL_ASID, /**< Invalidate all entries belonging to one address space. */
TLB_INVL_PAGES /**< Invalidate specified page range belonging to one address space. */
};
 
typedef enum tlb_invalidate_type tlb_invalidate_type_t;
 
/** TLB shootdown message. */
struct tlb_shootdown_msg {
tlb_invalidate_type_t type; /**< Message type. */
asid_t asid; /**< Address space identifier. */
__address page; /**< Page address. */
};
 
typedef struct tlb_shootdown_msg tlb_shootdown_msg_t;
 
extern void tlb_init(void);
 
#ifdef CONFIG_SMP
extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, __address page, count_t cnt);
extern void tlb_shootdown_finalize(void);
extern void tlb_shootdown_ipi_recv(void);
#else
# define tlb_shootdown_start(w, x, y, z)
# define tlb_shootdown_finalize()
# define tlb_shootdown_ipi_recv()
#endif /* CONFIG_SMP */
 
 
/* Export TLB interface that each architecture must implement. */
extern void tlb_arch_init(void);
extern void tlb_print(void);
extern void tlb_shootdown_ipi_send(void);
 
extern void tlb_invalidate_all(void);
extern void tlb_invalidate_asid(asid_t asid);
extern void tlb_invalidate_pages(asid_t asid, __address page, count_t cnt);
#endif
/kernel/trunk/generic/include/mm/heap.h
0,0 → 1,51
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __HEAP_H__
#define __HEAP_H__
 
#include <arch/types.h>
#include <typedefs.h>
 
#define malloc(size) early_malloc(size)
#define free(ptr) early_free(ptr)
 
struct chunk {
int used;
chunk_t *next;
chunk_t *prev;
__u32 size;
__native data[0];
};
 
extern void early_heap_init(__address heap, size_t size);
 
extern void *early_malloc(size_t size) __attribute__ ((malloc));
extern void early_free(void *ptr);
 
#endif