1a90ebd77SClemens Zeidler/*
2a90ebd77SClemens Zeidler * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3a90ebd77SClemens Zeidler * Distributed under the terms of the MIT License.
4a90ebd77SClemens Zeidler *
5a90ebd77SClemens Zeidler * Authors:
6a90ebd77SClemens Zeidler *		Axel D��rfler, axeld@pinc-software.de
7a90ebd77SClemens Zeidler */
8a90ebd77SClemens Zeidler#ifndef AREA_KEEPER_H
9a90ebd77SClemens Zeidler#define AREA_KEEPER_H
10a90ebd77SClemens Zeidler
11a90ebd77SClemens Zeidler
12a90ebd77SClemens Zeidler#include <KernelExport.h>
13a90ebd77SClemens Zeidler#include <OS.h>
14a90ebd77SClemens Zeidler
15a90ebd77SClemens Zeidler#include <util/kernel_cpp.h>
16a90ebd77SClemens Zeidler
17a90ebd77SClemens Zeidler
18a90ebd77SClemens Zeidlerclass AreaKeeper {
19a90ebd77SClemens Zeidler	public:
20a90ebd77SClemens Zeidler		AreaKeeper();
21a90ebd77SClemens Zeidler		~AreaKeeper();
22a90ebd77SClemens Zeidler
23a90ebd77SClemens Zeidler		area_id Create(const char *name, void **_virtualAddress, uint32 spec,
24a90ebd77SClemens Zeidler			size_t size, uint32 lock, uint32 protection);
25c162f52eSJérôme Duval		area_id Map(const char *name, addr_t physicalAddress, size_t numBytes,
26a90ebd77SClemens Zeidler			uint32 spec, uint32 protection, void **_virtualAddress);
27a90ebd77SClemens Zeidler
28a90ebd77SClemens Zeidler		status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; }
29a90ebd77SClemens Zeidler		void Detach();
30a90ebd77SClemens Zeidler
31a90ebd77SClemens Zeidler	private:
32a90ebd77SClemens Zeidler		area_id	fArea;
33a90ebd77SClemens Zeidler};
34a90ebd77SClemens Zeidler
35a90ebd77SClemens Zeidler
36a90ebd77SClemens ZeidlerAreaKeeper::AreaKeeper()
37a90ebd77SClemens Zeidler	:
38a90ebd77SClemens Zeidler	fArea(-1)
39a90ebd77SClemens Zeidler{
40a90ebd77SClemens Zeidler}
41a90ebd77SClemens Zeidler
42a90ebd77SClemens Zeidler
43a90ebd77SClemens ZeidlerAreaKeeper::~AreaKeeper()
44a90ebd77SClemens Zeidler{
45a90ebd77SClemens Zeidler	if (fArea >= B_OK)
46a90ebd77SClemens Zeidler		delete_area(fArea);
47a90ebd77SClemens Zeidler}
48a90ebd77SClemens Zeidler
49a90ebd77SClemens Zeidler
50a90ebd77SClemens Zeidlerarea_id
51a90ebd77SClemens ZeidlerAreaKeeper::Create(const char *name, void **_virtualAddress, uint32 spec,
52a90ebd77SClemens Zeidler	size_t size, uint32 lock, uint32 protection)
53a90ebd77SClemens Zeidler{
54a90ebd77SClemens Zeidler	fArea = create_area(name, _virtualAddress, spec, size, lock, protection);
55a90ebd77SClemens Zeidler	return fArea;
56a90ebd77SClemens Zeidler}
57a90ebd77SClemens Zeidler
58a90ebd77SClemens Zeidler
59a90ebd77SClemens Zeidlerarea_id
60c162f52eSJérôme DuvalAreaKeeper::Map(const char *name, addr_t physicalAddress, size_t numBytes,
61a90ebd77SClemens Zeidler	uint32 spec, uint32 protection, void **_virtualAddress)
62a90ebd77SClemens Zeidler{
63c162f52eSJérôme Duval	fArea = map_physical_memory(name, physicalAddress, numBytes, spec,
6464d79effSIngo Weinhold		protection, _virtualAddress);
65a90ebd77SClemens Zeidler	return fArea;
66a90ebd77SClemens Zeidler}
67a90ebd77SClemens Zeidler
68a90ebd77SClemens Zeidler
69a90ebd77SClemens Zeidlervoid
70a90ebd77SClemens ZeidlerAreaKeeper::Detach()
71a90ebd77SClemens Zeidler{
72a90ebd77SClemens Zeidler	fArea = -1;
73a90ebd77SClemens Zeidler}
74a90ebd77SClemens Zeidler
75a90ebd77SClemens Zeidler#endif	// AREA_KEEPER_H
76