Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/bhnd/bhndb/bhndb_private.h
Show All 27 Lines | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#ifndef _BHND_BHNDB_PRIVATE_H_ | #ifndef _BHND_BHNDB_PRIVATE_H_ | ||||
#define _BHND_BHNDB_PRIVATE_H_ | #define _BHND_BHNDB_PRIVATE_H_ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/bitstring.h> | |||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <machine/resource.h> | #include <machine/resource.h> | ||||
#include "bhndbvar.h" | #include "bhndbvar.h" | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | struct bhndb_resources { | ||||
struct rman ht_mem_rman; /**< host memory manager */ | struct rman ht_mem_rman; /**< host memory manager */ | ||||
struct rman br_mem_rman; /**< bridged memory manager */ | struct rman br_mem_rman; /**< bridged memory manager */ | ||||
STAILQ_HEAD(, bhndb_region) bus_regions; /**< bus region descriptors */ | STAILQ_HEAD(, bhndb_region) bus_regions; /**< bus region descriptors */ | ||||
struct bhndb_dw_alloc *dw_alloc; /**< dynamic window allocation records */ | struct bhndb_dw_alloc *dw_alloc; /**< dynamic window allocation records */ | ||||
size_t dwa_count; /**< number of dynamic windows available. */ | size_t dwa_count; /**< number of dynamic windows available. */ | ||||
uint32_t dwa_freelist; /**< dynamic window free list */ | bitstr_t *dwa_freelist; /**< dynamic window free list */ | ||||
bhndb_priority_t min_prio; /**< minimum resource priority required to | bhndb_priority_t min_prio; /**< minimum resource priority required to | ||||
allocate a dynamic window */ | allocate a dynamic window */ | ||||
}; | }; | ||||
/** | /** | ||||
* Returns true if the all dynamic windows have been exhausted, false | * Returns true if the all dynamic windows are marked free, false | ||||
* otherwise. | * otherwise. | ||||
* | * | ||||
* @param br The resource state to check. | * @param br The resource state to check. | ||||
*/ | */ | ||||
static inline bool | static inline bool | ||||
bhndb_dw_exhausted(struct bhndb_resources *br) | bhndb_dw_all_free(struct bhndb_resources *br) | ||||
{ | { | ||||
return (br->dwa_freelist == 0); | int bit; | ||||
bit_ffs(br->dwa_freelist, br->dwa_count, &bit); | |||||
return (bit == -1); | |||||
} | } | ||||
/** | /** | ||||
* Find the next free dynamic window region in @p br. | * Find the next free dynamic window region in @p br. | ||||
* | * | ||||
* @param br The resource state to search. | * @param br The resource state to search. | ||||
*/ | */ | ||||
static inline struct bhndb_dw_alloc * | static inline struct bhndb_dw_alloc * | ||||
bhndb_dw_next_free(struct bhndb_resources *br) | bhndb_dw_next_free(struct bhndb_resources *br) | ||||
{ | { | ||||
struct bhndb_dw_alloc *dw_free; | struct bhndb_dw_alloc *dw_free; | ||||
int bit; | |||||
if (bhndb_dw_exhausted(br)) | bit_ffc(br->dwa_freelist, br->dwa_count, &bit); | ||||
if (bit == -1) | |||||
return (NULL); | return (NULL); | ||||
dw_free = &br->dw_alloc[__builtin_ctz(br->dwa_freelist)]; | dw_free = &br->dw_alloc[bit]; | ||||
KASSERT(LIST_EMPTY(&dw_free->refs), | KASSERT(LIST_EMPTY(&dw_free->refs), | ||||
("free list out of sync with refs")); | ("free list out of sync with refs")); | ||||
return (dw_free); | return (dw_free); | ||||
} | } | ||||
/** | /** | ||||
* Returns true if a dynamic window allocation is marked as free. | * Returns true if a dynamic window allocation is marked as free. | ||||
* | * | ||||
* @param br The resource state owning @p dwa. | * @param br The resource state owning @p dwa. | ||||
* @param dwa The dynamic window allocation record to be checked. | * @param dwa The dynamic window allocation record to be checked. | ||||
*/ | */ | ||||
static inline bool | static inline bool | ||||
bhndb_dw_is_free(struct bhndb_resources *br, struct bhndb_dw_alloc *dwa) | bhndb_dw_is_free(struct bhndb_resources *br, struct bhndb_dw_alloc *dwa) | ||||
{ | { | ||||
bool is_free = LIST_EMPTY(&dwa->refs); | bool is_free = LIST_EMPTY(&dwa->refs); | ||||
KASSERT(is_free == ((br->dwa_freelist & (1 << dwa->rnid)) != 0), | KASSERT(is_free == !bit_test(br->dwa_freelist, dwa->rnid), | ||||
("refs out of sync with free list")); | ("refs out of sync with free list")); | ||||
return (is_free); | return (is_free); | ||||
} | } | ||||
#define BHNDB_LOCK_INIT(sc) \ | #define BHNDB_LOCK_INIT(sc) \ | ||||
mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->dev), \ | mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->dev), \ | ||||
"bhndb resource allocator lock", MTX_DEF) | "bhndb resource allocator lock", MTX_DEF) | ||||
#define BHNDB_LOCK(sc) mtx_lock(&(sc)->sc_mtx) | #define BHNDB_LOCK(sc) mtx_lock(&(sc)->sc_mtx) | ||||
#define BHNDB_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) | #define BHNDB_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) | ||||
#define BHNDB_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->sc_mtx, what) | #define BHNDB_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->sc_mtx, what) | ||||
#define BHNDB_LOCK_DESTROY(sc) mtx_destroy(&(sc)->sc_mtx) | #define BHNDB_LOCK_DESTROY(sc) mtx_destroy(&(sc)->sc_mtx) | ||||
#endif /* _BHND_BHNDB_PRIVATE_H_ */ | #endif /* _BHND_BHNDB_PRIVATE_H_ */ |