Some more progress on resource management and boot up.

This commit is contained in:
Bahadir Balban
2009-07-29 13:32:38 +03:00
parent 2b0ea24e94
commit dd8f773f10
17 changed files with 950 additions and 86 deletions

View File

@@ -0,0 +1,83 @@
/*
* Types of capabilities and their operations
*
* Copyright (C) 2009 Bahadir Balban
*/
#ifndef __CAP_TYPES_H__
#define __CAP_TYPES_H__
/*
* Capability types
*/
#define CAP_TYPE_MASK 0x0000FFFF
#define CAP_TYPE_TCTRL (1 << 0)
#define CAP_TYPE_EXREGS (1 << 1)
#define CAP_TYPE_MAP (1 << 2)
#define CAP_TYPE_IPC (1 << 3)
#define CAP_TYPE_SCHED (1 << 4)
#define CAP_TYPE_UMUTEX (1 << 5)
#define CAP_TYPE_QUANTITY (1 << 6)
/*
* Resource types
*/
#define CAP_RTYPE_MASK 0xFFFF0000
#define CAP_RTYPE_THREAD (1 << 16)
#define CAP_RTYPE_TGROUP (1 << 17)
#define CAP_RTYPE_SPACE (1 << 18)
#define CAP_RTYPE_CONTAINER (1 << 19)
#define CAP_RTYPE_UMUTEX (1 << 20)
#define CAP_RTYPE_VIRTMEM (1 << 21)
#define CAP_RTYPE_PHYSMEM (1 << 22)
#define CAP_RTYPE_CPUPOOL (1 << 23)
#define CAP_RTYPE_THREADPOOL (1 << 24)
#define CAP_RTYPE_SPACEPOOL (1 << 25)
#define CAP_RTYPE_MUTEXPOOL (1 << 27)
#define CAP_RTYPE_MEMPOOL (1 << 26) /* Do we need this ??? */
/*
* Access permissions
*/
/* Thread control capability */
#define CAP_TCTRL_CREATE (1 << 0)
#define CAP_TCTRL_DESTROY (1 << 1)
#define CAP_TCTRL_SUSPEND (1 << 2)
#define CAP_TCTRL_RESUME (1 << 3)
#define CAP_TCTRL_RECYCLE (1 << 4)
/* Exchange registers capability */
#define CAP_EXREGS_RW_PAGER (1 << 0)
#define CAP_EXREGS_RW_UTCB (1 << 1)
#define CAP_EXREGS_RW_SP (1 << 2)
#define CAP_EXREGS_RW_PC (1 << 3)
#define CAP_EXREGS_RW_REGS (1 << 4)
#define CAP_EXREGS_RW_CPU (1 << 5)
#define CAP_EXREGS_RW_CPUTIME (1 << 6)
/* Map capability */
#define CAP_MAP_READ (1 << 0)
#define CAP_MAP_WRITE (1 << 1)
#define CAP_MAP_EXEC (1 << 2)
#define CAP_MAP_CACHED (1 << 3)
#define CAP_MAP_UNCACHED (1 << 4)
#define CAP_MAP_UNMAP (1 << 5)
/* Ipc capability */
#define CAP_IPC_SEND (1 << 0)
#define CAP_IPC_RECV (1 << 1)
#define CAP_IPC_SHORT (1 << 2)
#define CAP_IPC_FULL (1 << 3)
#define CAP_IPC_EXTENDED (1 << 4)
#define CAP_IPC_ASYNC (1 << 5)
/* Userspace mutex capability */
#define CAP_UMUTEX_LOCK (1 << 0)
/* Capability control capability */
#define CAP_CAP_SPLIT (1 << 0)
#define CAP_CAP_SPLICE (1 << 1)
#define CAP_CAP_REDUCE (1 << 2)
#define CAP_CAP_REVOKE (1 << 3)
#define CAP_CAP_GRANT (1 << 4)
#endif /* __CAP_TYPES_H__ */

View File

@@ -0,0 +1,177 @@
/*
* Codezero Capability Definitions
*
* Copyright (C) 2009 Bahadir Balban
*/
#ifndef __CAPABILITY_H__
#define __CAPABILITY_H__
#include <l4/lib/list.h>
/*
* A capability is a unique representation of security
* qualifiers on a particular resource.
*
* In this structure:
*
* The capid denotes the unique capability ID. The resid denotes the unique ID
* of targeted resource. The owner denotes the unique ID of capability owner.
* This is almost always a thread ID.
*
* The type field contains two types: The capability type, and the targeted
* resource type. The targeted resouce type denotes what type of resource the
* capability is allowed to operate on. For example a thread, a thread group,
* an address space or a memory can be of this type.
*
* The capability type defines the general set of operations allowed on a
* particular resource. The resource type defines the type of resource that
* the capability is targeting. For example a capability type may be
* thread_control, exchange_registers, ipc, or map operations. A resource type
* may be such as a thread, a thread group, a virtual or physical memory
* region.
*
* There are also quantitative capability types. While their names denote
* quantitative objects such as memory, threads, and address spaces, these
* types actually define the quantitative operations available on those
* resources such as creation and deletion of a thread, allocation and
* deallocation of a memory region etc.
*
* The access field denotes the fine-grain operations available on a particular
* resource. The meaning of each bitfield differs according to the type of the
* capability. For example, for a capability type thread_control, the bitfields
* may mean suspend, resume, create, delete etc.
*/
struct capability {
struct link list;
/* Capability identifiers */
l4id_t capid; /* Unique capability ID */
l4id_t resid; /* Targeted resource ID */
l4id_t owner; /* Capability owner ID */
unsigned int type; /* Capability and target resource type */
/* Capability limits/permissions */
u32 access; /* Permitted operations */
/* Limits on the resource */
unsigned long start; /* Resource start value */
unsigned long end; /* Resource end value */
unsigned long size; /* Resource size */
};
struct cap_list {
int ncaps;
struct link caps;
};
#if 0
/* Virtual memory space allocated to container */
struct capability cap_virtmap = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_VIRTMEM,
.access = 0, /* No access operations */
.start = 0xF0000000,
.end = 0xF1000000,
.size = 0x1000000
};
/* Physical memory space allocated to container */
struct capability cap_physmap = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_PHYSMEM,
.access = 0, /* No access operations */
.start = 0x0,
.end = 0x1000000,
.size = 0x1000000
};
/* IPC operations permitted on target thread */
struct capability cap_ipc = {
.capid = id_alloc(capids),
.resid = target_tid,
.owner = tid,
.type = CAP_TYPE_IPC,
.access = CAP_IPC_SEND | CAP_IPC_RECV | CAP_IPC_FULL | CAP_IPC_SHORT | CAP_IPC_EXTENDED,
.start = 0xF0000000,
.end = 0xF1000000,
.size = 0x1000000
};
/* Thread control operations permitted on target thread */
struct capability cap_thread_control = {
.capid = id_alloc(capids),
.resid = target_tid,
.owner = pagerid,
.type = CAP_TYPE_THREAD_CONTROL,
.access = CAP_THREAD_SUSPEND | CAP_THREAD_RUN | CAP_THREAD_RECYCLE | CAP_THREAD_CREATE | CAP_THREAD_DESTROY,
.start = 0,
.end = 0,
.size = 0,
};
/* Exregs operations permitted on target thread */
struct capability cap_exregs = {
.capid = id_alloc(capids),
.resid = target_tid,
.owner = pagerid,
.type = CAP_TYPE_EXREGS,
.access = CAP_EXREGS_RW_PAGER | CAP_EXREGS_RW_SP | CAP_EXREGS_RW_PC | CAP_EXREGS_RW_UTCB | CAP_EXREGS_RW_OTHERS,
.start = 0,
.end = 0,
.size = 0
};
/* Number of threads allocated to container */
struct capability cap_threads = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_THREADS,
.access = 0,
.start = 0,
.end = 0,
.size = 256,
};
/* Number of spaces allocated to container */
struct capability cap_spaces = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_SPACES,
.access = 0,
.start = 0,
.end = 0,
.size = 128,
};
/* CPU time allocated to container */
struct capability cap_cputime = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_CPUTIME,
.access = 0,
.start = 0,
.end = 0,
.size = 55, /* Percentage */
};
struct capability cap_cpuprio = {
.capid = id_alloc(capids),
.resid = container_id,
.owner = pagerid,
.type = CAP_TYPE_CPUPRIO,
.access = 0,
.start = 0,
.end = 0,
.size = 55, /* Priority No */
};
#endif
#endif /* __CAPABILITY_H__ */

View File

@@ -9,11 +9,14 @@
#include <l4/generic/scheduler.h>
#include <l4/generic/space.h>
#include <l4/generic/capability.h>
#include <l4/generic/tcb.h>
#include <l4/lib/idpool.h>
#include <l4/api/mutex.h>
#include <l4/lib/list.h>
#include <l4/lib/idpool.h>
/* Container macro. No locks needed! */
#define container (current->container)
#define this_container (current->container)
struct container {
/* Unique container id */
@@ -47,21 +50,48 @@ struct container {
/* The array of containers present on the system */
extern struct container container[];
struct memdesc {
/* Compact, raw capability structure */
struct cap_info {
unsigned int type;
u32 access;
unsigned long start;
unsigned long end;
unsigned int flags;
unsigned long size;
};
struct cinfo {
char cname[32];
struct pager_info {
unsigned long pager_lma;
unsigned long pager_vma;
unsigned long pager_size;
unsigned long total_memdesc;
struct memdesc memdesc[];
/* Number of capabilities defined */
int ncaps;
/*
* Zero or more ipc caps,
* One or more thread pool caps,
* One or more space pool caps,
* One or more exregs caps,
* One or more tcontrol caps,
* One or more cputime caps,
* One or more physmem caps,
* One or more virtmem caps,
* Zero or more umutex caps,
*/
struct cap_info caps[];
};
/*
* This auto-generated structure is
* used to create run-time containers
*/
struct container_info {
char *name;
int npagers;
struct pager_info pagers[];
};
extern struct container_info cinfo[];
#endif /* __CONTAINER_H__ */

View File

@@ -0,0 +1,51 @@
#ifndef __RESOURCES_H__
#define __RESOURCES_H__
/* Number of containers defined at compile-time */
#define CONTAINERS_TOTAL 1
#include <l4/generic/capability.h>
struct boot_resources {
int nconts;
int ncaps;
int nids;
int nthreads;
int nspaces;
int npmds;
/* Kernel resource usage */
int nkpmds;
int nkpgds;
int nkmemcaps;
};
struct kernel_container {
/* Physical memory caps, used/unused */
struct cap_list physmem_used;
struct cap_list physmem_free;
/* Virtual memory caps, used/unused */
struct cap_list virtmem_used;
struct cap_list virtmem_free;
/* Device memory caps, used/unused */
struct cap_list devmem_used;
struct cap_list devmem_free;
struct mem_cache *pgd_cache;
struct mem_cache *pmd_cache;
struct mem_cache *ktcb_cache;
struct mem_cache *address_space_cache;
struct mem_cache *umutex_cache;
struct mem_cache *cap_cache;
struct mem_cache *cont_cache;
};
extern struct kernel_container kernel_container;
int init_system_resources(struct kernel_container *kcont,
struct boot_resources *bootres);
#endif /* __RESOURCES_H__ */

View File

@@ -20,8 +20,10 @@
#if defined (__KERNEL__)
#include <l4/lib/spinlock.h>
#include <l4/lib/list.h>
#include <l4/lib/mutex.h>
#include <l4/lib/idpool.h>
#include INC_SUBARCH(mm.h)
/* A simple page table with a reference count */
@@ -33,6 +35,17 @@ struct address_space {
int ktcb_refs;
};
struct address_space_list {
struct link list;
/* Lock for list add/removal */
struct spinlock list_lock;
/* Used when delete/creating spaces */
struct mutex ref_lock;
int count;
};
struct address_space *address_space_create(struct address_space *orig);
void address_space_delete(struct address_space *space);
void address_space_attach(struct ktcb *tcb, struct address_space *space);

View File

@@ -8,6 +8,7 @@
#include <l4/lib/list.h>
#include <l4/lib/mutex.h>
#include <l4/lib/spinlock.h>
#include <l4/generic/scheduler.h>
#include <l4/generic/pgalloc.h>
#include <l4/generic/space.h>
@@ -121,6 +122,13 @@ union ktcb_union {
};
/* Hash table for all existing tasks */
struct ktcb_list {
struct link list;
struct spinlock list_lock;
int count;
};
/*
* Each task is allocated a unique global id. A thread group can only belong to
* a single leader, and every thread can only belong to a single thread group.

View File

@@ -30,6 +30,7 @@ struct mem_cache {
unsigned int *bitmap;
};
int mem_cache_bufsize(void *start, int struct_size, int nstructs, int aligned);
void *mem_cache_zalloc(struct mem_cache *cache);
void *mem_cache_alloc(struct mem_cache *cache);
int mem_cache_free(struct mem_cache *cache, void *addr);