/* * MAGIC_SIZE must always be the greatest common divisor of * AEWB_PACKET_SIZE and AF_PAXEL_SIZE.
*/ #define MAGIC_SIZE 16 #define MAGIC_NUM 0x55
/* HACK: AF module seems to be writing one more paxel data than it should. */ #define AF_EXTRA_DATA OMAP3ISP_AF_PAXEL_SIZE
/* * HACK: H3A modules go to an invalid state after have a SBL overflow. It makes * the next buffer to start to be written in the same point where the overflow * occurred instead of the configured address. The only known way to make it to * go back to a valid state is having a valid buffer processing. Of course it * requires at least a doubled buffer size to avoid an access to invalid memory * region. But it does not fix everything. It may happen more than one * consecutive SBL overflows. In that case, it might be unpredictable how many * buffers the allocated memory should fit. For that case, a recover * configuration was created. It produces the minimum buffer size for each H3A * module and decrease the change for more SBL overflows. This recover state * will be enabled every time a SBL overflow occur. As the output buffer size * isn't big, it's possible to have an extra size able to fit many recover * buffers making it extreamily unlikely to have an access to invalid memory * region.
*/ #define NUM_H3A_RECOVER_BUFS 10
/* * HACK: Because of HW issues the generic layer sometimes need to have * different behaviour for different statistic modules.
*/ #define IS_H3A_AF(stat) ((stat) == &(stat)->isp->isp_af) #define IS_H3A_AEWB(stat) ((stat) == &(stat)->isp->isp_aewb) #define IS_H3A(stat) (IS_H3A_AF(stat) || IS_H3A_AEWB(stat))
/* Checking initial magic numbers. They shouldn't be here anymore. */ for (w = buf->virt_addr, end = w + MAGIC_SIZE; w < end; w++) if (likely(*w != MAGIC_NUM))
ret = 0;
if (ret) {
dev_dbg(stat->isp->dev, "%s: beginning magic check does not match.\n",
stat->subdev.name); return ret;
}
/* Checking magic numbers at the end. They must be still here. */ for (w = buf->virt_addr + buf_size, end = w + MAGIC_SIZE;
w < end; w++) { if (unlikely(*w != MAGIC_NUM)) {
dev_dbg(stat->isp->dev, "%s: ending magic check does not match.\n",
stat->subdev.name); return -EINVAL;
}
}
/* * Inserting MAGIC_NUM at the beginning and end of the buffer. * buf->buf_size is set only after the buffer is queued. For now the * right buf_size for the current configuration is pointed by * stat->buf_size.
*/
memset(buf->virt_addr, MAGIC_NUM, MAGIC_SIZE);
memset(buf->virt_addr + buf_size, MAGIC_NUM, MAGIC_SIZE);
staticvoid isp_stat_buf_clear(struct ispstat *stat)
{ int i;
for (i = 0; i < STAT_MAX_BUFS; i++)
stat->buf[i].empty = 1;
}
staticstruct ispstat_buffer *
__isp_stat_buf_find(struct ispstat *stat, int look_empty)
{ struct ispstat_buffer *found = NULL; int i;
for (i = 0; i < STAT_MAX_BUFS; i++) { struct ispstat_buffer *curr = &stat->buf[i];
/* * Don't select the buffer which is being copied to * userspace or used by the module.
*/ if (curr == stat->locked_buf || curr == stat->active_buf) continue;
/* Don't select uninitialised buffers if it's not required */ if (!look_empty && curr->empty) continue;
/* Pick uninitialised buffer over anything else if look_empty */ if (curr->empty) {
found = curr; break;
}
/* Choose the oldest buffer */ if (!found ||
(s32)curr->frame_number - (s32)found->frame_number < 0)
found = curr;
}
/* Get next free buffer to write the statistics to and mark it active. */ staticvoid isp_stat_buf_next(struct ispstat *stat)
{ if (unlikely(stat->active_buf)) /* Overwriting unused active buffer */
dev_dbg(stat->isp->dev, "%s: new buffer requested without queuing active one.\n",
stat->subdev.name); else
stat->active_buf = isp_stat_buf_find_oldest_or_empty(stat);
}
/* * The device passed to the DMA API depends on whether the statistics block uses * ISP DMA, external DMA or PIO to transfer data. * * The first case (for the AEWB and AF engines) passes the ISP device, resulting * in the DMA buffers being mapped through the ISP IOMMU. * * The second case (for the histogram engine) should pass the DMA engine device. * As that device isn't accessible through the OMAP DMA engine API the driver * passes NULL instead, resulting in the buffers being mapped directly as * physical pages. * * The third case (for the histogram engine) doesn't require any mapping. The * buffers could be allocated with kmalloc/vmalloc, but we still use * dma_alloc_coherent() for consistency purpose.
*/ staticint isp_stat_bufs_alloc(struct ispstat *stat, u32 size)
{ struct device *dev = ISP_STAT_USES_DMAENGINE(stat)
? NULL : stat->isp->dev; unsignedlong flags; unsignedint i;
spin_lock_irqsave(&stat->isp->stat_lock, flags);
BUG_ON(stat->locked_buf != NULL);
/* Are the old buffers big enough? */ if (stat->buf_alloc_size >= size) {
spin_unlock_irqrestore(&stat->isp->stat_lock, flags); return 0;
}
if (stat->state != ISPSTAT_DISABLED || stat->buf_processing) {
dev_info(stat->isp->dev, "%s: trying to allocate memory when busy\n",
stat->subdev.name);
spin_unlock_irqrestore(&stat->isp->stat_lock, flags); return -EBUSY;
}
/* * omap3isp_stat_config - Receives new statistic engine configuration. * @new_conf: Pointer to config structure. * * Returns 0 if successful, -EINVAL if new_conf pointer is NULL, -ENOMEM if * was unable to allocate memory for the buffer, or other errors if parameters * are invalid.
*/ int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
{ int ret; unsignedlong irqflags; struct ispstat_generic_config *user_cfg = new_conf;
u32 buf_size = user_cfg->buf_size;
mutex_lock(&stat->ioctl_lock);
dev_dbg(stat->isp->dev, "%s: configuring module with buffer size=0x%08lx\n",
stat->subdev.name, (unsignedlong)buf_size);
ret = stat->ops->validate_params(stat, new_conf); if (ret) {
mutex_unlock(&stat->ioctl_lock);
dev_dbg(stat->isp->dev, "%s: configuration values are invalid.\n",
stat->subdev.name); return ret;
}
if (buf_size != user_cfg->buf_size)
dev_dbg(stat->isp->dev, "%s: driver has corrected buffer size request to 0x%08lx\n",
stat->subdev.name,
(unsignedlong)user_cfg->buf_size);
/* * Hack: H3A modules may need a doubled buffer size to avoid access * to a invalid memory address after a SBL overflow. * The buffer size is always PAGE_ALIGNED. * Hack 2: MAGIC_SIZE is added to buf_size so a magic word can be * inserted at the end to data integrity check purpose. * Hack 3: AF module writes one paxel data more than it should, so * the buffer allocation must consider it to avoid invalid memory * access. * Hack 4: H3A need to allocate extra space for the recover state.
*/ if (IS_H3A(stat)) {
buf_size = user_cfg->buf_size * 2 + MAGIC_SIZE; if (IS_H3A_AF(stat)) /* * Adding one extra paxel data size for each recover * buffer + 2 regular ones.
*/
buf_size += AF_EXTRA_DATA * (NUM_H3A_RECOVER_BUFS + 2); if (stat->recover_priv) { struct ispstat_generic_config *recover_cfg =
stat->recover_priv;
buf_size += recover_cfg->buf_size *
NUM_H3A_RECOVER_BUFS;
}
buf_size = PAGE_ALIGN(buf_size);
} else { /* Histogram */
buf_size = PAGE_ALIGN(user_cfg->buf_size + MAGIC_SIZE);
}
ret = isp_stat_bufs_alloc(stat, buf_size); if (ret) {
mutex_unlock(&stat->ioctl_lock); return ret;
}
/* * Returning the right future config_counter for this setup, so * userspace can *know* when it has been applied.
*/
user_cfg->config_counter = stat->config_counter + stat->inc_config;
/* Module has a valid configuration. */
stat->configured = 1;
dev_dbg(stat->isp->dev, "%s: module has been successfully configured.\n",
stat->subdev.name);
mutex_unlock(&stat->ioctl_lock);
return 0;
}
/* * isp_stat_buf_process - Process statistic buffers. * @buf_state: points out if buffer is ready to be processed. It's necessary * because histogram needs to copy the data from internal memory * before be able to process the buffer.
*/ staticint isp_stat_buf_process(struct ispstat *stat, int buf_state)
{ int ret = STAT_NO_BUF;
if (!atomic_add_unless(&stat->buf_err, -1, 0) &&
buf_state == STAT_BUF_DONE && stat->state == ISPSTAT_ENABLED) {
ret = isp_stat_buf_queue(stat);
isp_stat_buf_next(stat);
}
return ret;
}
int omap3isp_stat_pcr_busy(struct ispstat *stat)
{ return stat->ops->busy(stat);
}
/* * isp_stat_pcr_enable - Disables/Enables statistic engines. * @pcr_enable: 0/1 - Disables/Enables the engine. * * Must be called from ISP driver when the module is idle and synchronized * with CCDC.
*/ staticvoid isp_stat_pcr_enable(struct ispstat *stat, u8 pcr_enable)
{ if ((stat->state != ISPSTAT_ENABLING &&
stat->state != ISPSTAT_ENABLED) && pcr_enable) /* Userspace has disabled the module. Aborting. */ return;
void omap3isp_stat_resume(struct ispstat *stat)
{ /* Module will be re-enabled with its pipeline */ if (stat->state == ISPSTAT_SUSPENDED)
stat->state = ISPSTAT_ENABLING;
}
if (stat->priv == NULL) /* driver wasn't initialised */ return;
spin_lock_irqsave(&stat->isp->stat_lock, irqflags); if (stat->state == ISPSTAT_ENABLING && !stat->buf_processing &&
stat->buf_alloc_size) { /* * Userspace's requested to enable the engine but it wasn't yet. * Let's do that now.
*/
stat->update = 1;
isp_stat_buf_next(stat);
stat->ops->setup_regs(stat, stat->priv);
isp_stat_buf_insert_magic(stat, stat->active_buf);
/* * H3A module has some hw issues which forces the driver to * ignore next buffers even if it was disabled in the meantime. * On the other hand, Histogram shouldn't ignore buffers anymore * if it's being enabled.
*/ if (!IS_H3A(stat))
atomic_set(&stat->buf_err, 0);
spin_lock_irqsave(&stat->isp->stat_lock, irqflags); /* * Due to a H3A hw issue which prevents the next buffer to start from * the correct memory address, 2 buffers must be ignored.
*/
atomic_set(&stat->buf_err, 2);
/* * If more than one SBL overflow happen in a row, H3A module may access * invalid memory region. * stat->sbl_ovl_recover is set to tell to the driver to temporarily use * a soft configuration which helps to avoid consecutive overflows.
*/ if (stat->recover_priv)
stat->sbl_ovl_recover = 1;
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
}
/* * omap3isp_stat_enable - Disable/Enable statistic engine as soon as possible * @enable: 0/1 - Disables/Enables the engine. * * Client should configure all the module registers before this. * This function can be called from a userspace request.
*/ int omap3isp_stat_enable(struct ispstat *stat, u8 enable)
{ unsignedlong irqflags;
dev_dbg(stat->isp->dev, "%s: user wants to %s module.\n",
stat->subdev.name, enable ? "enable" : "disable");
/* Prevent enabling while configuring */
mutex_lock(&stat->ioctl_lock);
if (!stat->configured && enable) {
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
mutex_unlock(&stat->ioctl_lock);
dev_dbg(stat->isp->dev, "%s: cannot enable module as it's never been successfully configured so far.\n",
stat->subdev.name); return -EINVAL;
}
if (enable) { if (stat->state == ISPSTAT_DISABLING) /* Previous disabling request wasn't done yet */
stat->state = ISPSTAT_ENABLED; elseif (stat->state == ISPSTAT_DISABLED) /* Module is now being enabled */
stat->state = ISPSTAT_ENABLING;
} else { if (stat->state == ISPSTAT_ENABLING) { /* Previous enabling request wasn't done yet */
stat->state = ISPSTAT_DISABLED;
} elseif (stat->state == ISPSTAT_ENABLED) { /* Module is now being disabled */
stat->state = ISPSTAT_DISABLING;
isp_stat_buf_clear(stat);
}
}
int omap3isp_stat_s_stream(struct v4l2_subdev *subdev, int enable)
{ struct ispstat *stat = v4l2_get_subdevdata(subdev);
if (enable) { /* * Only set enable PCR bit if the module was previously * enabled through ioctl.
*/
isp_stat_try_enable(stat);
} else { unsignedlong flags; /* Disable PCR bit and config enable field */
omap3isp_stat_enable(stat, 0);
spin_lock_irqsave(&stat->isp->stat_lock, flags);
stat->ops->enable(stat, 0);
spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
/* * If module isn't busy, a new interrupt may come or not to * set the state to DISABLED. As Histogram needs to read its * internal memory to clear it, let interrupt handler * responsible of changing state to DISABLED. If the last * interrupt is coming, it's still safe as the handler will * ignore the second time when state is already set to DISABLED. * It's necessary to synchronize Histogram with streamoff, once * the module may be considered idle before last SDMA transfer * starts if we return here.
*/ if (!omap3isp_stat_pcr_busy(stat))
omap3isp_stat_isr(stat);
dev_dbg(stat->isp->dev, "%s: module is being disabled\n",
stat->subdev.name);
}
return 0;
}
/* * __stat_isr - Interrupt handler for statistic drivers
*/ staticvoid __stat_isr(struct ispstat *stat, int from_dma)
{ int ret = STAT_BUF_DONE; int buf_processing; unsignedlong irqflags; struct isp_pipeline *pipe;
/* * stat->buf_processing must be set before disable module. It's * necessary to not inform too early the buffers aren't busy in case * of SDMA is going to be used.
*/
spin_lock_irqsave(&stat->isp->stat_lock, irqflags); if (stat->state == ISPSTAT_DISABLED) {
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags); return;
}
buf_processing = stat->buf_processing;
stat->buf_processing = 1;
stat->ops->enable(stat, 0);
if (buf_processing && !from_dma) { if (stat->state == ISPSTAT_ENABLED) {
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
dev_err(stat->isp->dev, "%s: interrupt occurred when module was still processing a buffer.\n",
stat->subdev.name);
ret = STAT_NO_BUF; goto out;
} else { /* * Interrupt handler was called from streamoff when * the module wasn't busy anymore to ensure it is being * disabled after process last buffer. If such buffer * processing has already started, no need to do * anything else.
*/
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags); return;
}
}
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
/* If it's busy we can't process this buffer anymore */ if (!omap3isp_stat_pcr_busy(stat)) { if (!from_dma && stat->ops->buf_process) /* Module still need to copy data to buffer. */
ret = stat->ops->buf_process(stat); if (ret == STAT_BUF_WAITING_DMA) /* Buffer is not ready yet */ return;
/* * Histogram needs to read its internal memory to clear it * before be disabled. For that reason, common statistic layer * can return only after call stat's buf_process() operator.
*/ if (stat->state == ISPSTAT_DISABLING) {
stat->state = ISPSTAT_DISABLED;
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
stat->buf_processing = 0; return;
}
pipe = to_isp_pipeline(&stat->subdev.entity);
stat->frame_number = atomic_read(&pipe->frame_number);
/* * Before this point, 'ret' stores the buffer's status if it's * ready to be processed. Afterwards, it holds the status if * it was processed successfully.
*/
ret = isp_stat_buf_process(stat, ret);
if (likely(!stat->sbl_ovl_recover)) {
stat->ops->setup_regs(stat, stat->priv);
} else { /* * Using recover config to increase the chance to have * a good buffer processing and make the H3A module to * go back to a valid state.
*/
stat->update = 1;
stat->ops->setup_regs(stat, stat->recover_priv);
stat->sbl_ovl_recover = 0;
/* * Set 'update' in case of the module needs to use * regular configuration after next buffer.
*/
stat->update = 1;
}
/* * Hack: H3A modules may access invalid memory address or send * corrupted data to userspace if more than 1 SBL overflow * happens in a row without re-writing its buffer's start memory * address in the meantime. Such situation is avoided if the * module is not immediately re-enabled when the ISR misses the * timing to process the buffer and to setup the registers. * Because of that, pcr_enable(1) was moved to inside this 'if' * block. But the next interruption will still happen as during * pcr_enable(0) the module was busy.
*/
isp_stat_pcr_enable(stat, 1);
spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
} else { /* * If a SBL overflow occurs and the H3A driver misses the timing * to process the buffer, stat->buf_err is set and won't be * cleared now. So the next buffer will be correctly ignored. * It's necessary due to a hw issue which makes the next H3A * buffer to start from the memory address where the previous * one stopped, instead of start where it was configured to. * Do not "stat->buf_err = 0" here.
*/
if (stat->ops->buf_process) /* * Driver may need to erase current data prior to * process a new buffer. If it misses the timing, the * next buffer might be wrong. So should be ignored. * It happens only for Histogram.
*/
atomic_set(&stat->buf_err, 1);
ret = STAT_NO_BUF;
dev_dbg(stat->isp->dev, "%s: cannot process buffer, device is busy.\n",
stat->subdev.name);
}
out:
stat->buf_processing = 0;
isp_stat_queue_event(stat, ret != STAT_BUF_DONE);
}
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.