Cleanup, turned off debug output.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12651 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-05-12 23:29:28 +00:00
parent 6efe4e121f
commit 90a0e0b9d9
+58 -52
View File
@@ -42,7 +42,7 @@
#include <string.h> #include <string.h>
#define TRACE_IO_RESOURCES //#define TRACE_IO_RESOURCES
#ifdef TRACE_IO_RESOURCES #ifdef TRACE_IO_RESOURCES
# define TRACE(x) dprintf x # define TRACE(x) dprintf x
#else #else
@@ -58,7 +58,7 @@ static void unregister_colliding_node_range(io_resource_info *list,
io_resource_info *resource); io_resource_info *resource);
// validate I/O resource data /** validate I/O resource data */
static status_t static status_t
validate_io_resource(io_resource *src) validate_io_resource(io_resource *src)
@@ -85,12 +85,12 @@ validate_io_resource(io_resource *src)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
TRACE(("success!\n")); TRACE((" success!\n"));
return B_OK; return B_OK;
} }
// allocate info structure for I/O resources /** Allocate info structure for I/O resources */
static status_t static status_t
alloc_io_resource_info(io_resource *src, io_resource_info **dest_out) alloc_io_resource_info(io_resource *src, io_resource_info **dest_out)
@@ -114,9 +114,10 @@ alloc_io_resource_info(io_resource *src, io_resource_info **dest_out)
} }
// acquire I/O range; /** Acquire I/O range; returns B_WOULD_BLOCK on collision with
// returns B_WOULD_BLOCK on collision with temporary allocation * temporary allocation.
// node_lock must be hold * gNodeLock must be held
*/
static status_t static status_t
acquire_range(io_resource_info **list, io_resource_info *resource) acquire_range(io_resource_info **list, io_resource_info *resource)
@@ -134,11 +135,11 @@ acquire_range(io_resource_info **list, io_resource_info *resource)
&& cur->resource.base + length - 1 <= base + length - 1) { && cur->resource.base + length - 1 <= base + length - 1) {
device_node_info *owner = cur->owner; device_node_info *owner = cur->owner;
TRACE(("collision\n")); TRACE((" collision\n"));
if (owner == NULL) { if (owner == NULL) {
// collision with temporary allocation - block ourself // collision with temporary allocation - block ourself
TRACE(("collision with temporary allocation - retry later\n")); TRACE((" collision with temporary allocation - retry later\n"));
res = B_WOULD_BLOCK; res = B_WOULD_BLOCK;
break; break;
@@ -147,13 +148,13 @@ acquire_range(io_resource_info **list, io_resource_info *resource)
if (owner->loading + owner->load_count > 0) { if (owner->loading + owner->load_count > 0) {
// driver is already loaded - give up // driver is already loaded - give up
// (driver may get loaded forever) // (driver may get loaded forever)
TRACE(("collision with loaded driver - giving up\n")); TRACE((" collision with loaded driver - giving up\n"));
res = B_BUSY; res = B_BUSY;
break; break;
} else { } else {
// driver is not loaded - block loading // driver is not loaded - block loading
TRACE(("collision with unloaded driver - block driver %p\n", owner)); TRACE((" collision with unloaded driver - block driver %p\n", owner));
++owner->load_block_count; ++owner->load_block_count;
} }
@@ -163,7 +164,7 @@ acquire_range(io_resource_info **list, io_resource_info *resource)
if (cur != NULL) { if (cur != NULL) {
// collided with someone // collided with someone
TRACE(("Resource collision\n")); TRACE((" Resource collision\n"));
release_range(list, resource, cur); release_range(list, resource, cur);
return res; return res;
@@ -175,7 +176,7 @@ acquire_range(io_resource_info **list, io_resource_info *resource)
} }
// free I/O resource info /** Free I/O resource info */
static void static void
free_io_resource_info(io_resource_info *resource) free_io_resource_info(io_resource_info *resource)
@@ -191,7 +192,7 @@ free_io_resource_info(io_resource_info *resource)
* appropriate resource list (i.e. mem/port/channel) plus * appropriate resource list (i.e. mem/port/channel) plus
* all colliding resources (including ours) are marked blocked; * all colliding resources (including ours) are marked blocked;
* returns B_WOULD_BLOCK on collision with temporary allocation; * returns B_WOULD_BLOCK on collision with temporary allocation;
* gNodeLock must be hold. * gNodeLock must be held.
*/ */
static status_t static status_t
@@ -229,19 +230,20 @@ acquire_io_resource(io_resource *src, io_resource_handle *dest_out)
*dest_out = dest; *dest_out = dest;
TRACE(("done\n")); TRACE((" done\n"));
return B_OK; return B_OK;
err: err:
free_io_resource_info(dest); free_io_resource_info(dest);
TRACE(("failed: %s\n", strerror(res))); TRACE((" failed: %s\n", strerror(res)));
return res; return res;
} }
// release I/O resource /** Release I/O resource.
// node_lock must be hold * gNodeLock must be held
*/
static void static void
release_io_resource(io_resource_info *resource) release_io_resource(io_resource_info *resource)
@@ -264,11 +266,12 @@ release_io_resource(io_resource_info *resource)
} }
// release I/O range, which can be I/O memory, ports and ISA DMA channels /** Release I/O range, which can be I/O memory, ports and ISA DMA channels
// up_to - up to but not including colliding range to be released * up_to - up to but not including colliding range to be released
// (NULL for normal release, not-NULL if used during failed allocation) * (NULL for normal release, not-NULL if used during failed allocation)
// blocked users get notified; * blocked users get notified;
// node_lock must be hold * gNodeLock must be held
*/
static void static void
release_range(io_resource_info **list, io_resource_info *resource, io_resource_info *up_to) release_range(io_resource_info **list, io_resource_info *resource, io_resource_info *up_to)
@@ -288,11 +291,11 @@ release_range(io_resource_info **list, io_resource_info *resource, io_resource_i
if (cur->resource.base >= base && cur->resource.base + length - 1 <= base + length - 1) { if (cur->resource.base >= base && cur->resource.base + length - 1 <= base + length - 1) {
device_node_info *owner = cur->owner; device_node_info *owner = cur->owner;
TRACE(("unblock\n")); TRACE((" unblock\n"));
if (owner != NULL) { if (owner != NULL) {
// collision with driver - unblock it // collision with driver - unblock it
TRACE(("collision with driver - unblock driver %p\n", owner)); TRACE((" collision with driver - unblock driver %p\n", owner));
pnp_unblock_load(owner); pnp_unblock_load(owner);
} }
@@ -309,13 +312,16 @@ release_range(io_resource_info **list, io_resource_info *resource, io_resource_i
} }
// wait until someone freed some resource or /** Wait until someone freed some resource or
// allocated some resource permanently; * allocated some resource permanently.
// node_lock must be hold * gNodeLock must be held.
*/
static void static void
wait_for_resources(void) wait_for_resources(void)
{ {
TRACE(("wait_for_resources()\n"));
++pnp_resource_wait_count; ++pnp_resource_wait_count;
// we have to release while waiting // we have to release while waiting
@@ -323,15 +329,14 @@ wait_for_resources(void)
acquire_sem(pnp_resource_wait_sem); acquire_sem(pnp_resource_wait_sem);
TRACE(("retrying resource allocation"));
benaphore_unlock(&gNodeLock); benaphore_unlock(&gNodeLock);
} }
// try to acquire list of resources. /** Try to acquire list of resources.
// returns B_WOULD_BLOCK on collision with temporary allocation * returns B_WOULD_BLOCK on collision with temporary allocation.
// node_lock must be hold * gNodeLock must be held.
*/
static status_t static status_t
try_acquire_io_resources(io_resource *resources, io_resource_handle *handles) try_acquire_io_resources(io_resource *resources, io_resource_handle *handles)
@@ -363,11 +368,12 @@ err:
} }
// acquire I/O resources. /** Acquire I/O resources.
// node_lock must be hold * gNodeLock must be held.
*/
static static status_t
status_t acquire_io_resources(io_resource *resources, io_resource_handle *handles) acquire_io_resources(io_resource *resources, io_resource_handle *handles)
{ {
// try allocation until we either got all resources or // try allocation until we either got all resources or
// detected a collision with a loaded device node // detected a collision with a loaded device node
@@ -386,14 +392,14 @@ status_t acquire_io_resources(io_resource *resources, io_resource_handle *handle
wait_for_resources(); wait_for_resources();
} else { } else {
// collided with loaded node - no point waiting for the node // collided with loaded node - no point waiting for the node
TRACE(("Giving up because collision with loaded device node\n")); TRACE(("acquire_io_resouces(): Collision with loaded device node\n"));
return res; return res;
} }
} }
} }
// unregister devices that collide with one of our I/O resources /** Unregister devices that collide with one of our I/O resources */
static void static void
unregister_colliding_nodes(const io_resource_handle *resources) unregister_colliding_nodes(const io_resource_handle *resources)
@@ -416,7 +422,7 @@ unregister_colliding_nodes(const io_resource_handle *resources)
} }
/** unregister device nodes that collide with I/O resource */ /** Unregister device nodes that collide with I/O resource */
static void static void
unregister_colliding_node_range(io_resource_info *list, io_resource_info *resource) unregister_colliding_node_range(io_resource_info *list, io_resource_info *resource)
@@ -439,7 +445,7 @@ unregister_colliding_node_range(io_resource_info *list, io_resource_info *resour
if (owner == NULL) if (owner == NULL)
panic("Transfer of I/O resources from temporary to device node collided with other temporary allocation"); panic("Transfer of I/O resources from temporary to device node collided with other temporary allocation");
TRACE(("Deleting colliding node %p\n", owner)); TRACE(("Deleting colliding device node %p\n", owner));
// make sure node still exists after we'll have released lock // make sure node still exists after we'll have released lock
++owner->ref_count; ++owner->ref_count;
@@ -462,8 +468,8 @@ unregister_colliding_node_range(io_resource_info *list, io_resource_info *resour
} }
/** unblock other temporary allocations so they can retry /** Unblock other temporary allocations so they can retry.
* gNodeLock must be hold * gNodeLock must be held.
*/ */
static void static void
@@ -481,8 +487,8 @@ unblock_temporary_allocation(void)
// #pragma mark - // #pragma mark -
/** transfer temporary I/O resources to device node; /** Transfer temporary I/O resources to device node;
* colliding devices are unregistered * colliding devices are unregistered.
*/ */
void void
@@ -513,9 +519,9 @@ dm_assign_io_resources(device_node_info *node, const io_resource_handle *resourc
} }
/** release I/O resources of a device node and set list to NULL; /** Release I/O resources of a device node and set list to NULL;
* users previously blocked by our resource alloction are notified; * users previously blocked by our resource alloction are notified;
* gNodeLock must be hold * gNodeLock must be held.
*/ */
void void
@@ -546,17 +552,17 @@ dm_release_node_resources(device_node_info *node)
status_t status_t
dm_acquire_io_resources(io_resource *resources, io_resource_handle *handles) dm_acquire_io_resources(io_resource *resources, io_resource_handle *handles)
{ {
status_t res; status_t status;
TRACE(("pnp_acquire_io_resources()\n")); TRACE(("dm_acquire_io_resources()\n"));
benaphore_lock(&gNodeLock); benaphore_lock(&gNodeLock);
res = acquire_io_resources(resources, handles); status = acquire_io_resources(resources, handles);
benaphore_unlock(&gNodeLock); benaphore_unlock(&gNodeLock);
TRACE(("done (%s)", strerror(res))); TRACE((" done (%s)", strerror(status)));
return res; return status;
} }