subr_bus.c (78e253c8d5e3e2bd2ead8fabe1c730493343a9e4) subr_bus.c (36fed96550cc5e0c7c87d0c69eb5beccf1d2d77f)
1/*-
2 * Copyright (c) 1997,1998,2003 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 2448 unchanged lines hidden (view full) ---

2457/**
2458 * @brief Initialise a resource list.
2459 *
2460 * @param rl the resource list to initialise
2461 */
2462void
2463resource_list_init(struct resource_list *rl)
2464{
1/*-
2 * Copyright (c) 1997,1998,2003 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 2448 unchanged lines hidden (view full) ---

2457/**
2458 * @brief Initialise a resource list.
2459 *
2460 * @param rl the resource list to initialise
2461 */
2462void
2463resource_list_init(struct resource_list *rl)
2464{
2465 SLIST_INIT(rl);
2465 STAILQ_INIT(rl);
2466}
2467
2468/**
2469 * @brief Reclaim memory used by a resource list.
2470 *
2471 * This function frees the memory for all resource entries on the list
2472 * (if any).
2473 *
2474 * @param rl the resource list to free
2475 */
2476void
2477resource_list_free(struct resource_list *rl)
2478{
2479 struct resource_list_entry *rle;
2480
2466}
2467
2468/**
2469 * @brief Reclaim memory used by a resource list.
2470 *
2471 * This function frees the memory for all resource entries on the list
2472 * (if any).
2473 *
2474 * @param rl the resource list to free
2475 */
2476void
2477resource_list_free(struct resource_list *rl)
2478{
2479 struct resource_list_entry *rle;
2480
2481 while ((rle = SLIST_FIRST(rl)) != NULL) {
2481 while ((rle = STAILQ_FIRST(rl)) != NULL) {
2482 if (rle->res)
2483 panic("resource_list_free: resource entry is busy");
2482 if (rle->res)
2483 panic("resource_list_free: resource entry is busy");
2484 SLIST_REMOVE_HEAD(rl, link);
2484 STAILQ_REMOVE_HEAD(rl, link);
2485 free(rle, M_BUS);
2486 }
2487}
2488
2489/**
2490 * @brief Add a resource entry.
2491 *
2492 * This function adds a resource entry using the given @p type, @p

--- 41 unchanged lines hidden (view full) ---

2534 struct resource_list_entry *rle;
2535
2536 rle = resource_list_find(rl, type, rid);
2537 if (!rle) {
2538 rle = malloc(sizeof(struct resource_list_entry), M_BUS,
2539 M_NOWAIT);
2540 if (!rle)
2541 panic("resource_list_add: can't record entry");
2485 free(rle, M_BUS);
2486 }
2487}
2488
2489/**
2490 * @brief Add a resource entry.
2491 *
2492 * This function adds a resource entry using the given @p type, @p

--- 41 unchanged lines hidden (view full) ---

2534 struct resource_list_entry *rle;
2535
2536 rle = resource_list_find(rl, type, rid);
2537 if (!rle) {
2538 rle = malloc(sizeof(struct resource_list_entry), M_BUS,
2539 M_NOWAIT);
2540 if (!rle)
2541 panic("resource_list_add: can't record entry");
2542 SLIST_INSERT_HEAD(rl, rle, link);
2542 STAILQ_INSERT_TAIL(rl, rle, link);
2543 rle->type = type;
2544 rle->rid = rid;
2545 rle->res = NULL;
2546 }
2547
2548 if (rle->res)
2549 panic("resource_list_add: resource entry is busy");
2550

--- 12 unchanged lines hidden (view full) ---

2563 * @returns the resource entry pointer or NULL if there is no such
2564 * entry.
2565 */
2566struct resource_list_entry *
2567resource_list_find(struct resource_list *rl, int type, int rid)
2568{
2569 struct resource_list_entry *rle;
2570
2543 rle->type = type;
2544 rle->rid = rid;
2545 rle->res = NULL;
2546 }
2547
2548 if (rle->res)
2549 panic("resource_list_add: resource entry is busy");
2550

--- 12 unchanged lines hidden (view full) ---

2563 * @returns the resource entry pointer or NULL if there is no such
2564 * entry.
2565 */
2566struct resource_list_entry *
2567resource_list_find(struct resource_list *rl, int type, int rid)
2568{
2569 struct resource_list_entry *rle;
2570
2571 SLIST_FOREACH(rle, rl, link) {
2571 STAILQ_FOREACH(rle, rl, link) {
2572 if (rle->type == type && rle->rid == rid)
2573 return (rle);
2574 }
2575 return (NULL);
2576}
2577
2578/**
2579 * @brief Delete a resource entry.

--- 5 unchanged lines hidden (view full) ---

2585void
2586resource_list_delete(struct resource_list *rl, int type, int rid)
2587{
2588 struct resource_list_entry *rle = resource_list_find(rl, type, rid);
2589
2590 if (rle) {
2591 if (rle->res != NULL)
2592 panic("resource_list_delete: resource has not been released");
2572 if (rle->type == type && rle->rid == rid)
2573 return (rle);
2574 }
2575 return (NULL);
2576}
2577
2578/**
2579 * @brief Delete a resource entry.

--- 5 unchanged lines hidden (view full) ---

2585void
2586resource_list_delete(struct resource_list *rl, int type, int rid)
2587{
2588 struct resource_list_entry *rle = resource_list_find(rl, type, rid);
2589
2590 if (rle) {
2591 if (rle->res != NULL)
2592 panic("resource_list_delete: resource has not been released");
2593 SLIST_REMOVE(rl, rle, resource_list_entry, link);
2593 STAILQ_REMOVE(rl, rle, resource_list_entry, link);
2594 free(rle, M_BUS);
2595 }
2596}
2597
2598/**
2599 * @brief Helper function for implementing BUS_ALLOC_RESOURCE()
2600 *
2601 * Implement BUS_ALLOC_RESOURCE() by looking up a resource from the list

--- 134 unchanged lines hidden (view full) ---

2736 const char *format)
2737{
2738 struct resource_list_entry *rle;
2739 int printed, retval;
2740
2741 printed = 0;
2742 retval = 0;
2743 /* Yes, this is kinda cheating */
2594 free(rle, M_BUS);
2595 }
2596}
2597
2598/**
2599 * @brief Helper function for implementing BUS_ALLOC_RESOURCE()
2600 *
2601 * Implement BUS_ALLOC_RESOURCE() by looking up a resource from the list

--- 134 unchanged lines hidden (view full) ---

2736 const char *format)
2737{
2738 struct resource_list_entry *rle;
2739 int printed, retval;
2740
2741 printed = 0;
2742 retval = 0;
2743 /* Yes, this is kinda cheating */
2744 SLIST_FOREACH(rle, rl, link) {
2744 STAILQ_FOREACH(rle, rl, link) {
2745 if (rle->type == type) {
2746 if (printed == 0)
2747 retval += printf(" %s ", name);
2748 else
2749 retval += printf(",");
2750 printed++;
2751 retval += printf(format, rle->start);
2752 if (rle->count > 1) {

--- 1277 unchanged lines hidden ---
2745 if (rle->type == type) {
2746 if (printed == 0)
2747 retval += printf(" %s ", name);
2748 else
2749 retval += printf(",");
2750 printed++;
2751 retval += printf(format, rle->start);
2752 if (rle->count > 1) {

--- 1277 unchanged lines hidden ---