From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
2.1 KiB
C
79 lines
2.1 KiB
C
#include "dma.h"
|
|
|
|
static int backend_valid(const struct dma_backend *backend)
|
|
{
|
|
if (backend == NULL) {
|
|
return 0;
|
|
}
|
|
if (backend->streaming == NULL || backend->coherent == NULL) {
|
|
return 0;
|
|
}
|
|
if (backend->restore == NULL) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int device_valid(const struct dma_device *device)
|
|
{
|
|
if (device == NULL || device->bound != 1) {
|
|
return 0;
|
|
}
|
|
if (!backend_valid(&device->backend)) {
|
|
return 0;
|
|
}
|
|
if (device->streaming_bits > 64 || device->coherent_bits > 64) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int dma_device_bind(struct dma_device *device, const struct dma_backend *backend,
|
|
unsigned streaming_bits, unsigned coherent_bits)
|
|
{
|
|
struct dma_device fresh;
|
|
if (device == NULL || !backend_valid(backend)) {
|
|
return DMA_EINVAL;
|
|
}
|
|
if (streaming_bits > 64 || coherent_bits > 64) {
|
|
return DMA_EINVAL;
|
|
}
|
|
fresh.backend = *backend;
|
|
fresh.streaming_bits = streaming_bits;
|
|
fresh.coherent_bits = coherent_bits;
|
|
fresh.bound = 1;
|
|
*device = fresh;
|
|
return DMA_OK;
|
|
}
|
|
|
|
int dma_device_state(const struct dma_device *device, unsigned *streaming_bits,
|
|
unsigned *coherent_bits)
|
|
{
|
|
if (!device_valid(device) || streaming_bits == NULL || coherent_bits == NULL) {
|
|
return DMA_EINVAL;
|
|
}
|
|
*streaming_bits = device->streaming_bits;
|
|
*coherent_bits = device->coherent_bits;
|
|
return DMA_OK;
|
|
}
|
|
|
|
int dma_device_pair(struct dma_device *device, unsigned bits)
|
|
{
|
|
struct dma_device saved;
|
|
dma_set_fn operations[2];
|
|
unsigned channel;
|
|
if (!device_valid(device) || bits < 1 || bits > 64) return DMA_EINVAL;
|
|
saved = *device;
|
|
operations[0] = saved.backend.streaming;
|
|
operations[1] = saved.backend.coherent;
|
|
for (channel = 0; channel < 2; channel++) {
|
|
int rc = operations[channel](saved.backend.context,bits);
|
|
if (rc) {
|
|
saved.backend.restore(saved.backend.context,saved.streaming_bits,saved.coherent_bits);
|
|
return rc;
|
|
}
|
|
}
|
|
device->streaming_bits = device->coherent_bits = bits;
|
|
return 0;
|
|
}
|