[Cbe-oss-dev] [PATCH] libspe2: spe_mfcio_tag_status_read implementation

Kazunori Asayama asayama at sm.sony.co.jp
Wed Nov 15 23:37:10 EST 2006


Attached is a patch to implement spe_mfcio_tag_status_read API
function in libspe2.

Thanks,
--
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t
-------------- next part --------------
Index: libspe2/libspe2-types.h
===================================================================
--- libspe2.orig/libspe2-types.h
+++ libspe2/libspe2-types.h
@@ -212,6 +212,14 @@ enum ps_area { SPE_MSSYNC_AREA, SPE_MFC_
 
 
 /**
+ * Behavior flags tag status functions
+ */
+#define SPE_TAG_ALL			1
+#define SPE_TAG_ANY			2
+#define SPE_TAG_IMMEDIATE		3
+
+
+/**
  * Flags for _base_spe_context_run
  */
 #define SPE_DEFAULT_ENTRY   UINT_MAX
Index: libspe2/spebase/dma.c
===================================================================
--- libspe2.orig/spebase/dma.c
+++ libspe2/spebase/dma.c
@@ -28,6 +28,9 @@
 #include "create.h"
 #include "dma.h"
 
+static int spe_read_tag_status_block(spe_context_ptr_t spectx, unsigned int *tag_status);
+static int spe_read_tag_status_noblock(spe_context_ptr_t spectx, unsigned int *tag_status);
+
 static int spe_do_mfc_put(spe_context_ptr_t spectx, unsigned src, void *dst,
 			  unsigned size, unsigned tag, unsigned class,
 			  enum mfc_cmd cmd)
@@ -174,50 +177,36 @@ int _base_spe_mfcio_getf(spe_context_ptr
 				tid << 8 | rid, MFC_CMD_GETF);
 }
 
-int _base_spe_mfcio_read_tag_status_all(spe_context_ptr_t spectx, 
-                        unsigned int mask)
+static int spe_mfcio_tag_status_read_all(spe_context_ptr_t spectx, 
+                        unsigned int mask, unsigned int *tag_status)
 {
-	int status = 0;
+	int fd;
 
 	if (spectx->base_private->flags & SPE_MAP_PS) {
 		// fixme
+		errno = ENOTSUP;
 	} else {
-		if ((status = spe_read_tag_status_noblock(spectx)) == -1)
-			return -1;
+		fd = open_if_closed(spectx, FD_MFC);
 
-		while ((status & mask) != mask) {
-			if ((status = spe_read_tag_status_async(spectx)) == -1)
-				return -1;
+		if (fsync(fd) != 0) {
+			return -1;
 		}
 
-	}	
-	return status & mask;
+		return spe_read_tag_status_block(spectx, tag_status);
+	}
+	return -1;
 }
 
-int _base_spe_mfcio_read_tag_status_any(spe_context_ptr_t spectx, unsigned int mask)
+static int spe_mfcio_tag_status_read_any(spe_context_ptr_t spectx,
+					unsigned int mask, unsigned int *tag_status)
 {
-	int status;
-	
-	if ((status = spe_read_tag_status_noblock(spectx)) == -1)
-		return -1;
-
-	while ((status & mask) == 0)
-	{
-		if ((status = spe_read_tag_status_async(spectx)) == -1)
-			return -1;
-	}
-
-	return status & mask;
+	return spe_read_tag_status_block(spectx, tag_status);
 }
 
-int _base_spe_mfcio_read_tag_status_immediate(spe_context_ptr_t spectx, unsigned int mask)
+static int spe_mfcio_tag_status_read_immediate(spe_context_ptr_t spectx,
+						     unsigned int mask, unsigned int *tag_status)
 {
-	int status;
-	
-	if ((status = spe_read_tag_status_noblock(spectx)) == -1)
-		return -1;
-	
-	return  status & mask ;
+	return spe_read_tag_status_noblock(spectx, tag_status);
 }
 
 
@@ -225,49 +214,51 @@ int _base_spe_mfcio_read_tag_status_imme
 /* MFC Read tag status functions
  *
  */
-int spe_read_tag_status_noblock(spe_context_ptr_t spectx)
+static int spe_read_tag_status_block(spe_context_ptr_t spectx, unsigned int *tag_status)
 {
-	int fd, r_read = 0;
-	unsigned int ret;
+	int fd;
 
 	if (spectx->base_private->flags & SPE_MAP_PS) {
 		// fixme
+		errno = ENOTSUP;
 	} else {
 		fd = open_if_closed(spectx, FD_MFC);
 		
-		r_read = read(fd,&ret,4);
-
-		if (r_read == 4) {
-			return ret;
+		if (read(fd,tag_status,4) == 4) {
+			return 0;
 		}
 	}
 	return -1;
 }
 
-int spe_read_tag_status_async(spe_context_ptr_t spectx)
+static int spe_read_tag_status_noblock(spe_context_ptr_t spectx, unsigned int *tag_status)
 {
 	struct pollfd poll_fd;
 	
-	int fd, r_read = 0;
+	int fd;
 	unsigned int ret;
 
 	if (spectx->base_private->flags & SPE_MAP_PS) {
 		// fixme
+		errno = ENOTSUP;
 	} else {
 		fd = open_if_closed(spectx, FD_MFC);
 		
 		poll_fd.fd = fd;
 		poll_fd.events = POLLIN;
 
-		ret = poll(&poll_fd, 1, -1);
+		ret = poll(&poll_fd, 1, 0);
 
-		if (ret < 0 || !(poll_fd.revents | POLLIN))
+		if (ret < 0)
 			return -1;
-	
-		r_read = read(fd,&ret,4);
 
-		if (r_read == 4) {
-			return ret;
+		if (ret == 0 || !(poll_fd.revents | POLLIN)) {
+			*tag_status = 0;
+			return 0;
+		}
+	
+		if (read(fd,tag_status,4) == 4) {
+			return 0;
 		}
 	}
 	return -1;
@@ -275,6 +266,20 @@ int spe_read_tag_status_async(spe_contex
 
 int _base_spe_mfcio_tag_status_read(spe_context_ptr_t spectx, unsigned int mask, unsigned int behavior, unsigned int *tag_status)
 {
-	/*Fixme: Implemantation missing*/
-	return 0;
+	if ( mask != 0 ) {
+		errno = ENOTSUP;
+		return -1;
+	}
+
+	switch (behavior) {
+	case SPE_TAG_ALL:
+		return spe_mfcio_tag_status_read_all(spectx, mask, tag_status);
+	case SPE_TAG_ANY:
+		return spe_mfcio_tag_status_read_any(spectx, mask, tag_status);
+	case SPE_TAG_IMMEDIATE:
+		return spe_mfcio_tag_status_read_immediate(spectx, mask, tag_status);
+	default:
+		errno = EINVAL;
+		return -1;
+	}
 }
Index: libspe2/spebase/dma.h
===================================================================
--- libspe2.orig/spebase/dma.h
+++ libspe2/spebase/dma.h
@@ -25,7 +25,7 @@
 struct mfc_command_parameter_area {
 	unsigned int pad;	/* reserved		 */
 	unsigned int lsa;	/* local storage address */
-	unsigned long ea;	/* effective address	 */
+	unsigned long long ea;	/* effective address	 */
 	unsigned short size;	/* transfer size	 */
 	unsigned short tag;	/* command tag		 */
 	unsigned short class;	/* class ID		 */
@@ -40,7 +40,5 @@ enum mfc_cmd {
 	MFC_CMD_GETB = 0x41,
 	MFC_CMD_GETF = 0x42,
 };
-int spe_read_tag_status_noblock(spe_context_ptr_t spectx);
-int spe_read_tag_status_async(spe_context_ptr_t spectx);
 
 #endif
Index: libspe2/spebase/spebase.h
===================================================================
--- libspe2.orig/spebase/spebase.h
+++ libspe2/spebase/spebase.h
@@ -393,45 +393,6 @@ int _base_spe_mfcio_getf(spe_context_ptr
 			unsigned int rid);
                        
 /**
- * The _base_spe_mfcio_read_tag_status_all function suspends execution until all DMA 
- * commands in the tag groups enabled by the mask parameter have no outstanding 
- * DMAs in the proxy command queue of the SPE thread specified by speid. The 
- * masked tag status is returned.
- * 
- * @param spectx Specifies the SPE thread whose proxy command queue status is to be 
- * read.
- * @param mask Specifies the tag groups to be included in the query or wait operation.
- * @return On success, returns the current tag status. On failure, -1 is returned.
- */
-int _base_spe_mfcio_read_tag_status_all(spe_context_ptr_t spectx, 
-			unsigned int mask);
-
-/**
- * The _base_spe_mfcio_read_tag_status_immediate function returns the tag status for the 
- * tag groups specified by the mask parameter for the proxy command queue of the 
- * SPE thread specified by the speid.
- * 
- * @param spectx Specifies the SPE thread whose proxy command queue status is to be 
- * read.
- * @param mask Specifies the tag groups to be included in the query or wait operation.
- * @return On success, returns the current tag status. On failure, -1 is returned.
- */
-int _base_spe_mfcio_read_tag_status_immediate(spe_context_ptr_t spectx, unsigned int mask);
-
-/**
- * The _base_spe_mfcio_read_tag_status_any function suspends execution until any DMA 
- * commands in the tag groups enabled by the mask parameter have no outstanding 
- * DMAs in the proxy command queue of the SPE thread specified by speid. The masked 
- * tag status is returned.
- * 
- * @param spectx Specifies the SPE thread whose proxy command queue status is to be 
- * read.
- * @param mask Specifies the tag groups to be included in the query or wait operation.
- * @return On success, returns the current tag status. On failure, -1 is returned.
- */
-int _base_spe_mfcio_read_tag_status_any(spe_context_ptr_t spectx, unsigned int mask);
-
-/**
  *        The _base_spe_out_mbox_read function reads the contents of the SPE outbound interrupting
  *        mailbox for the SPE thread speid.
  * 
Index: libspe2/libspe2.c
===================================================================
--- libspe2.orig/libspe2.c
+++ libspe2/libspe2.c
@@ -227,12 +227,7 @@ int spe_mfcio_getf (spe_context_ptr_t sp
 
 int spe_mfcio_tag_status_read(spe_context_ptr_t spe, unsigned int mask, unsigned int behavior, unsigned int *tag_status)
 {
-	if ( mask != 0 ) {
-		errno = ENOTSUP;
-		return -1;
-	} else {
-		return _base_spe_mfcio_tag_status_read(spe, 0, behavior, tag_status);
-	}
+	return _base_spe_mfcio_tag_status_read(spe, mask, behavior, tag_status);
 }
 
 /*


More information about the cbe-oss-dev mailing list