/* Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.  */
u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
/* Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.  */
u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
{
	u16 set, free_bit;
	for (set = 0; set < res->sets; set++) {
		free_bit = find_first_zero_bit(res->desc[set].res_map,
					       res->desc[set].num);
		if (free_bit != res->desc[set].num) {
			set_bit(free_bit, res->desc[set].res_map);
			return res->desc[set].start + free_bit;
		}
	}
	return TI_SCI_RESOURCE_NULL;
}