Ejemplo n.º 1
0
/* Wait for a signal event, without holding a mutex. Either return TIMEOUT if
 * the event never occurred, or SAA_OK if it was signaled during the wait.
 */
int saa7164_cmd_wait(struct saa7164_dev *dev, u8 seqno)
{
	wait_queue_head_t *q = NULL;
	int ret = SAA_BUS_TIMEOUT;
	unsigned long stamp;
	int r;

	if (saa_debug >= 4)
		saa7164_bus_dump(dev);

;

	mutex_lock(&dev->lock);
	if ((dev->cmds[seqno].inuse == 1) &&
		(dev->cmds[seqno].seqno == seqno)) {
		q = &dev->cmds[seqno].wait;
	}
	mutex_unlock(&dev->lock);

	if (q) {
		/* If we haven't been signalled we need to wait */
		if (dev->cmds[seqno].signalled == 0) {
			stamp = jiffies;
//			dprintk(DBGLVL_CMD,
//				"%s(seqno=%d) Waiting (signalled=%d)\n",
;

			/* Wait for signalled to be flagged or timeout */
			/* In a highly stressed system this can easily extend
			 * into multiple seconds before the deferred worker
			 * is scheduled, and we're woken up via signal.
			 * We typically are signalled in < 50ms but it can
			 * take MUCH longer.
			 */
			wait_event_timeout(*q, dev->cmds[seqno].signalled,
				(HZ * waitsecs));
			r = time_before(jiffies, stamp + (HZ * waitsecs));
			if (r)
				ret = SAA_OK;
			else
				saa7164_cmd_timeout_seqno(dev, seqno);

//			dprintk(DBGLVL_CMD, "%s(seqno=%d) Waiting res = %d "
//				"(signalled=%d)\n", __func__, seqno, r,
;
		} else
			ret = SAA_OK;
	} else
//		printk(KERN_ERR "%s(seqno=%d) seqno is invalid\n",
;

	return ret;
}
Ejemplo n.º 2
0
/* Intensionally throw a BUG() if the state of the message bus looks corrupt */
void 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();
	}
}
Ejemplo n.º 3
0
/*
 * Places a command or a response on the bus. The implementation does not
 * know if it is a command or a response it just places the data on the
 * bus depending on the bus information given in the struct tmComResBusInfo
 * structure. If the command or response does not fit into the bus ring
 * buffer it will be refused.
 *
 * Return Value:
 *  SAA_OK     The function executed successfully.
 *  < 0        One or more members are not initialized.
 */
int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
	void *buf)
{
	struct tmComResBusInfo *bus = &dev->bus;
	u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp;
	u32 new_swp, space_rem;
	int ret = SAA_ERR_BAD_PARAMETER;

	if (!msg) {
		printk(KERN_ERR "%s() !msg\n", __func__);
		return SAA_ERR_BAD_PARAMETER;
	}

	dprintk(DBGLVL_BUS, "%s()\n", __func__);

	saa7164_bus_verify(dev);

	msg->size = cpu_to_le16(msg->size);
	msg->command = cpu_to_le16(msg->command);
	msg->controlselector = cpu_to_le16(msg->controlselector);

	if (msg->size > dev->bus.m_wMaxReqSize) {
		printk(KERN_ERR "%s() Exceeded dev->bus.m_wMaxReqSize\n",
			__func__);
		return SAA_ERR_BAD_PARAMETER;
	}

	if ((msg->size > 0) && (buf == NULL)) {
		printk(KERN_ERR "%s() Missing message buffer\n", __func__);
		return SAA_ERR_BAD_PARAMETER;
	}

	/* Lock the bus from any other access */
	mutex_lock(&bus->lock);

	bytes_to_write = sizeof(*msg) + msg->size;
	free_write_space = 0;
	timeout = SAA_BUS_TIMEOUT;
	curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos));
	curr_swp = le32_to_cpu(saa7164_readl(bus->m_dwSetWritePos));

	/* 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;

	dprintk(DBGLVL_BUS, "%s() bytes_to_write = %d\n", __func__,
		bytes_to_write);

	dprintk(DBGLVL_BUS, "%s() free_write_space = %d\n", __func__,
		free_write_space);

	dprintk(DBGLVL_BUS, "%s() curr_srp = %x\n", __func__, curr_srp);
	dprintk(DBGLVL_BUS, "%s() curr_swp = %x\n", __func__, 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 = le32_to_cpu(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;

	dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);
	dprintk(DBGLVL_BUS, "%s() bus->m_dwSizeSetRing = %x\n", __func__,
		bus->m_dwSizeSetRing);

	/* Mental Note: line 462 tmmhComResBusPCIe.cpp */

	/* Check if we're going to wrap again */
	if (new_swp > bus->m_dwSizeSetRing) {

		/* Ring wraps */
		new_swp -= bus->m_dwSizeSetRing;

		space_rem = bus->m_dwSizeSetRing - curr_swp;

		dprintk(DBGLVL_BUS, "%s() space_rem = %x\n", __func__,
			space_rem);

		dprintk(DBGLVL_BUS, "%s() sizeof(*msg) = %d\n", __func__,
			(u32)sizeof(*msg));

		if (space_rem < sizeof(*msg)) {
			dprintk(DBGLVL_BUS, "%s() tr4\n", __func__);

			/* Split the msg into pieces as the ring wraps */
			memcpy(bus->m_pdwSetRing + curr_swp, msg, space_rem);
			memcpy(bus->m_pdwSetRing, (u8 *)msg + space_rem,
				sizeof(*msg) - space_rem);

			memcpy(bus->m_pdwSetRing + sizeof(*msg) - space_rem,
				buf, msg->size);

		} else if (space_rem == sizeof(*msg)) {
			dprintk(DBGLVL_BUS, "%s() tr5\n", __func__);

			/* Additional data at the beginning of the ring */
			memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
			memcpy(bus->m_pdwSetRing, buf, msg->size);

		} else {
			/* Additional data wraps around the ring */
			memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
			if (msg->size > 0) {
				memcpy(bus->m_pdwSetRing + curr_swp +
					sizeof(*msg), buf, space_rem -
					sizeof(*msg));
				memcpy(bus->m_pdwSetRing, (u8 *)buf +
					space_rem - sizeof(*msg),
					bytes_to_write - space_rem);
			}

		}

	} /* (new_swp > bus->m_dwSizeSetRing) */
	else {
		dprintk(DBGLVL_BUS, "%s() tr6\n", __func__);

		/* The ring buffer doesn't wrap, two simple copies */
		memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
		memcpy(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf,
			msg->size);
	}

	dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);

	/* Update the bus write position */
	saa7164_writel(bus->m_dwSetWritePos, cpu_to_le32(new_swp));
	ret = SAA_OK;

out:
	saa7164_bus_dump(dev);
	mutex_unlock(&bus->lock);
	saa7164_bus_verify(dev);
	return ret;
}
int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
                    void *buf)
{
    struct tmComResBusInfo *bus = &dev->bus;
    u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp;
    u32 new_swp, space_rem;
    int ret = SAA_ERR_BAD_PARAMETER;

    if (!msg) {
        printk(KERN_ERR "%s() !msg\n", __func__);
        return SAA_ERR_BAD_PARAMETER;
    }

    dprintk(DBGLVL_BUS, "%s()\n", __func__);

    saa7164_bus_verify(dev);

    msg->size = cpu_to_le16(msg->size);
    msg->command = cpu_to_le32(msg->command);
    msg->controlselector = cpu_to_le16(msg->controlselector);

    if (msg->size > dev->bus.m_wMaxReqSize) {
        printk(KERN_ERR "%s() Exceeded dev->bus.m_wMaxReqSize\n",
               __func__);
        return SAA_ERR_BAD_PARAMETER;
    }

    if ((msg->size > 0) && (buf == NULL)) {
        printk(KERN_ERR "%s() Missing message buffer\n", __func__);
        return SAA_ERR_BAD_PARAMETER;
    }


    mutex_lock(&bus->lock);

    bytes_to_write = sizeof(*msg) + msg->size;
    free_write_space = 0;
    timeout = SAA_BUS_TIMEOUT;
    curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos));
    curr_swp = le32_to_cpu(saa7164_readl(bus->m_dwSetWritePos));


    if (curr_srp > curr_swp)

        free_write_space = curr_srp - curr_swp;
    else

        free_write_space = (curr_srp + bus->m_dwSizeSetRing) - curr_swp;

    dprintk(DBGLVL_BUS, "%s() bytes_to_write = %d\n", __func__,
            bytes_to_write);

    dprintk(DBGLVL_BUS, "%s() free_write_space = %d\n", __func__,
            free_write_space);

    dprintk(DBGLVL_BUS, "%s() curr_srp = %x\n", __func__, curr_srp);
    dprintk(DBGLVL_BUS, "%s() curr_swp = %x\n", __func__, curr_swp);


    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;
        }



        mdelay(1);


        curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos));


        if (curr_srp > curr_swp)

            free_write_space = curr_srp - curr_swp;
        else

            free_write_space = (curr_srp + bus->m_dwSizeSetRing) -
                               curr_swp;

    }


    new_swp = curr_swp + bytes_to_write;

    dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);
    dprintk(DBGLVL_BUS, "%s() bus->m_dwSizeSetRing = %x\n", __func__,
            bus->m_dwSizeSetRing);




    if (new_swp > bus->m_dwSizeSetRing) {


        new_swp -= bus->m_dwSizeSetRing;

        space_rem = bus->m_dwSizeSetRing - curr_swp;

        dprintk(DBGLVL_BUS, "%s() space_rem = %x\n", __func__,
                space_rem);

        dprintk(DBGLVL_BUS, "%s() sizeof(*msg) = %d\n", __func__,
                (u32)sizeof(*msg));

        if (space_rem < sizeof(*msg)) {
            dprintk(DBGLVL_BUS, "%s() tr4\n", __func__);


            memcpy(bus->m_pdwSetRing + curr_swp, msg, space_rem);
            memcpy(bus->m_pdwSetRing, (u8 *)msg + space_rem,
                   sizeof(*msg) - space_rem);

            memcpy(bus->m_pdwSetRing + sizeof(*msg) - space_rem,
                   buf, msg->size);

        } else if (space_rem == sizeof(*msg)) {
            dprintk(DBGLVL_BUS, "%s() tr5\n", __func__);


            memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
            memcpy(bus->m_pdwSetRing, buf, msg->size);

        } else {

            memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
            if (msg->size > 0) {
                memcpy(bus->m_pdwSetRing + curr_swp +
                       sizeof(*msg), buf, space_rem -
                       sizeof(*msg));
                memcpy(bus->m_pdwSetRing, (u8 *)buf +
                       space_rem - sizeof(*msg),
                       bytes_to_write - space_rem);
            }

        }

    }
    else {
        dprintk(DBGLVL_BUS, "%s() tr6\n", __func__);


        memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
        memcpy(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf,
               msg->size);
    }

    dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);


    saa7164_writel(bus->m_dwSetWritePos, cpu_to_le32(new_swp));
    ret = SAA_OK;

out:
    saa7164_bus_dump(dev);
    mutex_unlock(&bus->lock);
    saa7164_bus_verify(dev);
    return ret;
}