2 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2002-2004, Thomas Kurschel. All rights reserved.
5 * Distributed under the terms of the MIT License.
9 #include "io_resources.h"
15 //#define TRACE_IO_RESOURCES
16 #ifdef TRACE_IO_RESOURCES
17 # define TRACE(x) dprintf x
23 typedef DoublyLinkedList
<io_resource_private
,
24 DoublyLinkedListMemberGetLink
<io_resource_private
,
25 &io_resource_private::fTypeLink
> > ResourceTypeList
;
28 static ResourceTypeList sMemoryList
;
29 static ResourceTypeList sPortList
;
30 static ResourceTypeList sDMAChannelList
;
33 io_resource_private::io_resource_private()
39 io_resource_private::~io_resource_private()
46 io_resource_private::_Init()
55 io_resource_private::Acquire(const io_resource
& resource
)
57 if (!_IsValid(resource
))
63 if (type
!= B_ISA_DMA_CHANNEL
)
64 length
= resource
.length
;
68 ResourceTypeList
* list
= NULL
;
77 case B_ISA_DMA_CHANNEL
:
78 list
= &sDMAChannelList
;
82 ResourceTypeList::Iterator iterator
= list
->GetIterator();
83 while (iterator
.HasNext()) {
84 io_resource
* resource
= iterator
.Next();
86 // we need the "base + length - 1" trick to avoid wrap around at 4 GB
87 if (resource
->base
>= base
88 && resource
->base
+ length
- 1 <= base
+ length
- 1) {
89 // This range is already covered by someone else
90 // TODO: we might want to ignore resources that belong to
91 // a node that isn't used.
93 return B_RESOURCE_UNAVAILABLE
;
103 io_resource_private::Release()
110 sMemoryList
.Remove(this);
113 sPortList
.Remove(this);
115 case B_ISA_DMA_CHANNEL
:
116 sDMAChannelList
.Remove(this);
125 io_resource_private::_IsValid(const io_resource
& resource
)
127 switch (resource
.type
) {
129 return resource
.base
+ resource
.length
> resource
.base
;
131 return (uint16
)resource
.base
== resource
.base
132 && (uint16
)resource
.length
== resource
.length
133 && resource
.base
+ resource
.length
> resource
.base
;
134 case B_ISA_DMA_CHANNEL
:
135 return resource
.base
<= 8;
147 dm_init_io_resources(void)
149 new(&sMemoryList
) ResourceTypeList
;
150 new(&sPortList
) ResourceTypeList
;
151 new(&sDMAChannelList
) ResourceTypeList
;