/* The message bus to/from the firmware is a ring buffer in PCI address *space.Establishthedefaults.
*/ int saa7164_bus_setup(struct saa7164_dev *dev)
{ struct tmComResBusInfo *b = &dev->bus;
/* Intensionally throw a BUG() if the state of the message bus looks corrupt */ staticvoid saa7164_bus_verify(struct saa7164_dev *dev)
{ struct tmComResBusInfo *b = &dev->bus; int bug = 0;
if (saa7164_readl(b->m_dwSetReadPos) > b->m_dwSizeSetRing)
bug++;
if (saa7164_readl(b->m_dwSetWritePos) > b->m_dwSizeSetRing)
bug++;
if (saa7164_readl(b->m_dwGetReadPos) > b->m_dwSizeGetRing)
bug++;
if (saa7164_readl(b->m_dwGetWritePos) > b->m_dwSizeGetRing)
bug++;
if (bug) {
saa_debug = 0xffff; /* Ensure we get the bus dump */
saa7164_bus_dump(dev);
saa_debug = 1024; /* Ensure we get the bus dump */
BUG();
}
}
/* Deal with ring wrapping issues */ if (curr_srp > curr_swp) /* Deal with the wrapped ring */
free_write_space = curr_srp - curr_swp; else /* The ring has not wrapped yet */
free_write_space = (curr_srp + bus->m_dwSizeSetRing) - curr_swp;
/* Process the msg and write the content onto the bus */ while (bytes_to_write >= free_write_space) {
if (timeout-- == 0) {
printk(KERN_ERR "%s() bus timeout\n", __func__);
ret = SAA_ERR_NO_RESOURCES; goto out;
}
/* TODO: Review this delay, efficient? */ /* Wait, allowing the hardware fetch time */
mdelay(1);
/* Check the space usage again */
curr_srp = saa7164_readl(bus->m_dwSetReadPos);
/* Deal with ring wrapping issues */ if (curr_srp > curr_swp) /* Deal with the wrapped ring */
free_write_space = curr_srp - curr_swp; else /* Read didn't wrap around the buffer */
free_write_space = (curr_srp + bus->m_dwSizeSetRing) -
curr_swp;
}
/* Calculate the new write position */
new_swp = curr_swp + bytes_to_write;
if (space_rem < sizeof(*msg)) {
dprintk(DBGLVL_BUS, "%s() tr4\n", __func__);
/* Split the msg into pieces as the ring wraps */
memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, space_rem);
memcpy_toio(bus->m_pdwSetRing, (u8 *)msg + space_rem, sizeof(*msg) - space_rem);
/* Additional data at the beginning of the ring */
memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
memcpy_toio(bus->m_pdwSetRing, buf, size);
} else { /* Additional data wraps around the ring */
memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); if (size > 0) {
memcpy_toio(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf, space_rem - sizeof(*msg));
memcpy_toio(bus->m_pdwSetRing, (u8 *)buf +
space_rem - sizeof(*msg),
bytes_to_write - space_rem);
}
/* Update the bus write position */
saa7164_writel(bus->m_dwSetWritePos, new_swp);
/* Convert back to cpu after writing the msg to the ringbuffer. */
msg->size = le16_to_cpu((__force __le16)msg->size);
msg->command = le32_to_cpu((__force __le32)msg->command);
msg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);
ret = SAA_OK;
if ((peekonly == 0) && (msg->size > 0) && (buf == NULL)) {
printk(KERN_ERR "%s() Missing msg buf, size should be %d bytes\n",
__func__, msg->size); return ret;
}
mutex_lock(&bus->lock);
/* Peek the bus to see if a msg exists, if it's not what we're expecting *thenreturncleanlyelsereadthemessagefromthebus.
*/
curr_gwp = saa7164_readl(bus->m_dwGetWritePos);
curr_grp = saa7164_readl(bus->m_dwGetReadPos);
if (curr_gwp == curr_grp) {
ret = SAA_ERR_EMPTY; goto out;
}
bytes_to_read = sizeof(*msg);
/* Calculate write distance to current read position */
write_distance = 0; if (curr_gwp >= curr_grp) /* Write doesn't wrap around the ring */
write_distance = curr_gwp - curr_grp; else /* Write wraps around the ring */
write_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;
if (bytes_to_read > write_distance) {
printk(KERN_ERR "%s() No message/response found\n", __func__);
ret = SAA_ERR_INVALID_COMMAND; goto out;
}
/* Calculate the new read position */
new_grp = curr_grp + bytes_to_read; if (new_grp > bus->m_dwSizeGetRing) {
} else { /* No wrapping */
memcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read);
} /* Convert from little endian to CPU */
msg_tmp.size = le16_to_cpu((__force __le16)msg_tmp.size);
msg_tmp.command = le32_to_cpu((__force __le32)msg_tmp.command);
msg_tmp.controlselector = le16_to_cpu((__force __le16)msg_tmp.controlselector);
memcpy(msg, &msg_tmp, sizeof(*msg));
/* No need to update the read positions, because this was a peek */ /* If the caller specifically want to peek, return */ if (peekonly) { goto peekout;
}
/* Check if the command/response matches what is expected */ if ((msg_tmp.id != msg->id) || (msg_tmp.command != msg->command) ||
(msg_tmp.controlselector != msg->controlselector) ||
(msg_tmp.seqno != msg->seqno) || (msg_tmp.size != msg->size)) {
/* Get the actual command and response from the bus */
buf_size = msg->size;
bytes_to_read = sizeof(*msg) + msg->size; /* Calculate write distance to current read position */
write_distance = 0; if (curr_gwp >= curr_grp) /* Write doesn't wrap around the ring */
write_distance = curr_gwp - curr_grp; else /* Write wraps around the ring */
write_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;
if (bytes_to_read > write_distance) {
printk(KERN_ERR "%s() Invalid bus state, missing msg or mangled ring, faulty H/W / bad code?\n",
__func__);
ret = SAA_ERR_INVALID_COMMAND; goto out;
}
/* Calculate the new read position */
new_grp = curr_grp + bytes_to_read; if (new_grp > bus->m_dwSizeGetRing) {
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.