/* Firmware mailbox standard timeout */ #define IVTV_API_STD_TIMEOUT 0x02000000
#define API_CACHE (1 << 0) /* Allow the command to be stored in the cache */ #define API_RESULT (1 << 1) /* Allow 1 second for this cmd to end */ #define API_FAST_RESULT (3 << 1) /* Allow 0.1 second for this cmd to end */ #define API_DMA (1 << 3) /* DMA mailbox, has special handling */ #define API_HIGH_VOL (1 << 5) /* High volume command (i.e. called during encoding or decoding) */ #define API_NO_WAIT_MB (1 << 4) /* Command may not wait for a free mailbox */ #define API_NO_WAIT_RES (1 << 5) /* Command may not wait for the result */ #define API_NO_POLL (1 << 6) /* Avoid pointless polling */
struct ivtv_api_info { int flags; /* Flags, see above */ constchar *name; /* The name of the command */
};
/* if the mailbox is free, then try to claim it */ if (is_free && !test_and_set_bit(mb, &mbdata->busy)) {
write_sync(IVTV_MBOX_DRIVER_BUSY, &mbdata->mbox[mb].flags); return 1;
} return 0;
}
/* Try to find a free mailbox. Note mailbox 0 is reserved for DMA and so is not
attempted here. */ staticint get_mailbox(struct ivtv *itv, struct ivtv_mailbox_data *mbdata, int flags)
{ unsignedlong then = jiffies; int i, mb; int max_mbox = mbdata->max_mbox; int retries = 100;
/* All slow commands use the same mailbox, serializing them and also
leaving the other mailbox free for simple fast commands. */ if ((flags & API_FAST_RESULT) == API_RESULT)
max_mbox = 1;
/* find free non-DMA mailbox */ for (i = 0; i < retries; i++) { for (mb = 1; mb <= max_mbox; mb++) if (try_mailbox(itv, mbdata, mb)) return mb;
/* Sleep before a retry, if not atomic */ if (!(flags & API_NO_WAIT_MB)) { if (time_after(jiffies,
then + msecs_to_jiffies(10*retries))) break;
ivtv_msleep_timeout(10, 0);
}
} return -ENODEV;
}
staticvoid write_mailbox(volatilestruct ivtv_mailbox __iomem *mbox, int cmd, int args, u32 data[])
{ int i;
/* clear possibly uninitialized part of data array */ for (i = args; i < CX2341X_MBOX_MAX_DATA; i++)
data[i] = 0;
/* If this command was issued within the last 30 minutes and with identical data, then just return 0 as there is no need to issue this command again.
Just an optimization to prevent unnecessary use of mailboxes. */ if (itv->api_cache[cmd].last_jiffies &&
time_before(jiffies,
itv->api_cache[cmd].last_jiffies +
msecs_to_jiffies(1800000)) &&
!memcmp(data, itv->api_cache[cmd].data, sizeof(itv->api_cache[cmd].data))) {
itv->api_cache[cmd].last_jiffies = jiffies; return 0;
}
flags = api_info[cmd].flags;
if (flags & API_DMA) { for (i = 0; i < 100; i++) {
mb = i % (mbdata->max_mbox + 1); if (try_mailbox(itv, mbdata, mb)) {
write_mailbox(&mbdata->mbox[mb], cmd, args, data);
clear_bit(mb, &mbdata->busy); return 0;
}
IVTV_DEBUG_WARN("%s: mailbox %d not free %08x\n",
api_info[cmd].name, mb, readl(&mbdata->mbox[mb].flags));
}
IVTV_WARN("Could not find free DMA mailbox for %s\n", api_info[cmd].name);
clear_all_mailboxes(itv, mbdata); return -EBUSY;
}
if ((flags & API_FAST_RESULT) == API_FAST_RESULT)
api_timeout = msecs_to_jiffies(100);
if (!(flags & API_NO_POLL)) { /* First try to poll, then switch to delays */ for (i = 0; i < 100; i++) { if (readl(&mbox->flags) & IVTV_MBOX_FIRMWARE_DONE) break;
}
} while (!(readl(&mbox->flags) & IVTV_MBOX_FIRMWARE_DONE)) { if (time_after(jiffies, then + api_timeout)) {
IVTV_DEBUG_WARN("Could not get result (%s)\n", api_info[cmd].name); /* reset the mailbox, but it is likely too late already */
write_sync(0, &mbox->flags);
clear_bit(mb, &mbdata->busy); return -EIO;
} if (flags & API_NO_WAIT_RES)
mdelay(1); else
ivtv_msleep_timeout(1, 0);
} if (time_after(jiffies, then + msecs_to_jiffies(100)))
IVTV_DEBUG_WARN("%s took %u jiffies\n",
api_info[cmd].name,
jiffies_to_msecs(jiffies - then));
for (i = 0; i < CX2341X_MBOX_MAX_DATA; i++)
data[i] = readl(&mbox->data[i]);
write_sync(0, &mbox->flags);
clear_bit(mb, &mbdata->busy); return 0;
}
int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[])
{ int res = ivtv_api_call(itv, cmd, args, data);
/* Allow a single retry, probably already too late though. If there is no free mailbox then that is usually an indication
of a more serious problem. */ return (res == -EBUSY) ? ivtv_api_call(itv, cmd, args, data) : res;
}
int ivtv_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA])
{ return ivtv_api(priv, cmd, in, data);
}
int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...)
{
va_list ap; int i;
va_start(ap, args); for (i = 0; i < args; i++) {
data[i] = va_arg(ap, u32);
}
va_end(ap); return ivtv_api(itv, cmd, args, data);
}
int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...)
{
u32 data[CX2341X_MBOX_MAX_DATA];
va_list ap; int i;
va_start(ap, args); for (i = 0; i < args; i++) {
data[i] = va_arg(ap, u32);
}
va_end(ap); return ivtv_api(itv, cmd, args, data);
}
/* This one is for stuff that can't sleep.. irq handlers, etc.. */ void ivtv_api_get_data(struct ivtv_mailbox_data *mbdata, int mb, int argc, u32 data[])
{ volatile u32 __iomem *p = mbdata->mbox[mb].data; int i; for (i = 0; i < argc; i++, p++)
data[i] = readl(p);
}
/* Wipe api cache */ void ivtv_mailbox_cache_invalidate(struct ivtv *itv)
{ int i; for (i = 0; i < 256; i++)
itv->api_cache[i].last_jiffies = 0;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
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.