open-src/app/gfx-utils/sun-src/vts/efb/mapper.c
changeset 1368 475ce9398539
parent 1117 629ac4b133bc
equal deleted inserted replaced
1367:f94011dda343 1368:475ce9398539
     1 
       
     2 /*
     1 /*
     3  * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
     4  *
     3  *
     5  * Permission is hereby granted, free of charge, to any person obtaining a
     4  * Permission is hereby granted, free of charge, to any person obtaining a
     6  * copy of this software and associated documentation files (the "Software"),
     5  * copy of this software and associated documentation files (the "Software"),
     7  * to deal in the Software without restriction, including without limitation
     6  * to deal in the Software without restriction, including without limitation
     8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    21  * DEALINGS IN THE SOFTWARE.
    23  */
    22  */
    24 
    23 
    25 #include <sys/types.h>
    24 #include "libvtsSUNWefb.h"	/* Common VTS library definitions */
    26 #include <stdio.h>
    25 #include "efb.h"
    27 #include <sys/mman.h>
       
    28 
    26 
    29 #include "gfx_common.h"		/* GFX Common definitions */
    27 /*
    30 #include "graphicstest.h"
    28  * efb_test_open()
    31 #include "libvtsSUNWefb.h"	/* Common VTS library definitions */
    29  *
       
    30  *    This test will open the device, read and write some registers
       
    31  *    after mmaping in the register and frame buffer spaces.
       
    32  */
    32 
    33 
    33 #include "X11/Xlib.h"
    34 return_packet *
    34 #include "gfx_vts.h"		/* VTS Graphics Test common routines */
    35 efb_test_open(
    35 #include "efb.h"
    36     register int const fd)
       
    37 {
       
    38 	static return_packet rp;
       
    39 	int rc = 0;
       
    40 	struct vis_identifier vis_identifier;
       
    41 
       
    42 	memset(&rp, 0, sizeof (return_packet));
       
    43 
       
    44 	if (gfx_vts_check_fd(fd, &rp))
       
    45 		return (&rp);
       
    46 
       
    47 	TraceMessage(VTS_TEST_STATUS, "efb_test_open", "check_fd passed.\n");
       
    48 
       
    49 	/* vis identifier will do this */
       
    50 	rc = ioctl(fd, VIS_GETIDENTIFIER, &vis_identifier);
       
    51 
       
    52 	TraceMessage(VTS_TEST_STATUS, "efb_test_open", "rc = %d\n", rc);
       
    53 
       
    54 	if (rc != 0) {
       
    55 		gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
       
    56 		return (&rp);
       
    57 	}
       
    58 
       
    59 	if (strncmp(vis_identifier.name, "SUNWefb", 7) != 0 &&
       
    60 	    strncmp(vis_identifier.name, "ORCLefb", 7) != 0) {
       
    61 		gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
       
    62 		return (&rp);
       
    63 	}
       
    64 
       
    65 	efb_block_signals();
       
    66 
       
    67 	efb_lock_display();
       
    68 
       
    69 	map_me(&rp, fd);
       
    70 
       
    71 	efb_unlock_display();
       
    72 
       
    73 	efb_restore_signals();
       
    74 
       
    75 	TraceMessage(VTS_DEBUG, "efb_test_open", "Open completed OK\n");
       
    76 
       
    77 	return (&rp);
       
    78 
       
    79 }	/* efb_test_open() */
    36 
    80 
    37 
    81 
    38 /*
    82 /*
    39  * map_me()
    83  * map_me()
    40  */
    84  */
    41 
    85 
    42 void
    86 int
    43 map_me(return_packet *rp, int fd)
    87 map_me(
       
    88     register return_packet *const rp,
       
    89     register int const fd)
    44 {
    90 {
    45 	struct efb_info  efb_info;
    91 	memset(&efb_info, 0, sizeof (efb_info));
    46 	struct efb_info  *pEFB;
    92 	efb_info.efb_fd = fd;
    47 	unsigned int	 value, chipType;
       
    48 	
       
    49 
    93 
    50 	pEFB = &efb_info;
    94 	if (efb_map_mem(rp, GRAPHICS_ERR_OPEN) != 0)
    51 	pEFB->fd = fd;
    95 		return (-1);
    52 
    96 
    53 	/*
    97 	if (efb_test_semaphore(rp, GRAPHICS_ERR_OPEN) != 0) {
    54 	 * map the registers & frame buffers memory
    98 		efb_unmap_mem(NULL, GRAPHICS_ERR_OPEN);
    55 	 */
    99 		return (-1);
    56 	if (efb_map_mem(pEFB, rp, GRAPHICS_ERR_OPEN) == -1) {
       
    57 	    return;
       
    58 	}
   100 	}
    59 
   101 
    60 done:
       
    61 	/*
   102 	/*
    62 	 * Unmap the registers & frame buffers memory
   103 	 * Unmap the registers & frame buffers memory
    63 	 */
   104 	 */
    64 	if (efb_unmap_mem(pEFB, rp, GRAPHICS_ERR_OPEN) == -1) {
   105 	if (efb_unmap_mem(rp, GRAPHICS_ERR_OPEN) != 0)
    65 	    return;
   106 		return (-1);
    66 	}
       
    67 
   107 
       
   108 	return (0);
    68 }	/* map_me() */
   109 }	/* map_me() */
    69 
   110 
       
   111 #define	RADEON_SW_SEMAPHORE_MASK	0xffff
       
   112 #define	SEMAPHORE_XOR_VALUE		0x5555
       
   113 
       
   114 int
       
   115 efb_test_semaphore(
       
   116     register return_packet *const rp,
       
   117     register int const test)
       
   118 {
       
   119 	register uint_t save_semaphore;
       
   120 	register uint_t new_semaphore;
       
   121 
       
   122 	/*
       
   123 	 * Test the software bits of the semaphore register.
       
   124 	 * Complement the bits, and see if they read back
       
   125 	 * complemented.
       
   126 	 */
       
   127 
       
   128 	/* Save the original semaphore. */
       
   129 
       
   130 	save_semaphore = REGR(RADEON_SW_SEMAPHORE);
       
   131 
       
   132 	/* Write the semaphore with the software bits complemented. */
       
   133 	REGW(RADEON_SW_SEMAPHORE,
       
   134 	    save_semaphore ^ SEMAPHORE_XOR_VALUE);
       
   135 
       
   136 	/* Get the new semaphore. */
       
   137 
       
   138 	new_semaphore = REGR(RADEON_SW_SEMAPHORE);
       
   139 
       
   140 	/* Restore the old semaphore. */
       
   141 
       
   142 	REGW(RADEON_SW_SEMAPHORE, save_semaphore);
       
   143 
       
   144 	/* Check if the software bits did complement. */
       
   145 
       
   146 	if ((save_semaphore & RADEON_SW_SEMAPHORE_MASK) !=
       
   147 	    ((new_semaphore ^ SEMAPHORE_XOR_VALUE) &
       
   148 	    RADEON_SW_SEMAPHORE_MASK)) {
       
   149 		printf("semaphore 0x%08x 0x%08x 0x%08x\n",
       
   150 		    save_semaphore, new_semaphore,
       
   151 		    save_semaphore ^ SEMAPHORE_XOR_VALUE);
       
   152 
       
   153 		gfx_vts_set_message(rp, 1, test, "semaphore test failed");
       
   154 		return (0);
       
   155 	}
       
   156 	return (1);
       
   157 }
    70 
   158 
    71 /* End of mapper.c */
   159 /* End of mapper.c */