Removed the vm_store::data field. Cleaned up the files a bit, removed

unused headers.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8834 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-09-03 19:08:47 +00:00
parent 3551420440
commit f3165b2826
3 changed files with 101 additions and 90 deletions

View File

@ -4,20 +4,15 @@
*/
#include <kernel.h>
#include <vm.h>
#include <malloc.h>
#include <debug.h>
#include <vm_store_anonymous_noswap.h>
#include <Errors.h>
#include <kerrors.h>
#include <KernelExport.h>
#include <vm_store_anonymous_noswap.h>
#ifndef TRACE_VM
# define TRACE_VM 0
#endif
#if TRACE_VM
# define TRACE(x) dprintf(x)
#include <stdlib.h>
#define TRACE_VM
#ifdef TRACE_VM
# define TRACE(x) dprintf x
#else
# define TRACE(x) ;
#endif
@ -29,39 +24,42 @@ anonymous_destroy(struct vm_store *store)
free(store);
}
/* anonymous_commit
* As this store provides anonymous memory that is simply discarded
* when finished with, we don't bother recording the changes
* here, so we just return 0.
*/
static off_t anonymous_commit(struct vm_store *store, off_t size)
static off_t
anonymous_commit(struct vm_store *store, off_t size)
{
return 0;
}
static int anonymous_has_page(struct vm_store *store, off_t offset)
static int
anonymous_has_page(struct vm_store *store, off_t offset)
{
return 0;
}
static ssize_t anonymous_read(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
anonymous_read(struct vm_store *store, off_t offset, iovecs *vecs)
{
panic("anonymous_store: read called. Invalid!\n");
return ERR_UNIMPLEMENTED;
return B_ERROR;
}
static ssize_t anonymous_write(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
anonymous_write(struct vm_store *store, off_t offset, iovecs *vecs)
{
// no place to write, this will cause the page daemon to skip this store
return 0;
}
/*
static int anonymous_fault(struct vm_store *backing_store, struct vm_address_space *aspace, off_t offset)
{
// unused
}
*/
static vm_store_ops anonymous_ops = {
&anonymous_destroy,
@ -74,15 +72,15 @@ static vm_store_ops anonymous_ops = {
NULL
};
/* vm_store_create_anonymous
* Create a new vm_store that uses anonymous noswap memory
*/
vm_store *
vm_store_create_anonymous_noswap()
{
vm_store *store;
store = malloc(sizeof(vm_store));
vm_store *store = malloc(sizeof(vm_store));
if (store == NULL)
return NULL;
@ -90,7 +88,6 @@ vm_store_create_anonymous_noswap()
store->ops = &anonymous_ops;
store->cache = NULL;
store->data = NULL;
store->committed_size = 0;
return store;

View File

@ -3,59 +3,68 @@
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <malloc.h>
#include <debug.h>
#include <lock.h>
#include <vm_store_device.h>
#include <Errors.h>
#include <kerrors.h>
#include <KernelExport.h>
struct device_store_data {
addr base_addr;
#include <KernelExport.h>
#include <vm_store_device.h>
#include <stdlib.h>
struct device_store {
vm_store vm;
addr_t base_address;
};
static void device_destroy(struct vm_store *store)
static void
device_destroy(struct vm_store *store)
{
if(store) {
free(store);
}
free(store);
}
static off_t device_commit(struct vm_store *store, off_t size)
static off_t
device_commit(struct vm_store *store, off_t size)
{
store->committed_size = size;
return size;
}
static int device_has_page(struct vm_store *store, off_t offset)
static int
device_has_page(struct vm_store *store, off_t offset)
{
// this should never be called
return 0;
}
static ssize_t device_read(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
device_read(struct vm_store *store, off_t offset, iovecs *vecs)
{
panic("device_store: read called. Invalid!\n");
return ERR_UNIMPLEMENTED;
return B_ERROR;
}
static ssize_t device_write(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
device_write(struct vm_store *store, off_t offset, iovecs *vecs)
{
// no place to write, this will cause the page daemon to skip this store
return 0;
}
// this fault handler should take over the page fault routine and map the page in
//
// setup: the cache that this store is part of has a ref being held and will be
// released after this handler is done
static int device_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset)
/** this fault handler should take over the page fault routine and map the page in
*
* setup: the cache that this store is part of has a ref being held and will be
* released after this handler is done
*/
static int
device_fault(struct vm_store *_store, struct vm_address_space *aspace, off_t offset)
{
struct device_store_data *d = (struct device_store_data *)store->data;
vm_cache_ref *cache_ref = store->cache->ref;
struct device_store *store = (struct device_store *)_store;
vm_cache_ref *cache_ref = store->vm.cache->ref;
vm_region *region;
// dprintf("device_fault: offset 0x%x 0x%x + base_addr 0x%x\n", offset, d->base_addr);
@ -65,15 +74,15 @@ static int device_fault(struct vm_store *store, struct vm_address_space *aspace,
(*aspace->translation_map.ops->lock)(&aspace->translation_map);
// cycle through all of the regions that map this cache and map the page in
for(region = cache_ref->region_list; region != NULL; region = region->cache_next) {
for (region = cache_ref->region_list; region != NULL; region = region->cache_next) {
// make sure this page in the cache that was faulted on is covered in this region
if(offset >= region->cache_offset && (offset - region->cache_offset) < region->size) {
if (offset >= region->cache_offset && (offset - region->cache_offset) < region->size) {
// dprintf("device_fault: mapping paddr 0x%x to vaddr 0x%x\n",
// (addr)(d->base_addr + offset),
// (addr)(region->base + (offset - region->cache_offset)));
(*aspace->translation_map.ops->map)(&aspace->translation_map,
region->base + (offset - region->cache_offset),
d->base_addr + offset, region->lock);
store->base_address + offset, region->lock);
}
}
@ -85,6 +94,7 @@ static int device_fault(struct vm_store *store, struct vm_address_space *aspace,
return 0;
}
static vm_store_ops device_ops = {
&device_destroy,
&device_commit,
@ -96,23 +106,20 @@ static vm_store_ops device_ops = {
NULL
};
vm_store *vm_store_create_device(addr base_addr)
{
vm_store *store;
struct device_store_data *d;
store = malloc(sizeof(vm_store) + sizeof(struct device_store_data));
if(store == NULL)
vm_store *
vm_store_create_device(addr_t baseAddress)
{
struct device_store *store = malloc(sizeof(struct device_store));
if (store == NULL)
return NULL;
store->ops = &device_ops;
store->cache = NULL;
store->data = (void *)((addr)store + sizeof(vm_store));
store->committed_size = 0;
store->vm.ops = &device_ops;
store->vm.cache = NULL;
store->vm.committed_size = 0;
d = (struct device_store_data *)store->data;
d->base_addr = base_addr;
store->base_address = baseAddress;
return store;
return &store->vm;
}

View File

@ -3,50 +3,57 @@
** Distributed under the terms of the NewOS License.
*/
#include <kernel.h>
#include <vm.h>
#include <malloc.h>
#include <debug.h>
#include <lock.h>
#include <vm_store_null.h>
#include <vfs.h>
#include <Errors.h>
#include <kerrors.h>
static void null_destroy(struct vm_store *store)
#include <stdlib.h>
static void
null_destroy(struct vm_store *store)
{
if(store) {
free(store);
}
free(store);
}
static off_t null_commit(struct vm_store *store, off_t size)
static off_t
null_commit(struct vm_store *store, off_t size)
{
store->committed_size = size;
return size;
}
static int null_has_page(struct vm_store *store, off_t offset)
static int
null_has_page(struct vm_store *store, off_t offset)
{
return 1; // we always have the page, man
}
static ssize_t null_read(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
null_read(struct vm_store *store, off_t offset, iovecs *vecs)
{
return -1;
}
static ssize_t null_write(struct vm_store *store, off_t offset, iovecs *vecs)
static ssize_t
null_write(struct vm_store *store, off_t offset, iovecs *vecs)
{
return -1;
}
static int null_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset)
static int
null_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset)
{
/* we can't fault on this region, that's pretty much the point of the null store object */
return ERR_VM_PF_FATAL;
}
static vm_store_ops null_ops = {
&null_destroy,
&null_commit,
@ -58,18 +65,18 @@ static vm_store_ops null_ops = {
NULL
};
vm_store *vm_store_create_null(void)
vm_store *
vm_store_create_null(void)
{
vm_store *store;
store = malloc(sizeof(vm_store));
if(store == NULL) {
if (store == NULL)
return NULL;
}
store->ops = &null_ops;
store->cache = NULL;
store->data = NULL;
store->committed_size = 0;
return store;