xref: /haiku/src/add-ons/accelerants/intel_extreme/memory.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 
9 
10 #include "accelerant.h"
11 #include "intel_extreme.h"
12 
13 #include <errno.h>
14 #include <unistd.h>
15 
16 
17 //#define TRACE_MEMORY
18 #ifdef TRACE_MEMORY
19 extern "C" void _sPrintf(const char *format, ...);
20 #	define TRACE(x) _sPrintf x
21 #else
22 #	define TRACE(x) ;
23 #endif
24 
25 
26 void
27 intel_free_memory(uint32 handle)
28 {
29 	if (!handle)
30 		return;
31 
32 	intel_free_graphics_memory freeMemory;
33 	freeMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
34 	freeMemory.handle = handle;
35 
36 	ioctl(gInfo->device, INTEL_FREE_GRAPHICS_MEMORY, &freeMemory, sizeof(freeMemory));
37 }
38 
39 
40 status_t
41 intel_allocate_memory(size_t size, uint32& handle, uint32& offset)
42 {
43 	intel_allocate_graphics_memory allocMemory;
44 	allocMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
45 	allocMemory.size = size;
46 
47 	if (ioctl(gInfo->device, INTEL_ALLOCATE_GRAPHICS_MEMORY, &allocMemory, sizeof(allocMemory)) < 0)
48 		return errno;
49 
50 	handle = allocMemory.handle;
51 	offset = allocMemory.buffer_offset;
52 
53 	return B_OK;
54 }
55 
56