Esempio n. 1
0
int io_write(resmgr_context_t *ctp, io_write_t *msg, iofunc_ocb_t *ocb)
{
	LOCK(resource_mutex);
	printf("IO write activated\n");

	// set data to return
	_IO_SET_WRITE_NBYTES(ctp, msg->i.nbytes);

	int nBytes = msg->i.nbytes + 1;

	char *buf = (char *)malloc(nBytes * sizeof(char));
	if (!buf)
		RETURN_UNLOCK(ENOMEM, resource_mutex);

	resmgr_msgread(ctp, buf, nBytes, sizeof(msg->i));
	buf[msg->i.nbytes] = '\0';
	printf("Received %d bytes = \"%s\"\n", msg->i.nbytes, buf);

	int rcvid = fifo_rem_blocked_id(fifoHandler);
	if(rcvid != -1)
	{
		printf("Found blocked id, sending string '%s' with %i bytes\n", buf, nBytes);
		MsgReply(rcvid, nBytes, buf, nBytes);
		free(buf);
		RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
	}

	fifo_add_string(fifoHandler, buf);
	free(buf);

	RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
}
int
_spi_iomsg_write(resmgr_context_t *ctp, io_msg_t *msg, spi_ocb_t *ocb)
{
	spi_msg_t	*spimsg = (spi_msg_t *)msg;
    uint8_t		*buf;
    int			nbytes, msglen, status;
	SPIDEV		*drvhdl = (SPIDEV *)ocb->hdr.attr;
	spi_dev_t	*dev = drvhdl->hdl;
	uint16_t	chip = spimsg->device & SPI_DEV_ID_MASK;

	/* check if message buffer is too short */
	nbytes = spimsg->xlen;

    if (nbytes <= 0) {
        _IO_SET_WRITE_NBYTES(ctp, 0);
        return _RESMGR_NPARTS(0);
    }

	msglen = nbytes + sizeof(spi_msg_t);

	if (msglen > ctp->msg_max_size) {
		if (dev->buflen < msglen) {
			dev->buflen = msglen;
			if (dev->buf)
				free(dev->buf);
			if ((dev->buf = malloc(dev->buflen)) == NULL) {
				dev->buflen = 0;
				return ENOMEM;
			}
		}

		status = resmgr_msgread(ctp, dev->buf, msglen, 0);
		if (status < 0)
			return errno;
		if (status < msglen)
			return EFAULT;

		buf = dev->buf;
	}
	else
		buf = (uint8_t *)msg;

	if (chip == SPI_DEV_ID_NONE)
		chip = ocb->chip;

	buf = dev->funcs->xfer(drvhdl, _SPI_DEV_WRITE(chip), buf + sizeof(spi_msg_t), &nbytes);

	if (nbytes == 0)
		return EAGAIN;

	if (nbytes > 0) {
		_IO_SET_WRITE_NBYTES(ctp, nbytes);
		return _RESMGR_NPARTS(0);
	}

	return EIO;
}
Esempio n. 3
0
int syslink_frameq_getv(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

			FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
			FrameQDrv_CmdArgs *out = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));

			FrameQ_Frame        *framePtr = NULL;
            UInt32              *filledQueueId = NULL;
            FrameQ_FrameBufInfo *frameBufInfo;
            Ptr                 phyPtr;
            Ptr                 addr;
            UInt32              j;
			int					i;

			framePtr = (FrameQ_Frame*)(cargs+1);

			filledQueueId = (UInt32*)(framePtr + cargs->args.getv.numFrames);

            out->apiStatus = FrameQ_getv (cargs->args.getv.handle,
                                          framePtr,
                                          (Ptr)filledQueueId,
                                          &cargs->args.getv.numFrames);

			SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(FrameQDrv_CmdArgs));

            if ((out->apiStatus >= 0) && (cargs->args.getv.numFrames > 0)) {

                      for (i = 0; i < cargs->args.getv.numFrames; i++) {
                            /* Convert Frame and frame buffer address in frame
                             			  * to physical address formatso that user space api
                             			  * convert this physical address in to user space
                             		 	  * virtual format.
                             			  */
                            frameBufInfo = (FrameQ_FrameBufInfo *)
                                                &(framePtr[i]->frameBufInfo[0]);

                            for(j = 0; j < framePtr[i]->numFrameBuffers; j++) {
                                addr = (Ptr)frameBufInfo[j].bufPtr;
                                phyPtr = Memory_translate(
                                                     addr,
                                                     Memory_XltFlags_Virt2Phys);
                                GT_assert(curTrace,(phyPtr != NULL));
                                frameBufInfo[j].bufPtr = (UInt32)phyPtr;
                            }

                            framePtr[i] = Memory_translate(
                                                     framePtr[i],
                                                     Memory_XltFlags_Virt2Phys);
                        }

						SETIOV(&ctp->iov[1], framePtr, sizeof (UInt32) * cargs->args.getv.numFrames);

                       	return _RESMGR_NPARTS(2);
                    }

			return _RESMGR_NPARTS(1);
}
Esempio n. 4
0
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb){
    int nbytes;
    int buffer_read;

    /* Check if the buffer has been reads */
    if(ocb->offset){
    	nbytes = 0;
    	_IO_SET_READ_NBYTES (ctp, 0);
    	buffer_read = 0;
    }else{
    	nbytes = BUFFER_SIZE;

    	pthread_mutex_lock(&lock);
		sprintf(buffer, "%i\n", counter_var);
		pthread_mutex_unlock(&lock);

		printf("buffer is: %s \n", buffer);

		/* Set up the return data IOV */
		SETIOV (ctp->iov, buffer, nbytes);

		/* Set up the number of bytes (returned by client's read()) */
		_IO_SET_READ_NBYTES (ctp, nbytes);

		/* Set the offset to one, indicating the buffer has been read */
		ocb->offset = 1;
		buffer_read = 1;
    }
    return (_RESMGR_NPARTS (buffer_read));
}
Esempio n. 5
0
int syslink_frameq_get_vnumfreeframes(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

			FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
			FrameQDrv_CmdArgs *out = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));

			/* Get the available frames in filled queue 0 of FrameQ */
            UInt32  *freeQueueId = NULL;
            UInt32  *numFreeFrames;

			numFreeFrames = (UInt32*)(cargs+1);

            freeQueueId = (UInt32*)(numFreeFrames + cargs->args.getvNumFreeFrames.numFreeQids);

			out->apiStatus = FrameQ_getvNumFreeFrames(
                                        cargs->args.getvNumFreeFrames.handle,
                                        numFreeFrames,
                                        (Ptr)freeQueueId,
                                        cargs->args.getvNumFreeFrames.numFreeQids);

			SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(FrameQDrv_CmdArgs));
			SETIOV(&ctp->iov[1], numFreeFrames, sizeof (UInt32) * cargs->args.getvNumFreeFrames.numFreeQids);

			return _RESMGR_NPARTS(2);

}
Esempio n. 6
0
static int 
devi_notify(resmgr_context_t *ctp, io_notify_t *msg, RESMGR_OCB_T *ocb)
{
        devi_attr_t 		*attr = ocb->ocb.attr;
        event_bus_line_t		*line = attr->line;
        int			trig = 0, n;
        int			sts;

        /* we don't support output or out of band notification */

        if (msg->i.flags & (_NOTIFY_COND_OBAND | _NOTIFY_COND_OUTPUT))
                return (ENOSYS);

        pthread_mutex_lock(&line->mutex);
        
        /* if queue non-empty, trigger */
        if (ocb->read_ptr != line->head) 
                trig = _NOTIFY_COND_INPUT;

        pthread_mutex_unlock(&line->mutex);
        
        sts = iofunc_notify(ctp, msg, attr->notify, trig, NULL, &n);
        if (sts == EBUSY)
                return (EBUSY);

        if (n) 
                attr->flags |= DEVI_NOTIFICATION_ARMED;

        return (_RESMGR_NPARTS(1));
}
Esempio n. 7
0
int
io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
{
    int status;
	static char data[] = "hello";
	int nb;
	
	
    if (optv) {
        printf ("%s:  in io_read\n", progname);
    }
    
 	if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK) {
    	if (optv) printf("read failed because of error %d\n", status );
        return (status);
    }
        
    // No special xtypes
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {
        return(ENOSYS);
    }
    
    nb = strlen(data );
    
	nb = min( nb, msg->i.nbytes );
	
    _IO_SET_READ_NBYTES (ctp, nb);
    SETIOV( ctp->iov, data, nb );

    if (nb > 0)
        ocb->attr->flags |= IOFUNC_ATTR_ATIME;

    return (_RESMGR_NPARTS (1));
    
}
int io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int     status;    

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);

    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
        return(ENOSYS);

    /* set up the number of bytes (returned by client's write()) */

    _IO_SET_WRITE_NBYTES (ctp, msg->i.nbytes);   

    /*
     *  Reread the data from the sender's message buffer.
     *  We're not assuming that all of the data fit into the
     *  resource manager library's receive buffer.
     */
    
    resmgr_msgread(ctp, buffer, min(msg->i.nbytes, 4095), sizeof(msg->i));    
    buffer[min(msg->i.nbytes, 4095)] = '\0'; /* just in case the text is not NULL terminated */
    ocb->offset = 0;
    attr.nbytes = strlen (buffer)+1;
    printf("%s\n", buffer);  

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
{
	int         nleft;
    int         nbytes;
    int         nparts;
    int         status;

    if ((status = iofunc_read_verify (ctp, msg, ocb, NULL)) != EOK)
        return (status);
        
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
        return (ENOSYS);

    /*
     *  On all reads (first and subsequent), calculate
     *  how many bytes we can return to the client,
     *  based upon the number of bytes available (nleft)
     *  and the client's buffer size
     */

    nleft = ocb->attr->nbytes - ocb->offset;
    nbytes = min(msg->i.nbytes, nleft);    

    if (nbytes > 0) {
        /* set up the return data IOV */
        SETIOV (ctp->iov, buffer + ocb->offset, nbytes);

        /* set up the number of bytes (returned by client's read()) */
        _IO_SET_READ_NBYTES (ctp, nbytes);

        /*
         * advance the offset by the number of bytes
         * returned to the client.
         */

        ocb->offset += nbytes;
        
        nparts = 1;
    } else {
        /*
         * they've asked for zero bytes or they've already previously
         * read everything
         */
        
        _IO_SET_READ_NBYTES (ctp, 0);
        
        nparts = 0;
    }

    /* mark the access time as invalid (we just accessed it) */

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_ATIME;

    return (_RESMGR_NPARTS (nparts));
}
Esempio n. 10
0
int
_spi_read(resmgr_context_t *ctp, io_read_t *msg, spi_ocb_t *ocb)
{
	uint8_t		*buf;
	int			nbytes;
	int			nonblock = 0;
	int			status;
	SPIDEV		*drvhdl = (SPIDEV *)ocb->hdr.attr;
	spi_dev_t	*dev = drvhdl->hdl;

    if ((status = iofunc_read_verify(ctp, msg, &ocb->hdr, &nonblock)) != EOK)
        return status;

    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
        return ENOSYS;

	/*
	 * Check to see if the device is locked
	 */
	if ((status =_spi_lock_check(ctp, ocb->chip, ocb)) != EOK)
		return status;

    if (msg->i.nbytes <= 0) {
        _IO_SET_READ_NBYTES(ctp, 0);
        return _RESMGR_NPARTS(0);
    }

    /* check if message buffer is too short */
    nbytes = msg->i.nbytes;
    if (nbytes > ctp->msg_max_size) {
        if (dev->buflen < nbytes) {
            dev->buflen = nbytes;
			if (dev->buf)
            	free(dev->buf);
            if (NULL == (dev->buf = malloc(dev->buflen))) {
                dev->buflen = 0;
                return ENOMEM;
            }
        }
        buf = dev->buf;
    }
	else
        buf = (uint8_t *)msg;

	buf = dev->funcs->xfer(drvhdl, _SPI_DEV_READ(ocb->chip), buf, &nbytes);

	if (nbytes > 0) {
		_IO_SET_READ_NBYTES(ctp, nbytes);
		return _RESMGR_PTR(ctp, buf, nbytes);
	}

	return EIO;
}
Esempio n. 11
0
/**
 * Handler for frameq getconfig API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_frameq_getconfig(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb){

			FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

			FrameQ_Config *config = (FrameQ_Config*)(cargs+1);

  			FrameQ_getConfig (config);

			SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(FrameQDrv_CmdArgs));
			SETIOV(&ctp->iov[1], config, sizeof(FrameQ_Config));

			return _RESMGR_NPARTS(2);
}
Esempio n. 12
0
/**
 * Handler for heapbuf mp params init API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_heapbufmp_params_init(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb)
{
	HeapBufMPDrv_CmdArgs *		cargs = (HeapBufMPDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	HeapBufMP_Params *local_params = (HeapBufMP_Params *)(cargs+1);

	HeapBufMP_Params_init (local_params);
	cargs->apiStatus = HeapBufMP_S_SUCCESS;

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(HeapBufMPDrv_CmdArgs));
	SETIOV(&ctp->iov[1], local_params, sizeof(HeapBufMP_Params));

   return _RESMGR_NPARTS(2);
}
Esempio n. 13
0
int io_read(resmgr_context_t *ctp, io_read_t *msg, iofunc_ocb_t *ocb)
{
	LOCK(resource_mutex);
	printf("IO read activated\n");

	int nonblock, status;

	if ((status = iofunc_read_verify (ctp, msg, ocb, &nonblock)) != EOK)
	{
		RETURN_UNLOCK(status, resource_mutex);
	}

	// set data to return
	if (ocb->offset)
	{
		SETIOV(ctp->iov, NULL, 0);
		_IO_SET_READ_NBYTES(ctp, 0);
		RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
	}
	ocb->offset = 1;

	if (nonblock && !fifo_status(fifoHandler))
	{
		SETIOV(ctp->iov, NULL, 0);
		_IO_SET_READ_NBYTES(ctp, 0);
		RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
	}
	else if(!fifo_status(fifoHandler))
	{
		fifo_add_blocked_id(fifoHandler, ctp->rcvid);
		RETURN_UNLOCK(_RESMGR_NOREPLY, resource_mutex);
	}

	char buffer[WIDTH];
	fifo_rem_string(fifoHandler, buffer);
	SETIOV(ctp->iov, buffer, strlen(buffer));
	_IO_SET_READ_NBYTES(ctp, strlen(buffer));
	RETURN_UNLOCK(_RESMGR_NPARTS(1), resource_mutex);
}
Esempio n. 14
0
int syslink_frameq_shmem_params_init(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb){

			FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

			FrameQ_ShMem_Params *params = (FrameQ_ShMem_Params*)(cargs+1);

			FrameQ_ShMem_Params_init(params);

			SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(FrameQDrv_CmdArgs));
			SETIOV(&ctp->iov[1], params, sizeof(FrameQ_ShMem_Params));

			return _RESMGR_NPARTS(2);

}
/**
 * Handler for shared region get config API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_sharedregion_getconfig(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

	SharedRegionDrv_CmdArgs *		cargs = (SharedRegionDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

	SharedRegion_Config *config = (SharedRegion_Config *)(cargs+1);

	SharedRegion_getConfig (config);
	cargs->apiStatus = SharedRegion_S_SUCCESS;

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(SharedRegionDrv_CmdArgs));
	SETIOV(&ctp->iov[1], config, sizeof(SharedRegion_Config));

    return _RESMGR_NPARTS(2);
}
Esempio n. 16
0
/**
 * Handler for heapbuf mp get config API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_heapbufmp_getconfig(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

	HeapBufMPDrv_CmdArgs *		cargs = (HeapBufMPDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

    HeapBufMP_Config *config = (HeapBufMP_Config *)(cargs+1);

	HeapBufMP_getConfig (config);
	cargs->apiStatus = HeapBufMP_S_SUCCESS;

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(HeapBufMPDrv_CmdArgs));
	SETIOV(&ctp->iov[1], config, sizeof(HeapBufMP_Config));

   return _RESMGR_NPARTS(2);
}
Esempio n. 17
0
/**
 * Handler for messageq params init API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_messageq_params_init(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb)
{
	MessageQDrv_CmdArgs *		cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

	MessageQ_Params *local_params = (MessageQ_Params *)(cargs+1);

  	MessageQ_Params_init (local_params);
    cargs->apiStatus = MessageQ_S_SUCCESS;

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs));
	SETIOV(&ctp->iov[1], local_params, sizeof(*local_params));

	return _RESMGR_NPARTS(2);
}
Esempio n. 18
0
/**
 * Handler for messageq getconfig API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_messageq_getconfig(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb)
{
    MessageQDrv_CmdArgs * cargs =
            (MessageQDrv_CmdArgs *)(_DEVCTL_DATA (msg->i));
	MessageQ_Config local_config;
  MessageQ_getConfig (&local_config);

    cargs->apiStatus = MessageQ_S_SUCCESS;
	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs));
	SETIOV(&ctp->iov[1], &local_config, sizeof(MessageQ_Config));

	return _RESMGR_NPARTS(2);

}
Esempio n. 19
0
/**
 * Handler for heap buf mp get extended stats API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_heapbufmp_getextendedstats(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

	HeapBufMPDrv_CmdArgs *		cargs = (HeapBufMPDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	HeapBufMP_ExtendedStats *stats = (HeapBufMP_ExtendedStats *)(cargs+1);

	HeapBufMP_getExtendedStats ( cargs->args.getExtendedStats.handle,
                                         stats);
	cargs->apiStatus = HeapBufMP_S_SUCCESS;

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(HeapBufMPDrv_CmdArgs));
	SETIOV(&ctp->iov[1], stats, sizeof(HeapBufMP_ExtendedStats));

	return _RESMGR_NPARTS(2);
}
Esempio n. 20
0
int io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb){
    char    *buf;

    /* set up the number of bytes (returned by client's write()) */
    _IO_SET_WRITE_NBYTES (ctp, msg->i.nbytes);

    buf = (char *) malloc(msg->i.nbytes + 1);
    if (buf == NULL)
        return(ENOMEM);

    /*
     *  Reread the data from the sender's message buffer.
     *  We're not assuming that all of the data fit into the
     *  resource manager library's receive buffer.
     */

    resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i));
    buf [msg->i.nbytes] = '\0'; /* just in case the text is not NULL terminated */
    printf ("Received %d bytes = '%s'\n", msg -> i.nbytes, buf);

    /* Set the dir var for counter thread according to the command */
    if(!strncmp(buf, "up", 2)){
    	/* Count upwards */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_UP;
    	pthread_mutex_unlock(&lock);

    }else if(!strncmp(buf,"down", 4)){
    	/* Count downwards */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_DOWN;
    	pthread_mutex_unlock(&lock);

    }else if(!strncmp(buf, "stop", 4)){
    	/* Stop counting */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_NONE;
    	pthread_mutex_unlock(&lock);

    }else{
    	// do nothing
    }

    free(buf);

    return (_RESMGR_NPARTS (0));
}
Esempio n. 21
0
int syslink_frameq_shmem_memreq(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb){

			FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));

			FrameQ_ShMem_Params *params = NULL;
            UInt32 *memreq;

			memreq = (UInt32*)(cargs+1);
			params = (FrameQ_ShMem_Params*)(memreq+1);

            *memreq = FrameQ_ShMem_sharedMemReq(params);

            SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(FrameQDrv_CmdArgs));
			SETIOV(&ctp->iov[1], memreq, sizeof (UInt32));

			return _RESMGR_NPARTS(2);

}
Esempio n. 22
0
int reply_symlink(resmgr_context_t *ctp, unsigned eflag, struct _io_connect_link_reply *linkp, struct symlink_object *symlinkp, const char *path, const char *tail) {
	int						len;
	iov_t					*iov;

	if(path) {
		_IO_SET_CONNECT_RET(ctp, _IO_CONNECT_RET_LINK);
	}
	linkp->eflag = eflag;
	linkp->nentries = 0;
	linkp->path_len = symlinkp->len;

	iov = ctp->iov;
	SETIOV(iov, linkp, sizeof *linkp);
	iov++;

	len = 0;
	if(path) {
		if(symlinkp->name[0] != '/' && (len = tail - path)) {
			while(--len && path[len-1] != '/') {
				/* nothing to do */
			}
		}

		if(len) {
			linkp->path_len += len;
			SETIOV(iov, path, len);
			iov++;
		}

		len = strlen(tail);
	}

	SETIOV(iov, symlinkp->name, len ? symlinkp->len - 1 : symlinkp->len);
	iov++;

	if(len) {
		linkp->path_len += len + 1;
		SETIOV(iov, tail - 1, len + 2);
		iov++;
	}

	return _RESMGR_NPARTS(iov - ctp->iov);
}
Esempio n. 23
0
/**
 * Handler for messageq create API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_messageq_create(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb)
{
	MessageQDrv_CmdArgs *		cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	MessageQDrv_CmdArgs *		out   = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));
	MessageQ_Params *local_createparams = NULL;
	String local_createname = NULL;
	out->apiStatus = MessageQ_S_SUCCESS;

	if (cargs->args.create.params) {
		local_createparams = (MessageQ_Params *)(cargs+1);
		if (cargs->args.create.name)
			local_createname = (String)(local_createparams+1);
	}
	else {
		if (cargs->args.create.name)
			local_createname = (String)(cargs+1);
	}

    out->args.create.handle = MessageQ_create (local_createname, local_createparams);
    GT_assert (curTrace, (out->args.create.handle != NULL));

    /* Set failure status if create has failed. */
    if (out->args.create.handle == NULL) {
        out->apiStatus = MessageQ_E_FAIL;
    }
    else {
    	out->apiStatus = MessageQ_S_SUCCESS;
    }

    if (out->args.create.handle != NULL) {
        out->args.create.queueId = MessageQ_getQueueId (
                                             out->args.create.handle);
    }

    if (out->apiStatus >= 0) {
        /* At this call to the list to be cleaned-up */
        add_ocb_res(ocb, DCMD_MESSAGEQ_DELETE, (int)out->args.create.handle, NULL);
    }

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs));
	return _RESMGR_NPARTS(1);
}
Esempio n. 24
0
/**
 * Handler for messageq setup API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_messageq_setup(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {

	MessageQDrv_CmdArgs *		cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	MessageQDrv_CmdArgs *		out  = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));

	MessageQ_Config *local_setupconfig;
	local_setupconfig = (MessageQ_Config *)(cargs+1);

	out->apiStatus = MessageQ_setup (local_setupconfig);

	GT_assert (curTrace, (out->apiStatus  >= 0));
    if (out->apiStatus >= 0) {
        /* Add this call to the list to be cleaned-up */
        add_ocb_res(ocb, DCMD_MESSAGEQ_DESTROY, NULL, NULL);
    }

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs));

	return _RESMGR_NPARTS(1);
}
/**
 * Handler for shared region setup API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_sharedregion_setup(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) {


	SharedRegionDrv_CmdArgs *		cargs = (SharedRegionDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	SharedRegionDrv_CmdArgs *		out  = (SharedRegionDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));

	SharedRegion_Config   *config = (SharedRegion_Config*)(cargs+1);
	 SharedRegion_Region   *region = (SharedRegion_Region *)(config+1);
	 UInt16 			 i;

	 out->apiStatus = SharedRegion_setup (config);
	 GT_assert (curTrace, (out->apiStatus >= 0));

	 for (i = 0; i < config->numEntries; i++) {

		 SharedRegion_getRegionInfo (i, &region[i]);

		 if (region[i].entry.isValid == TRUE) {

			 /* Convert the kernel virtual address to physical
			  * addresses */
			 region[i].entry.base = MemoryOS_translate (
										(Ptr)region[i].entry.base,
										Memory_XltFlags_Virt2Phys);
			 GT_assert (curTrace, (region[i].entry.base != NULL));
		 }
	 }

    if (out->apiStatus >= 0) {
        /* Add this call to the list to be cleaned-up */
        add_ocb_res(ocb, DCMD_SHAREDREGION_DESTROY, (int)NULL, NULL);
    }

    SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(SharedRegionDrv_CmdArgs));
	SETIOV(&ctp->iov[1], config, sizeof(SharedRegion_Config) );
  	SETIOV(&ctp->iov[2], region, config->numEntries*sizeof(SharedRegion_Region));

    return _RESMGR_NPARTS(3);

}
/**
 * Handler for shared region get region info API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_sharedregion_getregioninfo(
        resmgr_context_t *      ctp,
        io_devctl_t *           msg,
        syslink_ocb_t *         ocb)
{
    SharedRegionDrv_CmdArgs *   cmdArgs;
    SharedRegion_Region   *     region;
    SharedRegion_Config         config;
    UInt16                      i;

    cmdArgs = (SharedRegionDrv_CmdArgs *)(_DEVCTL_DATA(msg->i));
    region = (SharedRegion_Region *)(cmdArgs + 1);
    SharedRegion_getConfig(&config);

    for (i = 0; i < config.numEntries; i++) {
        SharedRegion_getRegionInfo(i, &region[i]);

        if (region[i].entry.isValid) {
            if (region[i].entry.createHeap) {
                /* convert the kernel virtual address to physical addresses */
                region[i].entry.base = MemoryOS_translate(
                    (Ptr)region[i].entry.base, Memory_XltFlags_Virt2Phys);
                GT_assert(curTrace, (region[i].entry.base != NULL));
            }
            /* else, nothing to do, entry.base is already physical address */
        }
        else {
            region[i].entry.base = NULL;
        }
    }

    SETIOV(&ctp->iov[0], &msg->o,
        sizeof(msg->o) + sizeof(SharedRegionDrv_CmdArgs));
    SETIOV(&ctp->iov[1], region,
        (sizeof(SharedRegion_Region) * config.numEntries));

    return(_RESMGR_NPARTS(2));  /* config.numEntries */
}
Esempio n. 27
0
/**
 * Handler for messageq open API.
 *
 * \param ctp	Thread's associated context information.
 * \param msg	The actual devctl() message.
 * \param ocb	OCB associated with client's session.
 *
 * \return POSIX errno value.
 *
 * \retval EOK		Success.
 * \retval ENOTSUP	Unsupported devctl().
 */
int syslink_messageq_open(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb)
{
	MessageQDrv_CmdArgs *		cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i));
	MessageQDrv_CmdArgs *		out   = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o));
	MessageQ_QueueId queueId = MessageQ_INVALIDMESSAGEQ;
	String local_openname = (String)(cargs+1);

	out->apiStatus = MessageQ_open (local_openname, &queueId);
	GT_1trace (curTrace,
				GT_2CLASS,
				"    MessageQ_open ioctl queueId [0x%x]",
				queueId);

	out->args.open.queueId = queueId;
    if (out->apiStatus >= 0) {
        /* At this call to the list to be cleaned-up */
        add_ocb_res(ocb, DCMD_MESSAGEQ_CLOSE, (int)out->args.open.queueId, NULL);
    }

	SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) + sizeof(MessageQDrv_CmdArgs));

	return _RESMGR_NPARTS(1);
}
Esempio n. 28
0
int
io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int status;
    
    if (optv) {
        printf ("%s:  in io_write\n", progname);
    }

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);
        
    // No special xtypes
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {
        return(ENOSYS);
    }

    _IO_SET_WRITE_NBYTES (ctp, msg -> i.nbytes);

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}
Esempio n. 29
0
int
io_write( resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
  int status;
  char *buf;

  if((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK )
    return(status);

  if((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
    return(ENOSYS);

  _IO_SET_WRITE_NBYTES(ctp, msg->i.nbytes);

  buf = (char *)malloc(msg->i.nbytes + 1);
  if( buf == NULL)
    return(ENOMEM);

  /*
   * reread the data from the sender's message buffer.
   * We're not assuming that all of the data fit into the 
   * resource manager library's receive buffer.
   */
  if( (status = resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i))) == -1){ 
    return(ENOSYS);
  }
  fprintf(stderr,"_ics660-drvr:  bytes attemted: %d  bytes received %d\n",msg->i.nbytes,status);
  buf[msg->i.nbytes] = '\0'; //just in case text is not NULL terminated 
  memcpy((int *)ics660->mem1,buf,(size_t)msg->i.nbytes);
  free(buf);

  if(msg->i.nbytes > 0)
    ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

  return(_RESMGR_NPARTS(0));
}
Esempio n. 30
0
int
io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int status;
    int nb;
    
    if (optv) {
        printf ("%s:  in io_write, of %d bytes\n", progname, msg->i.nbytes);
    }

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);
        
    // No special xtypes
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {
        return(ENOSYS);
    }
	
	if( msg->i.nbytes == ctp->info.msglen - (ctp->offset + sizeof(*msg) ))
	{
		/* have all the data */
		char *buf;
		buf = (char *)(msg+1);
		
		nb = write( STDOUT_FILENO , buf, msg->i.nbytes ); // fd 1 is stdout
		if( -1 == nb )
		   return errno;
	} else 
	{
#if 0
		char *buf;
		buf = malloc( msg->i.nbytes );
		if (NULL == buf )
		   return ENOMEM;
		nb = resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(*msg));
		nb = write(1, buf, nb ); // fd 1 is stdout
		free(buf);
		if( -1 == nb )
		   return errno;
#else		   
		char buf[1000]; // my hardware buffer
        int count, bytes;
        count = 0;
        
        while ( count < msg->i.nbytes )
        {
        	bytes = resmgr_msgread( ctp, buf, 1000, count + sizeof(*msg ));
        	if( bytes == -1 )
        	   return errno;
        	bytes = write( 1, buf, bytes ); // fd 1 is standard out 
        	if( bytes == -1 )
        	{  
        	   if (!count )
        	     return errno;
        	   else 
        	      break;
        	}
        	count += bytes;
        }
        nb = count;
#endif		
	}
    _IO_SET_WRITE_NBYTES (ctp, nb);

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}