Beispiel #1
0
StorageArea* Storage::create_area( ConfigElem& elem )
{
    const char* rest = elem.rest();
    if (rest && rest[0])
    {
        return create_area( rest );
    }
    else
    {
        string name = elem.remove_string( "NAME" );
        return create_area( name );
    }
}
Beispiel #2
0
NWindowScreen::NWindowScreen(status_t *ret)
	: BWindowScreen("Example", B_8_BIT_640x480, ret), width(639), height(479), COLORS(256)
{
	PRINT(("WindowScreen ctor.\n"));
	thread_is_locked = true;
	tid = 0;
	if(*ret == B_OK)
	{
		PRINT(("creating blocking sem and save_buffer area.\n"));
		// this semaphore controls the access to the WindowScreen
		sem = create_sem(0,"WindowScreen Access");
		// this area is used to save the whole framebuffer when
		//       switching workspaces. (better than malloc()).
		area = create_area("save", (void**)&save_buffer, B_ANY_ADDRESS, 640*480, B_NO_LOCK, B_READ_AREA|B_WRITE_AREA);
		// exit if an error occured.
		if((sem < B_OK) || (area < B_OK))
		{
			PRINT(("create_area() or create_sem() failed\n"));
			*ret = B_ERROR;
		}
		else
		{
			PRINT(("calling Show().\n"));
			Show(); // let's go. See you in ScreenConnected.
		}
	}
	else
	{
		PRINT(("BWindowScreen base class ctor returned failure\n"));
		be_app->PostMessage(B_QUIT_REQUESTED);
	}
	// set the frame rate
	set_frame_rate(30.);
}
Beispiel #3
0
LM_STATUS
MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
	PLM_VOID *pMemoryBlockVirt, PLM_PHYSICAL_ADDRESS pMemoryBlockPhy,
	LM_BOOL cached /* we ignore this */)
{
	struct be_b57_dev *dev;
	void *pvirt = NULL;
	area_id area_desc;
	physical_entry entry;

	dev = (struct be_b57_dev *)(pDevice);
	area_desc = dev->lockmem_list[dev->lockmem_list_num++] = create_area("broadcom_shared_mem",
		&pvirt, B_ANY_KERNEL_ADDRESS, ROUND_UP_TO_PAGE(BlockSize),
		B_CONTIGUOUS, 0);

	if (area_desc < B_OK)
		return LM_STATUS_FAILURE;

	memset(pvirt, 0, BlockSize);
	*pMemoryBlockVirt = (PLM_VOID) pvirt;

	get_memory_map(pvirt,BlockSize,&entry,1);
	pMemoryBlockPhy->Low = (uint32)entry.address;
	pMemoryBlockPhy->High = (uint32)(entry.address >> 32);
		/* We only support 32 bit */

	return LM_STATUS_SUCCESS;
}
Beispiel #4
0
static void init_heap( CacheHeap_s *psHeap )
{
	char *pPtr;
	uint32 nBufSize;
	uint32 nMaxBufSize = g_sSysBase.ex_nTotalPageCount * PAGE_SIZE;
	int nCnt = 0;

	if ( nMaxBufSize > 1024 * 1024 * 128 )
	{
		nMaxBufSize = 1024 * 1024 * 128;
	}
      retry:
	psHeap->ch_nSize = 4096 * 10;
	psHeap->ch_nUsedBlocks = 0;
	
	atomic_add( &g_sSysBase.ex_nBlockCacheSize, psHeap->ch_nSize );

	psHeap->ch_hAreaID = create_area( "bcache_1024", &psHeap->ch_pAddress, psHeap->ch_nSize, nMaxBufSize, AREA_FULL_ACCESS | AREA_KERNEL, AREA_FULL_LOCK );
	if ( psHeap->ch_hAreaID < 0 )
	{
		if ( psHeap->ch_hAreaID == -ENOADDRSPC && nMaxBufSize > psHeap->ch_nSize * 2 )
		{
			nMaxBufSize >>= 1;
			goto retry;
		}
		panic( "init_heap() failed to create area for %d size blocks\n", psHeap->ch_nBlockSize );
	}
Beispiel #5
0
/**********************************************************************
create_element (ElementStruct element, int issueHour, 
                char *eleStr, char *errorStr)
    This function takes information contained in the
    element structure and creates the string indicating the element
    type and calls create_area for each area of this type.
Input Parameters:
    element      ElementStruct   
    hour         int           issuance hour of gamet
Output Parameters:
    elementString char         string of type and information on each area
    errorStr      char         concatenated string of errors occurred while
                               creating area string
Functions Called:
    element_string
    create_area
    add_area_errors

**********************************************************************/
void create_element (ElementStruct element, int hour, 
  char *elementString, char *errors)
{
    char aString[256];
    char estr[64];
    int j;
    int retCode;
    /* Initial check */
    if (element.type >= MAX_ELEMENTS) {
        if (strlen(errors) == (size_t)0) {
            sprintf(estr, "Unexpected Element Type.");
            strcpy (errors, estr);
        }
        else {
            sprintf (estr, "; Unexpected Element Type.");
            strcat(errors, estr);
        }
        /* encountered error, set type to no type */
        element.type = no_element_type;
    }
    sprintf (elementString, "\n%s: ", element_string (element.type));
    /* For each area in an element, create the string */
    for (j = 0; j < element.numAreas; j++) {
        aString[0] = '\0';
        retCode = AREA_NO_ERROR;
        create_area(element.area[j], hour, j, element.type, &retCode, aString);
        /* check for errors */
        if (retCode != AREA_NO_ERROR)
            add_area_errors (retCode, element.type, j, errors);
        /* put a period between areas */
        if (j < element.numAreas - 1)
            strcat(aString, ". ");
        strcat (elementString, aString);
    }
}
Beispiel #6
0
void merge_areas(object_t *merged, object_t *source) {
	int i;
	for (i = 0; i < source->areas->length; ++i) {
		area_t *source_area = source->areas->items[i];
		area_t *merged_area = get_area_by_name(merged, source_area->name);
		if (merged_area == NULL) {
			merged_area = create_area(source_area->name);
			list_add(merged->areas, merged_area);
		}
		uint64_t new_address = merged_area->data_length;
		relocate_area(source_area, new_address, true);

		append_to_area(merged_area, source_area->data, source_area->data_length);
		list_cat(merged_area->symbols, source_area->symbols);
		list_cat(merged_area->late_immediates, source_area->late_immediates);
		// NOTE: I know this is not very good SoC
		metadata_t *new_functions = get_area_metadata(source_area, "scas.functions");
		metadata_t *old_functions = get_area_metadata(merged_area, "scas.functions");
		if (new_functions) {
			list_t *decoded = decode_function_metadata(source_area, new_functions->value, new_functions->value_length);
			list_t *merged;
			if (old_functions) {
				merged = decode_function_metadata(source_area, old_functions->value, old_functions->value_length);
			} else {
				merged = create_list();
			}
			list_cat(merged, decoded);
			uint64_t len;
			char *merged_metadata = encode_function_metadata(merged, &len);
			set_area_metadata(merged_area, "scas.functions", merged_metadata, len);
		}
		list_cat(merged_area->source_map, source_area->source_map);
	}
}
Beispiel #7
0
static bool
scsi_alloc_dma_buffer_sg_orig(dma_buffer *buffer, size_t size)
{
	// free old list first
	scsi_free_dma_buffer_sg_orig(buffer);

	size = (size * sizeof(physical_entry) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);

	buffer->sg_orig = create_area("S/G to original data",
		(void **)&buffer->sg_list_orig,
		B_ANY_KERNEL_ADDRESS, size,
		B_NO_LOCK, 0);
	if (buffer->sg_orig < 0) {
		SHOW_ERROR(2, "Cannot S/G list buffer to original data of %" B_PRIuSIZE
			" bytes", size);
		return false;
	}

	buffer->sg_count_max_orig = size / sizeof(physical_entry);

	SHOW_INFO(3, "Got up to %" B_PRIuSIZE " S/G entries to original data",
		buffer->sg_count_max_orig);

	return true;
}
Beispiel #8
0
Datei: osl.c Projekt: PyroOS/Pyro
void __iomem *
acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
{
	area_id area;
	unsigned long base = (unsigned long)phys;
	void *addr = NULL;
	unsigned long length = size;
	

	if (!acpi_gbl_permanent_mmap)
		return NULL;

	area = create_area( "acpi_memory", &addr, PAGE_ALIGN( length ) + PAGE_SIZE, PAGE_ALIGN( length ) + PAGE_SIZE,
												AREA_ANY_ADDRESS|AREA_KERNEL, AREA_FULL_LOCK );
	if( area < 0 )
	{
		printk( "acpi_os_map_memory() could not create area with size 0x%x\n", (uint)size );
		return NULL;
	}
	
	if( remap_area( area, (void*)( base & PAGE_MASK ) ) < 0 )
	{
		printk( "acpi_os_map_memory() could not remap area to 0x%x\n", (uint)phys );
		return NULL;
	}
	
	//printk( "acpi_os_map_memory() remapped 0x%x to 0x%x size 0x%x\n", (uint)base, (uint)addr, (uint)length );

	base = (unsigned long)addr + ( base - ( base & PAGE_MASK ) );

	return (void*)base;
}
Beispiel #9
0
void time_faults()
{
	const int FAULT_PAGES = 100;
	char *addr;
	int area = create_area("fault area", (void**) &addr, 0, FAULT_PAGES
		* PAGE_SIZE, AREA_NOT_WIRED, USER_READ | USER_WRITE);

	bigtime_t start = system_time();
	char *c = addr;
	for (int i = 0; i < FAULT_PAGES; i++) {
		*c = 0;
		c += PAGE_SIZE;
	}
	
	bigtime_t time1 = system_time() - start;
	start = system_time();
	c = addr;
	for (int i = 0; i < FAULT_PAGES; i++) {
		*c = 0;
		c += PAGE_SIZE;
	}
	
	bigtime_t time2 = system_time() - start;
	printf("\n%d pages.  fault time %Ldus (%Ldus per fault) no fault time %Ldus (%Ldus per fault)\n",
		FAULT_PAGES, time1, time1 / FAULT_PAGES, time2, time2 / FAULT_PAGES);

	delete_area(area);
}
Beispiel #10
0
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{
    physical_entry pe;
    void * logadr;
    area_id areaid;
    status_t rv;

    TRACE("allocating %#08X bytes for %s\n", (int)size, name);

    size = round_to_pagesize(size);
    areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
                         B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
    if (areaid < B_OK) {
        TRACE("couldn't allocate area %s\n",name);
        return B_ERROR;
    }
    rv = get_memory_map(logadr,size,&pe,1);
    if (rv < B_OK) {
        delete_area(areaid);
        TRACE("couldn't map %s\n",name);
        return B_ERROR;
    }
    memset(logadr,0,size);
    if (log)
        *log = logadr;
    if (phy)
        *phy = pe.address;
    TRACE("area = %d, size = %#08X, log = %#08X, phy = %#08X\n", (int)areaid, (int)size, (int)logadr, (int)pe.address);
    return areaid;
}
Beispiel #11
0
area_id
alloc_contiguous(void **virt, void **phy, size_t size, uint32 protection,
	const char *name)
{
	physical_entry pe;
	void * virtadr;
	area_id areaid;
	status_t rv;

	TRACE("allocating %ld bytes for %s\n", size, name);

	size = round_to_pagesize(size);
	areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
		B_CONTIGUOUS, protection);
	if (areaid < B_OK) {
		ERROR("couldn't allocate area %s\n", name);
		return B_ERROR;
	}
	rv = get_memory_map(virtadr, size, &pe, 1);
	if (rv < B_OK) {
		delete_area(areaid);
		ERROR("couldn't get mapping for %s\n", name);
		return B_ERROR;
	}
	memset(virtadr, 0, size);
	if (virt)
		*virt = virtadr;
	if (phy)
		*phy = pe.address;
	TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", areaid, size, virtadr, pe.address);
	return areaid;
}
Beispiel #12
0
area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
	const char *name)
{
// TODO: phy should be phys_addr_t*!
	physical_entry pe;
	void * virtadr;
	area_id areaid;
	status_t rv;

	TRACE("allocating %ld bytes for %s\n", size, name);

	size = ROUNDUP(size, B_PAGE_SIZE);
	areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
		B_32_BIT_CONTIGUOUS, protection);
		// TODO: The rest of the code doesn't deal correctly with physical
		// addresses > 4 GB, so we have to force 32 bit addresses here.
	if (areaid < B_OK) {
		TRACE("couldn't allocate area %s\n", name);
		return B_ERROR;
	}
	rv = get_memory_map(virtadr, size, &pe, 1);
	if (rv < B_OK) {
		delete_area(areaid);
		TRACE("couldn't map %s\n", name);
		return B_ERROR;
	}
	if (virt)
		*virt = virtadr;
	if (phy)
		*phy = (void*)(addr_t)pe.address;
	TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", areaid, size, virtadr, pe.address);
	return areaid;
}
Beispiel #13
0
area_id
Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
                    const char *name)
{
    TRACE("allocating %ld bytes for %s\n", size, name);

    void *logAddress;
    size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
    area_id area = create_area(name, &logAddress, B_ANY_KERNEL_ADDRESS, size,
                               B_CONTIGUOUS, 0);

    if (area < B_OK) {
        TRACE_ERROR("couldn't allocate area %s\n", name);
        return B_ERROR;
    }

    physical_entry physicalEntry;
    status_t result = get_memory_map(logAddress, size, &physicalEntry, 1);
    if (result < B_OK) {
        delete_area(area);
        TRACE_ERROR("couldn't map area %s\n", name);
        return B_ERROR;
    }

    memset(logAddress, 0, size);
    if (logicalAddress)
        *logicalAddress = logAddress;

    if (physicalAddress)
        *physicalAddress = physicalEntry.address;

    TRACE("area = %ld, size = %ld, log = %p, phy = %p\n",
          area, size, logAddress, physicalEntry.address);
    return area;
}
Beispiel #14
0
/*! Create a list of display_modes to pass back to the caller.
*/
status_t
create_mode_list(void)
{
	size_t max_size;
	uint32 i, j, pix_clk_range;
	const display_mode *src;
	display_mode *dst, low, high;
	color_space spaces[4] = {B_RGB32_LITTLE, B_RGB16_LITTLE, B_RGB15_LITTLE, B_CMAP8};

	/* figure out how big the list could be, and adjust up to nearest multiple of B_PAGE_SIZE */
	max_size = (((MODE_COUNT * 4) * sizeof(display_mode)) + (B_PAGE_SIZE-1)) & ~(B_PAGE_SIZE-1);

	/* create an area to hold the info */
	si->mode_area = my_mode_list_area = create_area("NV accelerant mode info",
		(void **)&my_mode_list, B_ANY_ADDRESS, max_size, B_NO_LOCK,
		B_READ_AREA | B_WRITE_AREA);
	if (my_mode_list_area < B_OK)
		return my_mode_list_area;

	/* walk through our predefined list and see which modes fit this device */
	src = mode_list;
	dst = my_mode_list;
	si->mode_count = 0;
	for (i = 0; i < MODE_COUNT; i++) {
		/* set ranges for acceptable values */
		low = high = *src;
		/* range is 6.25% of default clock: arbitrarily picked */ 
		pix_clk_range = low.timing.pixel_clock >> 5;
		low.timing.pixel_clock -= pix_clk_range;
		high.timing.pixel_clock += pix_clk_range;
		/* 'some cards need wider virtual widths for certain modes':
		 * Not true. They might need a wider pitch, but this is _not_ reflected in
		 * virtual_width, but in fbc.bytes_per_row. */
		//So disable next line: 
		//high.virtual_width = 4096;
		/* do it once for each depth we want to support */
		for (j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++) {
			/* set target values */
			*dst = *src;
			/* poke the specific space */
			dst->space = low.space = high.space = spaces[j];
			/* ask for a compatible mode */
			/* We have to check for B_OK, because otherwise the pix_clk_range
			 * won't be taken into account!! */
			//So don't do this: 
			//if (PROPOSE_DISPLAY_MODE(dst, &low, &high) != B_ERROR) {
			//Instead, do this:
			if (PROPOSE_DISPLAY_MODE(dst, &low, &high) == B_OK) {
				/* count it, and move on to next mode */
				dst++;
				si->mode_count++;
			}
		}
		/* advance to next mode */
		src++;
	}

	return B_OK;
}
	char* page_aligned_allocator::malloc(page_aligned_allocator::size_type bytes)
	{
		TORRENT_ASSERT(bytes > 0);
		// just sanity check (this needs to be pretty high
		// for cases where the cache size is several gigabytes)
		TORRENT_ASSERT(bytes < 0x30000000);

		TORRENT_ASSERT(int(bytes) >= page_size());
#ifdef TORRENT_DEBUG_BUFFERS
		const int page = page_size();
		const int num_pages = (bytes + (page-1)) / page + 2;
		const int orig_bytes = bytes;
		bytes = num_pages * page;
#endif

		char* ret;
#if TORRENT_USE_POSIX_MEMALIGN
		if (posix_memalign(reinterpret_cast<void**>(&ret), page_size(), bytes)
			!= 0) ret = NULL;
#elif TORRENT_USE_MEMALIGN
		ret = static_cast<char*>(memalign(page_size(), bytes));
#elif defined TORRENT_WINDOWS
		ret = static_cast<char*>(_aligned_malloc(bytes, page_size()));
#elif defined TORRENT_BEOS
		area_id id = create_area("", &ret, B_ANY_ADDRESS
			, (bytes + page_size() - 1) & (page_size()-1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
		if (id < B_OK) return NULL;
		ret = static_cast<char*>(ret);
#else
		ret = static_cast<char*>(valloc(size_t(bytes)));
#endif
		if (ret == NULL) return NULL;

#ifdef TORRENT_DEBUG_BUFFERS
		// make the two surrounding pages non-readable and -writable
		alloc_header* h = (alloc_header*)ret;
		h->size = orig_bytes;
		h->magic = 0x1337;
		print_backtrace(h->stack, sizeof(h->stack));

#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULL)
#define PROT_READ PAGE_READONLY
#endif
		mprotect(ret, page, PROT_READ);
		mprotect(ret + (num_pages-1) * page, page, PROT_READ);

#ifdef TORRENT_WINDOWS
#undef mprotect
#undef PROT_READ
#endif
//		fprintf(stderr, "malloc: %p head: %p tail: %p size: %d\n", ret + page, ret, ret + page + bytes, int(bytes));

		return ret + page;
#endif // TORRENT_DEBUG_BUFFERS

		return ret;
	}
Beispiel #16
0
void *
contigmalloc(int size, int p1, int p2, int p3, int p4, int p5, int p6)
{
	void *adr;
	if (create_area("contigmalloc", &adr, B_ANY_KERNEL_ADDRESS, size,
			B_CONTIGUOUS, 0) < B_OK)
		return NULL;
	return adr;
}
Beispiel #17
0
static status_t createGARTBuffer( GART_info *gart, size_t size )
{
	physical_entry map[1];
	void *unaligned_addr, *aligned_phys;

	SHOW_FLOW0( 3, "" );

	gart->buffer.size = size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);

	// we allocate an contiguous area having twice the size
	// to be able to find an aligned, contiguous range within it;
	// the graphics card doesn't care, but the CPU cannot
	// make an arbitrary area WC'ed, at least elder ones
	// question: is this necessary for a PCI GART because of bus snooping?
	gart->buffer.unaligned_area = create_area( "Radeon PCI GART buffer",
		&unaligned_addr, B_ANY_KERNEL_ADDRESS,
		2 * size, B_CONTIGUOUS/*B_FULL_LOCK*/, B_READ_AREA | B_WRITE_AREA | B_USER_CLONEABLE_AREA );
		// TODO: Physical aligning can be done without waste using the
		// private create_area_etc().
	if (gart->buffer.unaligned_area < 0) {
		SHOW_ERROR( 1, "cannot create PCI GART buffer (%s)",
			strerror( gart->buffer.unaligned_area ));
		return gart->buffer.unaligned_area;
	}

	get_memory_map( unaligned_addr, B_PAGE_SIZE, map, 1 );

	aligned_phys =
		(void **)((map[0].address + size - 1) & ~(size - 1));

	SHOW_FLOW( 3, "aligned_phys=%p", aligned_phys );

	gart->buffer.area = map_physical_memory( "Radeon aligned PCI GART buffer",
		(addr_t)aligned_phys,
		size, B_ANY_KERNEL_BLOCK_ADDRESS | B_MTR_WC,
		B_READ_AREA | B_WRITE_AREA, &gart->buffer.ptr );

	if( gart->buffer.area < 0 ) {
		SHOW_ERROR0( 3, "cannot map buffer with WC" );
		gart->buffer.area = map_physical_memory( "Radeon aligned PCI GART buffer",
			(addr_t)aligned_phys,
			size, B_ANY_KERNEL_BLOCK_ADDRESS,
			B_READ_AREA | B_WRITE_AREA, &gart->buffer.ptr );
	}

	if( gart->buffer.area < 0 ) {
		SHOW_ERROR0( 1, "cannot map GART buffer" );
		delete_area( gart->buffer.unaligned_area );
		gart->buffer.unaligned_area = -1;
		return gart->buffer.area;
	}

	memset( gart->buffer.ptr, 0, size );

	return B_OK;
}
Beispiel #18
0
void *
area_malloc(size_t size)
{
	void *p;
	size = ROUNDUP(size, B_PAGE_SIZE);
	
	if (create_area("area_malloc", &p, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK, 0) < 0)
		return 0;
	return p;
}
Beispiel #19
0
void
test_gart()
{
	addr_t apertureBase;
	aperture_id aperture = sGART->map_aperture(0, 0, 0, 0, &apertureBase);
	printf("Map Aperture: %ld, base %lx\n", aperture, apertureBase);

	aperture_info info;
	sGART->get_aperture_info(aperture, &info);
	printf("Aperture: base %lx, physical base %lx, size %ld, reserved %ld\n",
		info.base, info.physical_base, info.size, info.reserved_size);

	addr_t base[5], physical[5];
	allocate(aperture, 2 * B_PAGE_SIZE, 0, 0, base[0], physical[0]);
	allocate(aperture, 4 * B_PAGE_SIZE, 0, B_APERTURE_NON_RESERVED, base[1], physical[1]);
	allocate(aperture, 1 * B_PAGE_SIZE, 0, B_APERTURE_NEED_PHYSICAL, base[2], physical[2]);
	sGART->deallocate_memory(aperture, base[2]);
	allocate(aperture, 1 * B_PAGE_SIZE, 4 * B_PAGE_SIZE, 0, base[2], physical[2]);

	sGART->deallocate_memory(aperture, base[1]);

	allocate(aperture, 5 * B_PAGE_SIZE, 0, 0, base[1], physical[1]);

	sGART->deallocate_memory(aperture, base[2]);
	sGART->deallocate_memory(aperture, base[0]);
	if (sGART->deallocate_memory(aperture, 0x12345) == B_OK)
		debugger("Non-allocated succeeded to be freed!\n");

	void *buffer = memalign(3 * B_PAGE_SIZE, B_PAGE_SIZE);
	status_t status = sGART->bind_aperture(aperture, -1, (addr_t)buffer,
		3 * B_PAGE_SIZE, 0, false, 0, &base[3]);
	if (status < B_OK)
		printf("binding memory failed: %s\n", strerror(status));

	allocate(aperture, 25 * B_PAGE_SIZE, 0, 0, base[0], physical[0]);
		// will fail
	allocate(aperture, 4 * B_PAGE_SIZE, 0, 0, base[0], physical[0]);

	void *address;
	area_id area = create_area("test", &address, B_ANY_ADDRESS, 2 * B_PAGE_SIZE,
		B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
	printf("Area %ld, address %p\n", area, address);
	status = sGART->bind_aperture(aperture, area, 0, 0, 0, false, 0, &base[4]);
	if (status < B_OK)
		printf("binding area failed: %s\n", strerror(status));

	sGART->unbind_aperture(aperture, base[3]);
	sGART->unbind_aperture(aperture, base[4]);
//	sGART->deallocate_memory(aperture, base[0]);

	free(buffer);
	delete_area(area);

	sGART->unmap_aperture(aperture);
}
Beispiel #20
0
int
main(int argc, char *argv[])
{
	if (argc != 3) {
		printf("%s [size (MB)] [count]\n", argv[0]);
		return 0;
	}

	uint32 size = atoi(argv[1]) * MEGABYTE;
	uint32 count = atoi(argv[2]);

	printf("Creating and using memory that is %d MB, %d times...\n",
		size / MEGABYTE, count);

	int i = 0;
	for (i = 0; i < count; i++) {
		srand(time(NULL));
		int32 random = (rand() % 16) + 1;
		int32 randomBlock = (B_PAGE_SIZE * random) + random;

		printf("Round %d: Creating.. ", i);
		void* location = NULL;
		#ifdef USE_AREA
		area_id area = create_area("Test Memory", &location, B_ANY_ADDRESS, size,
			B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
		#else
		location = (void*)malloc(size);
		void* mallocLocation = location;
		#endif

		if (!location) {
			printf("FAIL!\n");
			continue;
		}
		printf("Created(%016p).. ", location);

		printf("Exercising.. ");
		addr_t pos = 0;
		while (pos < size - randomBlock) {
			uint32 data = randomBlock / random;
			memset(location, data, randomBlock);
			location += randomBlock;
			pos += randomBlock;
		}
		printf("Erasing.. ");
		#ifdef USE_AREA
		delete_area(area);
		#else
		free(mallocLocation);
		#endif
		printf("OK!\n");
	}

	return 0;
}
static status_t
InitDevice(DeviceInfo& di)
{
	// Perform initialization and mapping of the device, and return B_OK if
	// sucessful;  else, return error code.

	// Create the area for shared info with NO user-space read or write
	// permissions, to prevent accidental damage.

	TRACE("enter InitDevice()\n");

	pci_info& pciInfo = di.pciInfo;
	char sharedName[B_OS_NAME_LENGTH];

	sprintf(sharedName, DEVICE_FORMAT " shared",
		pciInfo.vendor_id, pciInfo.device_id,
		pciInfo.bus, pciInfo.device, pciInfo.function);

	di.sharedArea = create_area(sharedName, (void**) &(di.sharedInfo),
		B_ANY_KERNEL_ADDRESS,
		((sizeof(SharedInfo) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1)),
		B_FULL_LOCK, 0);
	if (di.sharedArea < 0)
		return di.sharedArea;	// return error code

	SharedInfo& si = *(di.sharedInfo);

	si.vendorID = pciInfo.vendor_id;
	si.deviceID = pciInfo.device_id;
	si.revision = pciInfo.revision;
	si.chipType = di.pChipInfo->chipType;
	strcpy(si.chipName, di.pChipInfo->chipName);

	// Trio64 and Trio64V+ chips have the same ID but different revision numbers.
	// Since the Trio64V+ supports MMIO, better performance can be obtained
	// from it if it is distinguished from the Trio64.

	if (si.chipType == S3_TRIO64 && si.revision & 0x40) {
		si.chipType = S3_TRIO64_VP;
		strcpy(si.chipName, "Trio64 V+");
	}

	status_t status = MapDevice(di);
	if (status < 0) {
		delete_area(di.sharedArea);
		di.sharedArea = -1;
		di.sharedInfo = NULL;
		return status;		// return error code
	}

	InitInterruptHandler(di);

	TRACE("Interrupt assigned:  %s\n", si.bInterruptAssigned ? "yes" : "no");
	return B_OK;
}
Beispiel #22
0
// Create
BlockAllocator::Area *
BlockAllocator::Area::Create(size_t size)
{
	Area *area = NULL;
	void *base = NULL;
#if USER
	area_id id = create_area("block alloc", &base, B_ANY_ADDRESS,
							 size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
#else
	area_id id = create_area("block alloc", &base, B_ANY_KERNEL_ADDRESS,
							 size, B_FULL_LOCK, B_READ_AREA | B_WRITE_AREA);
#endif
	if (id >= 0) {
		area = new(base) Area(id, size);
	} else {
		ERROR(("BlockAllocator::Area::Create(%lu): Failed to create area: %s\n",
			size, strerror(id)));
	}
	return area;
}
Beispiel #23
0
void Storage::read( ConfigFile& cf )
{
    static int num_until_dot = 1000;
    unsigned long nobjects = 0;

    StorageArea *area = NULL;
    ConfigElem elem;

    clock_t start = clock();

    while (cf.read( elem ))
    {
        if (--num_until_dot == 0)
        {
            cout << ".";
            num_until_dot = 1000;
        }
        if (elem.type_is( "StorageArea" ))
        {
            area = create_area( elem );
        }
        else if (elem.type_is("Item"))
        {
            if (area != NULL)
            {
                try 
                {
                    area->load_item( elem );
                }
                catch( std::exception& )
                {
                    if (!config.ignore_load_errors)
                        throw;
                }
            }
            else
            {
                cerr << "Storage: Got an ITEM element, but don't have a StorageArea to put it." << endl;
                throw runtime_error( "Data file integrity error" );
            }
        }
        else
        {
            cerr << "Unexpected element type " << elem.type() << " in storage file." << endl;
            throw runtime_error( "Data file integrity error" );
        }
		++nobjects;
    }

	clock_t end = clock();
	long ms = static_cast<long>((end-start) * 1000.0 / CLOCKS_PER_SEC);

	cout << " " << nobjects << " elements in " << ms << " ms." << std::endl;
}
Beispiel #24
0
area_data *fread_smaugfuss_area( FILE * fp )
{
   area_data *tarea = nullptr;

   for( ;; )
   {
      char letter;
      const char *word;

      letter = fread_letter( fp );
      if( letter == '*' )
      {
         fread_to_eol( fp );
         continue;
      }

      if( letter != '#' )
      {
         bug( "%s: # not found. Invalid format.", __func__ );
         if( fBootDb )
            exit( 1 );
         break;
      }

      word = ( feof( fp ) ? "ENDAREA" : fread_word( fp ) );

      if( word[0] == '\0' )
      {
         bug( "%s: EOF encountered reading file!", __func__ );
         word = "ENDAREA";
      }

      if( !str_cmp( word, "AREADATA" ) )
      {
         tarea = create_area(  );
         tarea->filename = str_dup( strArea );
         fread_fuss_areadata( fp, tarea );
      }
      else if( !str_cmp( word, "MOBILE" ) )
         fread_fuss_mobile( fp, tarea );
      else if( !str_cmp( word, "OBJECT" ) )
         fread_fuss_object( fp, tarea );
      else if( !str_cmp( word, "ROOM" ) )
         fread_fuss_room( fp, tarea );
      else if( !str_cmp( word, "ENDAREA" ) )
         break;
      else
      {
         bug( "%s: Bad section header: %s", __func__, word );
         fread_to_eol( fp );
      }
   }
   return tarea;
}
Beispiel #25
0
BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
	uint32 lock)
{
	CALLED();
	fInitError = _Init();
	if (fInitError != B_OK)
		return;

	// This one is easy. We need to create "count" BBuffers,
	// each one "size" bytes large. They all go into one
	// area, with "placement" and "lock" attributes.
	// The BBuffers created will clone the area, and
	// then we delete our area. This way BBuffers are
	// independent from the BBufferGroup

	// don't allow all placement parameter values
	if (placement != B_ANY_ADDRESS && placement != B_ANY_KERNEL_ADDRESS) {
		ERROR("BBufferGroup: placement != B_ANY_ADDRESS "
			"&& placement != B_ANY_KERNEL_ADDRESS (0x%#" B_PRIx32 ")\n",
			placement);
		placement = B_ANY_ADDRESS;
	}

	// first we roundup for a better placement in memory
	size_t allocSize = (size + 63) & ~63;

	// now we create the area
	size_t areaSize
		= ((allocSize * count) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);

	void* startAddress;
	area_id bufferArea = create_area("some buffers area", &startAddress,
		placement, areaSize, lock, B_READ_AREA | B_WRITE_AREA);
	if (bufferArea < 0) {
		ERROR("BBufferGroup: failed to allocate %ld bytes area\n", areaSize);
		fInitError = (status_t)bufferArea;
		return;
	}

	buffer_clone_info info;

	for (int32 i = 0; i < count; i++) {
		info.area = bufferArea;
		info.offset = i * allocSize;
		info.size = size;

		fInitError = AddBuffer(info);
		if (fInitError != B_OK)
			break;
	}

	delete_area(bufferArea);
}
Beispiel #26
0
/*!	Creates the initial mode list of the primary accelerant.
	It's called from intel_init_accelerant().
*/
status_t
create_mode_list(void)
{
	i2c_bus bus;
	bus.cookie = (void*)INTEL_I2C_IO_A;
	bus.set_signals = &set_i2c_signals;
	bus.get_signals = &get_i2c_signals;
	ddc2_init_timing(&bus);

	if (ddc2_read_edid1(&bus, &gInfo->edid_info, NULL, NULL) == B_OK) {
		edid_dump(&gInfo->edid_info);
		gInfo->has_edid = true;
	} else {
		TRACE(("intel_extreme: getting EDID failed!\n"));
	}

	// TODO: support lower modes via scaling and windowing
	if (gInfo->head_mode & HEAD_MODE_LVDS_PANEL
		&& ((gInfo->head_mode & HEAD_MODE_A_ANALOG) == 0)) {
		size_t size = (sizeof(display_mode) + B_PAGE_SIZE - 1)
			& ~(B_PAGE_SIZE - 1);

		display_mode *list;
		area_id area = create_area("intel extreme modes", (void **)&list,
			B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
		if (area < B_OK)
			return area;

		memcpy(list, &gInfo->lvds_panel_mode, sizeof(display_mode));

		gInfo->mode_list_area = area;
		gInfo->mode_list = list;
		gInfo->shared_info->mode_list_area = gInfo->mode_list_area;
		gInfo->shared_info->mode_count = 1;
		return B_OK;
	}

	// Otherwise return the 'real' list of modes
	display_mode *list;
	uint32 count = 0;
	gInfo->mode_list_area = create_display_modes("intel extreme modes",
		gInfo->has_edid ? &gInfo->edid_info : NULL, NULL, 0, NULL, 0, NULL,
		&list, &count);
	if (gInfo->mode_list_area < B_OK)
		return gInfo->mode_list_area;

	gInfo->mode_list = list;
	gInfo->shared_info->mode_list_area = gInfo->mode_list_area;
	gInfo->shared_info->mode_count = count;

	return B_OK;
}
Beispiel #27
0
static void *beosAlloc( const int size )
	{ 
	void *memPtr = NULL; 
	area_id areaID; 

	areaID = create_area( "memory_block", &memPtr, B_ANY_ADDRESS,
						  roundUp( size + MEM_INFO_HEADERSIZE, B_PAGE_SIZE ),
						  B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA );
	if( areaID < B_NO_ERROR )
		return( NULL );

	return( memPtr );
	}
Beispiel #28
0
            /**
             * Assemble an area from the given way.
             * The resulting area is put into the out_buffer.
             *
             * @returns false if there was some kind of error building the
             *          area, true otherwise.
             */
            bool operator()(const osmium::Way& way, osmium::memory::Buffer& out_buffer) {
                if (!config().create_way_polygons) {
                    return true;
                }

                if (config().problem_reporter) {
                    config().problem_reporter->set_object(osmium::item_type::way, way.id());
                    config().problem_reporter->set_nodes(way.nodes().size());
                }

                // Ignore (but count) ways without segments.
                if (way.nodes().size() < 2) {
                    ++stats().short_ways;
                    return false;
                }

                if (!way.ends_have_same_id()) {
                    ++stats().duplicate_nodes;
                    if (config().problem_reporter) {
                        config().problem_reporter->report_duplicate_node(way.nodes().front().ref(), way.nodes().back().ref(), way.nodes().front().location());
                    }
                }

                ++stats().from_ways;
                stats().invalid_locations = segment_list().extract_segments_from_way(config().problem_reporter,
                                                                                     stats().duplicate_nodes,
                                                                                     way);
                if (!config().ignore_invalid_locations && stats().invalid_locations > 0) {
                    return false;
                }

                if (config().debug_level > 0) {
                    std::cerr << "\nAssembling way " << way.id() << " containing " << segment_list().size() << " nodes\n";
                }

                // Now create the Area object and add the attributes and tags
                // from the way.
                const bool okay = create_area(out_buffer, way);
                if (okay) {
                    out_buffer.commit();
                } else {
                    out_buffer.rollback();
                }

                if (debug()) {
                    std::cerr << "Done: " << stats() << "\n";
                }

                return okay;
            }
Beispiel #29
0
static status_t
CreateShared()
{
	gPd->sharedArea = create_area("VMware shared", (void **)&gPd->si,
		B_ANY_KERNEL_ADDRESS, ROUND_TO_PAGE_SIZE(sizeof(SharedInfo)),
		B_FULL_LOCK, 0);
	if (gPd->sharedArea < B_OK) {
		TRACE("failed to create shared area\n");
		return gPd->sharedArea;
	}
	TRACE("shared area created\n");

	memset(gPd->si, 0, sizeof(SharedInfo));
	return B_OK;
}
Beispiel #30
0
status_t
rtm_create_pool(rtm_pool** _pool, size_t totalSize, const char* name)
{
	rtm_pool* pool = (rtm_pool*)malloc(sizeof(rtm_pool));
	if (pool == NULL)
		return B_NO_MEMORY;

	if (name == NULL)
		name = "realtime pool";

	status_t status = mutex_init(&pool->lock, name);
	if (status != B_OK) {
		free(pool);
		return status;
	}

	// Allocate enough space for at least one allocation over \a totalSize
	pool->max_size = (totalSize + sizeof(FreeChunk) - 1 + B_PAGE_SIZE)
		& ~(B_PAGE_SIZE - 1);

	area_id area = create_area(name, &pool->heap_base, B_ANY_ADDRESS,
		pool->max_size, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
	if (area < 0) {
		mutex_destroy(&pool->lock);
		free(pool);
		return area;
	}

	pool->area = area;
	pool->available = pool->max_size - FreeChunk::NextOffset();

	// declare the whole heap as one chunk, and add it
	// to the free list

	FreeChunk* chunk = (FreeChunk*)pool->heap_base;
	chunk->SetTo(pool->max_size, NULL);

	pool->free_anchor.SetTo(0, chunk);

	*_pool = pool;

	static pthread_once_t sOnce = PTHREAD_ONCE_INIT;
	pthread_once(&sOnce, &pool_init);

	MutexLocker _(&sPoolsLock);
	sPools.Add(pool);
	return B_OK;
}