162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef SOUND_FIREWIRE_ISO_RESOURCES_H_INCLUDED
362306a36Sopenharmony_ci#define SOUND_FIREWIRE_ISO_RESOURCES_H_INCLUDED
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/mutex.h>
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistruct fw_unit;
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/**
1162306a36Sopenharmony_ci * struct fw_iso_resources - manages channel/bandwidth allocation
1262306a36Sopenharmony_ci * @channels_mask: if the device does not support all channel numbers, set this
1362306a36Sopenharmony_ci *                 bit mask to something else than the default (all ones)
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * This structure manages (de)allocation of isochronous resources (channel and
1662306a36Sopenharmony_ci * bandwidth) for one isochronous stream.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_cistruct fw_iso_resources {
1962306a36Sopenharmony_ci	u64 channels_mask;
2062306a36Sopenharmony_ci	/* private: */
2162306a36Sopenharmony_ci	struct fw_unit *unit;
2262306a36Sopenharmony_ci	struct mutex mutex;
2362306a36Sopenharmony_ci	unsigned int channel;
2462306a36Sopenharmony_ci	unsigned int bandwidth; /* in bandwidth units, without overhead */
2562306a36Sopenharmony_ci	unsigned int bandwidth_overhead;
2662306a36Sopenharmony_ci	int generation; /* in which allocation is valid */
2762306a36Sopenharmony_ci	bool allocated;
2862306a36Sopenharmony_ci};
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciint fw_iso_resources_init(struct fw_iso_resources *r,
3162306a36Sopenharmony_ci			  struct fw_unit *unit);
3262306a36Sopenharmony_civoid fw_iso_resources_destroy(struct fw_iso_resources *r);
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciint fw_iso_resources_allocate(struct fw_iso_resources *r,
3562306a36Sopenharmony_ci			      unsigned int max_payload_bytes, int speed);
3662306a36Sopenharmony_ciint fw_iso_resources_update(struct fw_iso_resources *r);
3762306a36Sopenharmony_civoid fw_iso_resources_free(struct fw_iso_resources *r);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#endif
40