/* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright 2024 Google LLC * * dbitmap - dynamically sized bitmap library. * * Used by the binder driver to optimize the allocation of the smallest * available descriptor ID. Each bit in the bitmap represents the state * of an ID, with the exception of BIT(0) which is used exclusively to * reference binder's context manager. * * A dbitmap can grow or shrink as needed. This part has been designed * considering that users might need to briefly release their locks in * order to allocate memory for the new bitmap. These operations then, * are verified to determine if the grow or shrink is sill valid. * * This library does not provide protection against concurrent access * by itself. Binder uses the proc->outer_lock for this purpose. */ #ifndef _LINUX_DBITMAP_H #define _LINUX_DBITMAP_H #include <linux/bitmap.h> #define NBITS_MIN … struct dbitmap { … }; static inline int dbitmap_enabled(struct dbitmap *dmap) { … } static inline void dbitmap_free(struct dbitmap *dmap) { … } /* Returns the nbits that a dbitmap can shrink to, 0 if not possible. */ static inline unsigned int dbitmap_shrink_nbits(struct dbitmap *dmap) { … } /* Replace the internal bitmap with a new one of different size */ static inline void dbitmap_replace(struct dbitmap *dmap, unsigned long *new, unsigned int nbits) { … } static inline void dbitmap_shrink(struct dbitmap *dmap, unsigned long *new, unsigned int nbits) { … } /* Returns the nbits that a dbitmap can grow to. */ static inline unsigned int dbitmap_grow_nbits(struct dbitmap *dmap) { … } static inline void dbitmap_grow(struct dbitmap *dmap, unsigned long *new, unsigned int nbits) { … } /* * Finds and sets the first zero bit in the bitmap. Upon success @bit * is populated with the index and 0 is returned. Otherwise, -ENOSPC * is returned to indicate that a dbitmap_grow() is needed. */ static inline int dbitmap_acquire_first_zero_bit(struct dbitmap *dmap, unsigned long *bit) { … } static inline void dbitmap_clear_bit(struct dbitmap *dmap, unsigned long bit) { … } static inline int dbitmap_init(struct dbitmap *dmap) { … } #endif