// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved. * * @File ctresource.c * * @Brief * This file contains the implementation of some generic helper functions. * * @Author Liu Chun * @Date May 15 2008
*/
/* Resource allocation based on bit-map management mechanism */ staticint
get_resource(u8 *rscs, unsignedint amount, unsignedint multi, unsignedint *ridx)
{ int i, j, k, n;
/* Check whether there are sufficient resources to meet request. */ for (i = 0, n = multi; i < amount; i++) {
j = i / 8;
k = i % 8; if (rscs[j] & ((u8)1 << k)) {
n = multi; continue;
} if (!(--n)) break; /* found sufficient contiguous resources */
}
if (i >= amount) { /* Can not find sufficient contiguous resources */ return -ENOENT;
}
/* Mark the contiguous bits in resource bit-map as used */ for (n = multi; n > 0; n--) {
j = i / 8;
k = i % 8;
rscs[j] |= ((u8)1 << k);
i--;
}
/* Mark the contiguous bits in resource bit-map as used */ for (n = multi, i = idx; n > 0; n--) {
j = i / 8;
k = i % 8;
rscs[j] &= ~((u8)1 << k);
i++;
}
return 0;
}
int mgr_get_resource(struct rsc_mgr *mgr, unsignedint n, unsignedint *ridx)
{ int err;
if (n > mgr->avail) return -ENOENT;
err = get_resource(mgr->rscs, mgr->amount, n, ridx); if (!err)
mgr->avail -= n;
return err;
}
int mgr_put_resource(struct rsc_mgr *mgr, unsignedint n, unsignedint idx)
{
put_resource(mgr->rscs, n, idx);
mgr->avail += n;
return 0;
}
staticconstunsignedchar offset_in_audio_slot_block[NUM_RSCTYP] = { /* SRC channel is at Audio Ring slot 1 every 16 slots. */
[SRC] = 0x1,
[AMIXER] = 0x4,
[SUM] = 0xc,
};
switch (type) { case SRC:
err = hw->src_rsc_get_ctrl_blk(&rsc->ctrl_blk); break; case AMIXER:
err = hw->amixer_rsc_get_ctrl_blk(&rsc->ctrl_blk); break; case SRCIMP: case SUM: case DAIO: break; default:
dev_err(((struct hw *)hw)->card->dev, "Invalid resource type value %d!\n", type); return -EINVAL;
}
if (err) {
dev_err(((struct hw *)hw)->card->dev, "Failed to get resource control block!\n"); return err;
}
return 0;
}
int rsc_uninit(struct rsc *rsc)
{ if ((NULL != rsc->hw) && (NULL != rsc->ctrl_blk)) { switch (rsc->type) { case SRC:
rsc->hw->src_rsc_put_ctrl_blk(rsc->ctrl_blk); break; case AMIXER:
rsc->hw->amixer_rsc_put_ctrl_blk(rsc->ctrl_blk); break; case SUM: case DAIO: break; default:
dev_err(((struct hw *)rsc->hw)->card->dev, "Invalid resource type value %d!\n",
rsc->type); break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.