xref: /haiku/src/add-ons/accelerants/intel_extreme/memory.cpp (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 /*
2  * Copyright 2006-2008, 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 base)
28 {
29 	if (base == 0)
30 		return;
31 
32 	intel_free_graphics_memory freeMemory;
33 	freeMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
34 	freeMemory.buffer_base = base;
35 
36 	ioctl(gInfo->device, INTEL_FREE_GRAPHICS_MEMORY, &freeMemory,
37 		sizeof(freeMemory));
38 }
39 
40 
41 status_t
42 intel_allocate_memory(size_t size, uint32 flags, uint32 &base)
43 {
44 	intel_allocate_graphics_memory allocMemory;
45 	allocMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
46 	allocMemory.size = size;
47 	allocMemory.alignment = 0;
48 	allocMemory.flags = flags;
49 
50 	if (ioctl(gInfo->device, INTEL_ALLOCATE_GRAPHICS_MEMORY, &allocMemory,
51 			sizeof(allocMemory)) < 0)
52 		return errno;
53 
54 	base = allocMemory.buffer_base;
55 	return B_OK;
56 }
57 
58