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#ifndef AREA_KEEPER_H
9#define AREA_KEEPER_H
10
11
12#include <KernelExport.h>
13#include <OS.h>
14
15#include <util/kernel_cpp.h>
16
17
18class AreaKeeper {
19	public:
20		AreaKeeper();
21		~AreaKeeper();
22
23		area_id Create(const char *name, void **_virtualAddress, uint32 spec,
24			size_t size, uint32 lock, uint32 protection);
25		area_id Map(const char *name, phys_addr_t physicalAddress,
26			size_t numBytes, uint32 spec, uint32 protection,
27			void **_virtualAddress);
28
29		status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; }
30		void Detach();
31
32	private:
33		area_id	fArea;
34};
35
36
37AreaKeeper::AreaKeeper()
38	:
39	fArea(-1)
40{
41}
42
43
44AreaKeeper::~AreaKeeper()
45{
46	if (fArea >= B_OK)
47		delete_area(fArea);
48}
49
50
51area_id
52AreaKeeper::Create(const char *name, void **_virtualAddress, uint32 spec,
53	size_t size, uint32 lock, uint32 protection)
54{
55	fArea = create_area(name, _virtualAddress, spec, size, lock, protection);
56	return fArea;
57}
58
59
60area_id
61AreaKeeper::Map(const char *name, phys_addr_t physicalAddress, size_t numBytes,
62	uint32 spec, uint32 protection, void **_virtualAddress)
63{
64	fArea = map_physical_memory(name, physicalAddress, numBytes, spec,
65		protection, _virtualAddress);
66	return fArea;
67}
68
69
70void
71AreaKeeper::Detach()
72{
73	fArea = -1;
74}
75
76#endif	// AREA_KEEPER_H
77