1247N/A/*
1247N/A * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
1247N/A *
1247N/A * Permission is hereby granted, free of charge, to any person obtaining a
1247N/A * copy of this software and associated documentation files (the "Software"),
1247N/A * to deal in the Software without restriction, including without limitation
1247N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1247N/A * and/or sell copies of the Software, and to permit persons to whom the
1247N/A * Software is furnished to do so, subject to the following conditions:
1247N/A *
1247N/A * The above copyright notice and this permission notice (including the next
1247N/A * paragraph) shall be included in all copies or substantial portions of the
1247N/A * Software.
1247N/A *
1247N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1247N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1247N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1247N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1247N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1247N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1247N/A * DEALINGS IN THE SOFTWARE.
1247N/A */
1247N/A
1247N/A#include "libvtsSUNWmga.h" /* Common VTS library definitions */
1247N/A
1247N/A/*
1247N/A * mga_test_open()
1247N/A *
1247N/A * This test will open the device, read and write some registers
1247N/A * after mmaping in the register and frame buffer spaces.
1247N/A */
1247N/A
1247N/Areturn_packet *
1247N/Amga_test_open(
1247N/A register int const fd)
1247N/A{
1247N/A static return_packet rp;
1247N/A int rc = 0;
1247N/A struct vis_identifier vis_identifier;
1247N/A
1247N/A memset(&rp, 0, sizeof (return_packet));
1247N/A
1247N/A if (gfx_vts_check_fd(fd, &rp)) {
1247N/A return (&rp);
1247N/A }
1247N/A
1247N/A TraceMessage(VTS_TEST_STATUS, "mga_test_open",
1247N/A "check_fd passed.\n");
1247N/A
1247N/A rc = ioctl(fd, VIS_GETIDENTIFIER, &vis_identifier);
1247N/A
1247N/A TraceMessage(VTS_TEST_STATUS, "mga_test_open",
1247N/A "rc = %d\n", rc);
1247N/A
1247N/A if (rc != 0) {
1247N/A gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
1247N/A return (&rp);
1247N/A }
1247N/A
1247N/A if (strcmp(vis_identifier.name, "SUNWmga") != 0 &&
1247N/A strcmp(vis_identifier.name, "ORCLmga") != 0) {
1247N/A gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
1247N/A return (&rp);
1247N/A }
1247N/A
1247N/A mga_block_signals();
1247N/A
1247N/A mga_lock_display();
1247N/A
1247N/A map_me(&rp, fd);
1247N/A
1247N/A mga_unlock_display();
1247N/A
1247N/A mga_restore_signals();
1247N/A
1247N/A TraceMessage(VTS_DEBUG, "mga_test_open",
1247N/A "Open completed OK\n");
1247N/A
1247N/A return (&rp);
1247N/A
1247N/A}
1247N/A
1247N/A
1247N/Aint
1247N/Amap_me(
1247N/A register return_packet *const rp,
1247N/A register int const fd)
1247N/A{
1247N/A memset(&mga_info, 0, sizeof (mga_info));
1247N/A mga_info.mga_fd = fd;
1247N/A
1247N/A if (mga_map_mem(rp, GRAPHICS_ERR_OPEN) != 0) {
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (mga_init_info(rp, GRAPHICS_ERR_OPEN) != 0) {
1247N/A mga_unmap_mem(NULL, GRAPHICS_ERR_OPEN);
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (mga_test_status(rp, GRAPHICS_ERR_OPEN) != 0) {
1247N/A mga_unmap_mem(NULL, GRAPHICS_ERR_OPEN);
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (!mga_test_cursor(rp, GRAPHICS_ERR_OPEN)) {
1247N/A mga_unmap_mem(NULL, GRAPHICS_ERR_OPEN);
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (!mga_test_dac(rp, GRAPHICS_ERR_OPEN)) {
1247N/A mga_unmap_mem(NULL, GRAPHICS_ERR_OPEN);
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (mga_unmap_mem(rp, GRAPHICS_ERR_OPEN) != 0) {
1247N/A close(fd);
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A if (close(fd) != 0) {
1247N/A gfx_vts_set_message(rp, 1, GRAPHICS_ERR_OPEN,
1247N/A "error closing device\n");
1247N/A return (-1);
1247N/A }
1247N/A
1247N/A return (0);
1247N/A}
1247N/A
1247N/A
1247N/A#define STATUS_XOR_VALUE MGA_STATUS_SWFLAG_MASK
1247N/A
1247N/Aint
1247N/Amga_test_status(
1247N/A register return_packet *const rp,
1247N/A register int const test)
1247N/A{
1247N/A register mga_t volatile *const mgaptr = mga_info.mga_control_ptr;
1247N/A register uint32_t save_status;
1247N/A register uint32_t new_status;
1247N/A
1247N/A /*
1247N/A * Test the software bits of the status register.
1247N/A * Complement the bits, and see if they read back
1247N/A * complemented.
1247N/A */
1247N/A
1247N/A /* Save the original status. */
1247N/A
1247N/A save_status = mga_get_uint32(&mgaptr->mga_status);
1247N/A
1247N/A /* Write the status with the software bits complemented. */
1247N/A
1247N/A mga_put_uint32(&mgaptr->mga_status, save_status ^ STATUS_XOR_VALUE);
1247N/A
1247N/A /* Get the new status. */
1247N/A
1247N/A new_status = mga_get_uint32(&mgaptr->mga_status);
1247N/A
1247N/A /* Restore the old status. */
1247N/A
1247N/A mga_put_uint32(&mgaptr->mga_status, save_status);
1247N/A
1247N/A /* Check if the software bits did complement. */
1247N/A
1247N/A if ((save_status & MGA_STATUS_SWFLAG_MASK) !=
1247N/A ((new_status ^ STATUS_XOR_VALUE) & MGA_STATUS_SWFLAG_MASK)) {
1247N/A printf("status 0x%08lx 0x%08lx 0x%08lx\n",
1247N/A (ulong_t) save_status, (ulong_t) new_status,
1247N/A (ulong_t) save_status ^ STATUS_XOR_VALUE);
1247N/A
1247N/A gfx_vts_set_message(rp, 1, test, "status test failed");
1247N/A return (0);
1247N/A }
1247N/A
1247N/A return (1);
1247N/A}
1247N/A
1247N/A#define MGA_XOR_CURSOR_LOC_HIGH 0x38
1247N/A#define MGA_XOR_CURSOR_LOC_LOW 0xf1
1247N/A
1247N/Aint
1247N/Amga_test_cursor(
1247N/A register return_packet *const rp,
1247N/A register int const test)
1247N/A{
1247N/A register mga_t volatile *const mgaptr = mga_info.mga_control_ptr;
1247N/A register uint8_t save_crtc_index;
1247N/A register uint8_t save_cursor_loc_low;
1247N/A register uint8_t save_cursor_loc_high;
1247N/A register uint8_t new_cursor_loc_low;
1247N/A register uint8_t new_cursor_loc_high;
1247N/A
1247N/A /*
1247N/A * Test the software bits of the crtc cursor registers.
1247N/A * Complement the bits, and see if they read back
1247N/A * complemented.
1247N/A */
1247N/A
1247N/A /* Save the index. */
1247N/A
1247N/A save_crtc_index = mgaptr->mga_crtc_index;
1247N/A
1247N/A /* Save the cursor location. */
1247N/A
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_LOW;
1247N/A save_cursor_loc_low = mgaptr->mga_crtc_data;
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_HIGH;
1247N/A save_cursor_loc_high = mgaptr->mga_crtc_data;
1247N/A
1247N/A /* Write the cursor location with the bits complemented. */
1247N/A
1247N/A mgaptr->mga_crtc_data = save_cursor_loc_high ^
1247N/A MGA_XOR_CURSOR_LOC_HIGH;
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_LOW;
1247N/A mgaptr->mga_crtc_data = save_cursor_loc_low ^
1247N/A MGA_XOR_CURSOR_LOC_LOW;
1247N/A
1247N/A /* Read back the new cursor location. */
1247N/A
1247N/A new_cursor_loc_low = mgaptr->mga_crtc_data;
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_HIGH;
1247N/A new_cursor_loc_high = mgaptr->mga_crtc_data;
1247N/A
1247N/A /* Restore the old cursor location, */
1247N/A
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_LOW;
1247N/A mgaptr->mga_crtc_data = save_cursor_loc_low;
1247N/A mgaptr->mga_crtc_index = MGA_CRTC_CURSOR_LOC_HIGH;
1247N/A mgaptr->mga_crtc_data = save_cursor_loc_high;
1247N/A
1247N/A /* Restore the index */
1247N/A
1247N/A mgaptr->mga_crtc_index = save_crtc_index;
1247N/A
1247N/A if (save_cursor_loc_low !=
1247N/A (new_cursor_loc_low ^ MGA_XOR_CURSOR_LOC_LOW) ||
1247N/A save_cursor_loc_high !=
1247N/A (new_cursor_loc_high ^ MGA_XOR_CURSOR_LOC_HIGH)) {
1247N/A printf("loc 0x%02x 0x%02x 0x%02x, 0x%02x 0x%02x 0x%02x\n",
1247N/A save_cursor_loc_low, new_cursor_loc_low,
1247N/A new_cursor_loc_low ^ MGA_XOR_CURSOR_LOC_LOW,
1247N/A save_cursor_loc_high, new_cursor_loc_high,
1247N/A new_cursor_loc_high ^ MGA_XOR_CURSOR_LOC_HIGH);
1247N/A
1247N/A gfx_vts_set_message(rp, 1, test, "cursor test failed");
1247N/A return (0);
1247N/A }
1247N/A
1247N/A return (1);
1247N/A}
1247N/A
1247N/A
1247N/A#define RED_XOR_VALUE 0x11
1247N/A#define GREEN_XOR_VALUE 0x22
1247N/A#define BLUE_XOR_VALUE 0x44
1247N/A
1247N/Aint
1247N/Amga_test_dac(
1247N/A register return_packet *const rp,
1247N/A register int const test)
1247N/A{
1247N/A register mga_t volatile *const mgaptr = mga_info.mga_control_ptr;
1247N/A register uint8_t save_palwtadd;
1247N/A register uint8_t save_xcurcol15red;
1247N/A register uint8_t save_xcurcol15green;
1247N/A register uint8_t save_xcurcol15blue;
1247N/A register uint8_t new_xcurcol15red;
1247N/A register uint8_t new_xcurcol15green;
1247N/A register uint8_t new_xcurcol15blue;
1247N/A
1247N/A /*
1247N/A * Test the dac by modifying cursor color 15. Complement
1247N/A * some of the bits, and see if they read back
1247N/A * complemented.
1247N/A *
1247N/A */
1247N/A
1247N/A /* Save the original dac index. */
1247N/A
1247N/A save_palwtadd = mgaptr->mga_palwtadd;
1247N/A
1247N/A /* Save cursor 15 red/green/blue palet values. */
1247N/A
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15RED;
1247N/A save_xcurcol15red = mgaptr->mga_x_datareg;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15GREEN;
1247N/A save_xcurcol15green = mgaptr->mga_x_datareg;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15BLUE;
1247N/A save_xcurcol15blue = mgaptr->mga_x_datareg;
1247N/A
1247N/A /* Set cursor 15 red/green/blue values to the complement. */
1247N/A
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15GREEN;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15green ^ GREEN_XOR_VALUE;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15BLUE;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15blue ^ BLUE_XOR_VALUE;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15RED;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15red ^ RED_XOR_VALUE;
1247N/A
1247N/A /* Get the new cursor 15 red/green/blue palet values. */
1247N/A
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15BLUE;
1247N/A new_xcurcol15blue = mgaptr->mga_x_datareg;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15GREEN;
1247N/A new_xcurcol15green = mgaptr->mga_x_datareg;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15RED;
1247N/A new_xcurcol15red = mgaptr->mga_x_datareg;
1247N/A
1247N/A /* Restore the original cursor 15 red/green/blue palet values. */
1247N/A
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15RED;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15red;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15GREEN;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15green;
1247N/A mgaptr->mga_palwtadd = MGA_XDATA_XCURCOL15BLUE;
1247N/A mgaptr->mga_x_datareg = save_xcurcol15blue;
1247N/A
1247N/A /* Restore the original dac index. */
1247N/A
1247N/A mgaptr->mga_palwtadd = save_palwtadd;
1247N/A
1247N/A /* Check if the software bits did complement. */
1247N/A
1247N/A if (save_xcurcol15red != (new_xcurcol15red ^ RED_XOR_VALUE) ||
1247N/A save_xcurcol15green != (new_xcurcol15green ^ GREEN_XOR_VALUE) ||
1247N/A save_xcurcol15blue != (new_xcurcol15blue ^ BLUE_XOR_VALUE)) {
1247N/A printf("red 0x%02x 0x%02x 0x%02x, "
1247N/A "green 0x%02x 0x%02x 0x%02x, "
1247N/A "blue 0x%02x 0x%02x 0x%02x\n",
1247N/A save_xcurcol15red, new_xcurcol15red,
1247N/A new_xcurcol15red ^ RED_XOR_VALUE,
1247N/A save_xcurcol15green, new_xcurcol15green,
1247N/A new_xcurcol15green ^ GREEN_XOR_VALUE,
1247N/A save_xcurcol15blue, new_xcurcol15blue,
1247N/A new_xcurcol15blue ^BLUE_XOR_VALUE);
1247N/A
1247N/A gfx_vts_set_message(rp, 1, test, "dac test failed");
1247N/A return (0);
1247N/A }
1247N/A
1247N/A return (1);
1247N/A}