<commit_before>#include <cstdio>
#include <functional>
#include <glut.h>

double eyeX, eyeY, eyeZ, centerX, centerY, centerZ;
double x = 1.0, y = 1.0, z = 0.0;

void timer(int v) {
	x += 0.3;
	y += 0.3;
	z += 0.3;
	glutTimerFunc(1000, timer, 1);
	glutPostRedisplay();
}

void wall(double thickness){
    glPushMatrix();
    glTranslated(0.5, 0.5*thickness, 0.5);
    glScaled(1.0, thickness, 1.0);
    glutSolidCube(1);
    glPopMatrix();
}
void house(double size)
{
    // Drawing the walls
    wall(size);
    glPushMatrix();
    glRotated(90.0, 0.0, 0.0, 1.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glRotated(-90.0, 1.0, 0.0, 0.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(0.0, 1.0 - 0.02, 0.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(1.0, 0.0, 0.0);
    glRotated(90.0, 0.0, 0.0, 1.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(0.0, 0.0, 1.0);
    glRotated(-90.0, 1.0, 0.0, 0.0);
    wall(size);
    glPopMatrix();
    // Drawing the roof
    glPushMatrix();
    glTranslated(0.5, 1.0, 0.5);
    glRotated(-90, 1, 0, 0);
    glRotated(45, 0, 0, 1);
    glutSolidCone(0.9, 0.5, 4, 9);
    glPopMatrix();
}
void displayWire(void)
{
    //set the world
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    double winHt = 5.0;
    gluPerspective(60, 1, 0.1, 100);

    //set the camera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	glTranslated(x, y, z);
	glutWireSphere(0.15, 10, 10);
	glPopMatrix();

	house(0.02);
    // Drawing the first row
    glPushMatrix();
    for (int i = 0; i<5; i++){
        glTranslated(1.5, 0.0, 0.0);
        house(0.02);
    }
    glPopMatrix();
    // Drawing the second row
    glPushMatrix();
    glTranslated(0, 0, 5);
    house(0.02);
    for (int j = 0; j<5; j++){
        glTranslated(1.5, 0.0, 0.0);
        house(0.02);
    }
    glPopMatrix();
    glFlush();
}
void mySpecial(int key, int x, int y)
{
    switch (key){

    }

    glutPostRedisplay();
}

int print(int x){
    printf("%d\n", x);
    return 1;
}

void* pass(int (*f)(int)){

    std::function<int()> g = [f](){
        printf("%d\n", f(2));
        return 1;
    };
    if(g() == 1){
        return (void*) &"123";
    }
    else{
        return nullptr;
    }
}

int main(int argc, char** argv)
{
    printf("%s\n", (char*)pass(print));
    glutInit(&argc, argv); // initialize the toolkit
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); // set
    //display mode
    glutInitWindowSize(640, 480); // set window size
    glutInitWindowPosition(200, 150); // set window position on
    //screen
    glutCreateWindow("Colored Dots"); // open the screen window
    glutDisplayFunc(displayWire); // register redraw function
    glutSpecialFunc(mySpecial);
	glutTimerFunc(1, timer, 1);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glClearColor(1.0, 1.0, 1.0, 0.0);
    eyeX = 0.5;
    eyeY = 10;
    eyeZ = 8;
    centerX = 10.0;
    centerY = 1;
    centerZ = 0.0;
    //set the light source properties
    GLfloat lightIntensity[] = { 0.7f, 0.7f, 1, 1.0f };
    GLfloat light_position[] = { 7.0f, 6.0f, 3.0f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);
    glutMainLoop(); // go into a perpetual loop
    return 0;
}<commit_msg>Changed window title<commit_after>#include <cstdio>
#include <functional>
#include <glut.h>

double eyeX, eyeY, eyeZ, centerX, centerY, centerZ;
double x = 1.0, y = 1.0, z = 0.0;

void timer(int v) {
	x += 0.3;
	y += 0.3;
	z += 0.3;
	glutTimerFunc(1000, timer, 1);
	glutPostRedisplay();
}

void wall(double thickness){
    glPushMatrix();
    glTranslated(0.5, 0.5*thickness, 0.5);
    glScaled(1.0, thickness, 1.0);
    glutSolidCube(1);
    glPopMatrix();
}
void house(double size)
{
    // Drawing the walls
    wall(size);
    glPushMatrix();
    glRotated(90.0, 0.0, 0.0, 1.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glRotated(-90.0, 1.0, 0.0, 0.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(0.0, 1.0 - 0.02, 0.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(1.0, 0.0, 0.0);
    glRotated(90.0, 0.0, 0.0, 1.0);
    wall(size);
    glPopMatrix();
    glPushMatrix();
    glTranslated(0.0, 0.0, 1.0);
    glRotated(-90.0, 1.0, 0.0, 0.0);
    wall(size);
    glPopMatrix();
    // Drawing the roof
    glPushMatrix();
    glTranslated(0.5, 1.0, 0.5);
    glRotated(-90, 1, 0, 0);
    glRotated(45, 0, 0, 1);
    glutSolidCone(0.9, 0.5, 4, 9);
    glPopMatrix();
}
void displayWire(void)
{
    //set the world
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    double winHt = 5.0;
    gluPerspective(60, 1, 0.1, 100);

    //set the camera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	glTranslated(x, y, z);
	glutWireSphere(0.15, 10, 10);
	glPopMatrix();

	house(0.02);
    // Drawing the first row
    glPushMatrix();
    for (int i = 0; i<5; i++){
        glTranslated(1.5, 0.0, 0.0);
        house(0.02);
    }
    glPopMatrix();
    // Drawing the second row
    glPushMatrix();
    glTranslated(0, 0, 5);
    house(0.02);
    for (int j = 0; j<5; j++){
        glTranslated(1.5, 0.0, 0.0);
        house(0.02);
    }
    glPopMatrix();
    glFlush();
}
void mySpecial(int key, int x, int y)
{
    switch (key){

    }

    glutPostRedisplay();
}

int print(int x){
    printf("%d\n", x);
    return 1;
}

void* pass(int (*f)(int)){

    std::function<int()> g = [f](){
        printf("%d\n", f(2));
        return 1;
    };
    if(g() == 1){
        return (void*) &"123";
    }
    else{
        return nullptr;
    }
}

int main(int argc, char** argv)
{
    printf("%s\n", (char*)pass(print));
    glutInit(&argc, argv); // initialize the toolkit
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); // set
    //display mode
    glutInitWindowSize(640, 480); // set window size
    glutInitWindowPosition(200, 150); // set window position on
    //screen
    glutCreateWindow("Bouncy"); // open the screen window
    glutDisplayFunc(displayWire); // register redraw function
    glutSpecialFunc(mySpecial);
	glutTimerFunc(1, timer, 1);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glClearColor(1.0, 1.0, 1.0, 0.0);
    eyeX = 0.5;
    eyeY = 10;
    eyeZ = 8;
    centerX = 10.0;
    centerY = 1;
    centerZ = 0.0;
    //set the light source properties
    GLfloat lightIntensity[] = { 0.7f, 0.7f, 1, 1.0f };
    GLfloat light_position[] = { 7.0f, 6.0f, 3.0f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);
    glutMainLoop(); // go into a perpetual loop
    return 0;
}<|endoftext|>


<commit_before>void geom_cms_playback()
{
   TRecorder r("http://mtadel.home.cern.ch/mtadel/geom_cms_recording.root");
}
<commit_msg>Use new instead of normal constructor for TRecorder.<commit_after>void geom_cms_playback()
{
   TRecorder* r = new TRecorder("http://mtadel.home.cern.ch/mtadel/geom_cms_recording.root");
}
<|endoftext|>


<commit_before>#include "Halide.h"
#include "wrapper_tutorial_02.h"
#include "halide_image_io.h"
#include <cstdlib>
#include <iostream>

#define NN 10

void print_array(buffer_t buf, int N, int M)
{
	int i,j;

	for (i=0; i<N; i++)
	{
		for (j=0; j<M; j++)
		{
			printf("%u, ", buf.host[i*M+j]);
		}
		printf("\n");
	}
	printf("\n");
}

void init_array_val(buffer_t *buf, int N, int M, uint8_t val)
{
	int i, j;

	for (i=0; i<N; i++)
		for (j=0; j<M; j++)
			buf->host[i*M+j] = val;
}

void copy_array(uint8_t* buf, int N, int M, uint8_t* array)
{
	int i, j;

	for (i=0; i<N; i++)
		for (j=0; j<M; j++)
			buf[i*M+j] = array[i*M+j];
}

int main(int, char**)
{
   Halide::Image<uint8_t> image = Halide::Tools::load_image("./tutorials/images/rgb.png");

   buffer_t input_buf = {0};
   input_buf.host = (unsigned char *) malloc(image.extent(0)*image.extent(1)*sizeof(unsigned char));
   input_buf.stride[0] = 1;
   input_buf.stride[1] = image.extent(0);
   input_buf.extent[0] = image.extent(0);
   input_buf.extent[1] = image.extent(1);
   input_buf.min[0] = 0;
   input_buf.min[1] = 0;
   input_buf.elem_size = 1;

   buffer_t output_buf = {0};
   output_buf.host = (unsigned char *) malloc(image.extent(0)*image.extent(1)*sizeof(unsigned char));
   output_buf.stride[0] = 1;
   output_buf.stride[1] = image.extent(0);
   output_buf.extent[0] = image.extent(0);
   output_buf.extent[1] = image.extent(1);
   output_buf.min[0] = 0;
   output_buf.min[1] = 0;
   output_buf.elem_size = 1;

   copy_array(input_buf.host, image.extent(0), image.extent(1), image.data());

   blurxy(&input_buf, &output_buf);

   copy_array(image.data(), image.extent(0), image.extent(1), output_buf.host);

   Halide::Tools::save_image(image, "tutorial_02.png");

   return 0;
}
<commit_msg>Enhance tutorial_02<commit_after>#include "Halide.h"
#include "wrapper_tutorial_02.h"
#include "halide_image_io.h"
#include <cstdlib>
#include <iostream>

#define NN 10

void print_array(buffer_t buf, int N, int M)
{
	int i,j;

	for (i=0; i<N; i++)
	{
		for (j=0; j<M; j++)
		{
			printf("%u, ", buf.host[i*M+j]);
		}
		printf("\n");
	}
	printf("\n");
}

void init_array_val(buffer_t *buf, int N, int M, uint8_t val)
{
	int i, j;

	for (i=0; i<N; i++)
		for (j=0; j<M; j++)
			buf->host[i*M+j] = val;
}

void copy_array(uint8_t* buf, int N, int M, uint8_t* array)
{
	int i, j;

	for (i=0; i<N; i++)
		for (j=0; j<M; j++)
			buf[i*M+j] = array[i*M+j];
}

int main(int, char**)
{
   Halide::Image<uint8_t> image = Halide::Tools::load_image("./tutorials/images/rgb.png");

   buffer_t input_buf = {0};
   input_buf.host = (unsigned char *) image.data();
   input_buf.stride[0] = 1;
   input_buf.stride[1] = image.extent(0);
   input_buf.extent[0] = image.extent(0);
   input_buf.extent[1] = image.extent(1);
   input_buf.min[0] = 0;
   input_buf.min[1] = 0;
   input_buf.elem_size = 1;

   buffer_t output_buf = {0};
   output_buf.host = (unsigned char *) malloc(image.extent(0)*image.extent(1)*sizeof(unsigned char));
   output_buf.stride[0] = 1;
   output_buf.stride[1] = image.extent(0);
   output_buf.extent[0] = image.extent(0);
   output_buf.extent[1] = image.extent(1);
   output_buf.min[0] = 0;
   output_buf.min[1] = 0;
   output_buf.elem_size = 1;

   blurxy(&input_buf, &output_buf);

   copy_array(image.data(), image.extent(0), image.extent(1), output_buf.host);

   Halide::Tools::save_image(image, "tutorial_02.png");

   return 0;
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/io/p9_io_xbus_pdwn_lanes.C $          */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_io_xbus_pdwn_lanes.C
/// @brief P9 Xbus Power Down Lanes.
///----------------------------------------------------------------------------
/// *HWP HWP Owner        : Chris Steffen <cwsteffen@us.ibm.com>
/// *HWP HWP Backup Owner : Gary Peterson <garyp@us.ibm.com>
/// *HWP FW Owner         : Jamie Knight <rjknight@us.ibm.com>
/// *HWP Team             : IO
/// *HWP Level            : 2
/// *HWP Consumed by      : FSP:HB
///----------------------------------------------------------------------------
///
/// @verbatim
/// High-level procedure flow:
///
/// A HWP that powers down lanes.  This procedure should power down rx lanes,
///   tx lanes, or both rx & tx lanes.
///
/// Procedure Prereq:
///     - System clocks are running.
///
/// @endverbatim
///----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
#include "p9_io_xbus_pdwn_lanes.H"
#include "p9_io_scom.H"
#include "p9_io_regs.H"

// ----------------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------------
fapi2::ReturnCode rx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t i_clock_group,
    const std::vector< uint8_t >& i_bad_lanes);
fapi2::ReturnCode tx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t i_clock_group,
    const std::vector< uint8_t >& i_bad_lanes);

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The rx & tx lanes in the vectors will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_group         Clock Group of Target
 * @param[in] i_rx_bad_lanes  Vector of Rx Bad Lanes
 * @param[in] i_tx_bad_lanes  Vector of Tx Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode p9_io_xbus_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_group,
    const std::vector< uint8_t >&                   i_rx_bad_lanes,
    const std::vector< uint8_t >&                   i_tx_bad_lanes)
{
    FAPI_IMP("Entering...");

    FAPI_DBG("Rx Bad Lanes Size: %d", i_rx_bad_lanes.size());

    if( !i_rx_bad_lanes.empty() )
    {
        FAPI_TRY(rx_pdwn_lanes( i_target, i_group, i_rx_bad_lanes),
                 "Rx Power Down Lanes Failed");
    }

    FAPI_DBG("Tx Bad Lanes Size: %d", i_tx_bad_lanes.size());

    if( !i_tx_bad_lanes.empty() )
    {
        FAPI_TRY(tx_pdwn_lanes( i_target, i_group, i_tx_bad_lanes),
                 "Tx Power Down Lanes Failed");
    }

fapi_try_exit:
    FAPI_IMP("Exiting...");
    return fapi2::current_err;
}

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The rx lanes in the vector will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_clock_group   Clock Group of Target
 * @param[in] i_bad_lanes     Vector of Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode rx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_clock_group,
    const std::vector< uint8_t >&                   i_bad_lanes )
{
    FAPI_DBG( "rx_pdwn_lanes: Enter Size(%d)", i_bad_lanes.size() );
    char target_string[fapi2::MAX_ECMD_STRING_LEN];
    fapi2::toString( i_target, target_string, fapi2::MAX_ECMD_STRING_LEN );

    if( !i_bad_lanes.empty() )
    {
        for( uint8_t index = 0; index < i_bad_lanes.size(); ++index )
        {
            FAPI_DBG("Powering Down Rx Lane[%d/%d]: Target(%s:g%d:l%d)",
                     index,
                     i_bad_lanes.size() - 1,
                     target_string,
                     i_clock_group,
                     i_bad_lanes[index] );

            FAPI_TRY( io::rmw( EDIP_RX_LANE_DIG_PDWN, i_target, i_clock_group, i_bad_lanes[index], 1 ),
                      "Failed rmw rx dig pdwn reg" );

            FAPI_TRY( io::rmw( EDIP_RX_LANE_ANA_PDWN, i_target, i_clock_group, i_bad_lanes[index], 1 ),
                      "Failed rmw rx ana pdwn reg" );

        }
    }

fapi_try_exit:
    FAPI_IMP( "rx_pdwn_lanes: Exiting." );
    return fapi2::current_err;
}

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The tx lanes in the vector will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_group         Clock Group of Target
 * @param[in] i_bad_lanes     Vector of Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode tx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_group,
    const std::vector< uint8_t >&                   i_bad_lanes )
{
    FAPI_IMP( "tx_pdwn_lanes: Enter Size(%d)", i_bad_lanes.size() );
    const uint8_t LANE_00 = 0;
    uint8_t l_msbswap = 0;
    uint8_t l_end_lane = 0;
    uint8_t l_lane = 0;
    uint64_t l_data = 0;
    char target_string[fapi2::MAX_ECMD_STRING_LEN];
    fapi2::toString( i_target, target_string, fapi2::MAX_ECMD_STRING_LEN );

    if( !i_bad_lanes.empty() )
    {
        FAPI_TRY( io::read( EDIP_TX_MSBSWAP, i_target, i_group, LANE_00, l_data ),
                  "Failed read edip_tx_msbswap");
        l_msbswap = io::get(EDIP_TX_MSBSWAP, l_data );

        if( l_msbswap == 0x1 )
        {
            FAPI_TRY( io::read( EDIP_TX_END_LANE_ID, i_target, i_group, LANE_00, l_data ),
                      "Failed read edip_tx_end_lane_id");
            l_end_lane = io::get(EDIP_TX_END_LANE_ID, l_data );
            FAPI_DBG( "edip_tx_msbswap: tx_end_lane_id(%d).", l_end_lane );
        }

        for(uint8_t index = 0; index < i_bad_lanes.size(); ++index )
        {
            l_lane = i_bad_lanes[index];

            if( l_msbswap == 0x1 )
            {
                l_lane = l_end_lane - i_bad_lanes[index];
                FAPI_DBG( "edip_tx_msbswap: tx_end_lane_id(%d) lane(%d -> %d).",
                          l_end_lane, i_bad_lanes[index], l_lane );
            }

            FAPI_DBG("Powering Down Tx Lane[%d/%d]: Target(%s:g%d:l%d)",
                     index,
                     i_bad_lanes.size() - 1,
                     target_string,
                     i_group,
                     l_lane );

            FAPI_TRY( io::rmw( EDIP_TX_LANE_PDWN, i_target, i_group, l_lane, 1 ),
                      "Failed rmw tx pdwn");

        }
    }

fapi_try_exit:
    FAPI_IMP( "tx_pdwn_lanes: Exiting" );
    return fapi2::current_err;
}
<commit_msg>Update p9_io_xbus_pdwn_lanes.C local functions<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/io/p9_io_xbus_pdwn_lanes.C $          */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_io_xbus_pdwn_lanes.C
/// @brief P9 Xbus Power Down Lanes.
///----------------------------------------------------------------------------
/// *HWP HWP Owner        : Chris Steffen <cwsteffen@us.ibm.com>
/// *HWP HWP Backup Owner : Gary Peterson <garyp@us.ibm.com>
/// *HWP FW Owner         : Jamie Knight <rjknight@us.ibm.com>
/// *HWP Team             : IO
/// *HWP Level            : 2
/// *HWP Consumed by      : FSP:HB
///----------------------------------------------------------------------------
///
/// @verbatim
/// High-level procedure flow:
///
/// A HWP that powers down lanes.  This procedure should power down rx lanes,
///   tx lanes, or both rx & tx lanes.
///
/// Procedure Prereq:
///     - System clocks are running.
///
/// @endverbatim
///----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
#include "p9_io_xbus_pdwn_lanes.H"
#include "p9_io_scom.H"
#include "p9_io_regs.H"

// ----------------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------------
fapi2::ReturnCode rx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group,
    const std::vector< uint8_t >& i_bad_lanes);
fapi2::ReturnCode tx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group,
    const std::vector< uint8_t >& i_bad_lanes);

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The rx & tx lanes in the vectors will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_group         Clock Group of Target
 * @param[in] i_rx_bad_lanes  Vector of Rx Bad Lanes
 * @param[in] i_tx_bad_lanes  Vector of Tx Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode p9_io_xbus_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_group,
    const std::vector< uint8_t >&                   i_rx_bad_lanes,
    const std::vector< uint8_t >&                   i_tx_bad_lanes)
{
    FAPI_IMP("Entering...");

    FAPI_DBG("Rx Bad Lanes Size: %d", i_rx_bad_lanes.size());

    if( !i_rx_bad_lanes.empty() )
    {
        FAPI_TRY(rx_pdwn_lanes( i_target, i_group, i_rx_bad_lanes),
                 "Rx Power Down Lanes Failed");
    }

    FAPI_DBG("Tx Bad Lanes Size: %d", i_tx_bad_lanes.size());

    if( !i_tx_bad_lanes.empty() )
    {
        FAPI_TRY(tx_pdwn_lanes( i_target, i_group, i_tx_bad_lanes),
                 "Tx Power Down Lanes Failed");
    }

fapi_try_exit:
    FAPI_IMP("Exiting...");
    return fapi2::current_err;
}

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The rx lanes in the vector will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_clock_group   Clock Group of Target
 * @param[in] i_bad_lanes     Vector of Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode rx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_clock_group,
    const std::vector< uint8_t >&                   i_bad_lanes )
{
    FAPI_DBG( "rx_pdwn_lanes: Enter Size(%d)", i_bad_lanes.size() );
    char target_string[fapi2::MAX_ECMD_STRING_LEN];
    fapi2::toString( i_target, target_string, fapi2::MAX_ECMD_STRING_LEN );

    if( !i_bad_lanes.empty() )
    {
        for( uint8_t index = 0; index < i_bad_lanes.size(); ++index )
        {
            FAPI_DBG("Powering Down Rx Lane[%d/%d]: Target(%s:g%d:l%d)",
                     index,
                     i_bad_lanes.size() - 1,
                     target_string,
                     i_clock_group,
                     i_bad_lanes[index] );

            FAPI_TRY( io::rmw( EDIP_RX_LANE_DIG_PDWN, i_target, i_clock_group, i_bad_lanes[index], 1 ),
                      "Failed rmw rx dig pdwn reg" );

            FAPI_TRY( io::rmw( EDIP_RX_LANE_ANA_PDWN, i_target, i_clock_group, i_bad_lanes[index], 1 ),
                      "Failed rmw rx ana pdwn reg" );

        }
    }

fapi_try_exit:
    FAPI_IMP( "rx_pdwn_lanes: Exiting." );
    return fapi2::current_err;
}

/**
 * @brief A HWP that powers down the specified lanes on a given EDI+ Xbus
 *   target.  The tx lanes in the vector will be powered down on the
 *   given target.  Note: This procedure does not power down any lanes on the
 *   connected target of the link.
 * @param[in] i_target        FAPI2 Target
 * @param[in] i_group         Clock Group of Target
 * @param[in] i_bad_lanes     Vector of Bad Lanes
 * @retval ReturnCode
 */
fapi2::ReturnCode tx_pdwn_lanes(
    const fapi2::Target< fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                  i_group,
    const std::vector< uint8_t >&                   i_bad_lanes )
{
    FAPI_IMP( "tx_pdwn_lanes: Enter Size(%d)", i_bad_lanes.size() );
    const uint8_t LANE_00 = 0;
    uint8_t l_msbswap = 0;
    uint8_t l_end_lane = 0;
    uint8_t l_lane = 0;
    uint64_t l_data = 0;
    char target_string[fapi2::MAX_ECMD_STRING_LEN];
    fapi2::toString( i_target, target_string, fapi2::MAX_ECMD_STRING_LEN );

    if( !i_bad_lanes.empty() )
    {
        FAPI_TRY( io::read( EDIP_TX_MSBSWAP, i_target, i_group, LANE_00, l_data ),
                  "Failed read edip_tx_msbswap");
        l_msbswap = io::get(EDIP_TX_MSBSWAP, l_data );

        if( l_msbswap == 0x1 )
        {
            FAPI_TRY( io::read( EDIP_TX_END_LANE_ID, i_target, i_group, LANE_00, l_data ),
                      "Failed read edip_tx_end_lane_id");
            l_end_lane = io::get(EDIP_TX_END_LANE_ID, l_data );
            FAPI_DBG( "edip_tx_msbswap: tx_end_lane_id(%d).", l_end_lane );
        }

        for(uint8_t index = 0; index < i_bad_lanes.size(); ++index )
        {
            l_lane = i_bad_lanes[index];

            if( l_msbswap == 0x1 )
            {
                l_lane = l_end_lane - i_bad_lanes[index];
                FAPI_DBG( "edip_tx_msbswap: tx_end_lane_id(%d) lane(%d -> %d).",
                          l_end_lane, i_bad_lanes[index], l_lane );
            }

            FAPI_DBG("Powering Down Tx Lane[%d/%d]: Target(%s:g%d:l%d)",
                     index,
                     i_bad_lanes.size() - 1,
                     target_string,
                     i_group,
                     l_lane );

            FAPI_TRY( io::rmw( EDIP_TX_LANE_PDWN, i_target, i_group, l_lane, 1 ),
                      "Failed rmw tx pdwn");

        }
    }

fapi_try_exit:
    FAPI_IMP( "tx_pdwn_lanes: Exiting" );
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>// Copyright (c) 2011, Cornell University
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of HyperDex nor the names of its contributors may be
//       used to endorse or promote products derived from this software without
//       specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

// POSIX
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>

// C++
#include <iostream>

// STL
#include <sstream>
#include <tr1/functional>
#include <tr1/memory>

// Google Log
#include <glog/logging.h>

// Libev
#include <ev++.h>

// po6
#include <po6/threads/thread.h>

// e
#include <e/guard.h>
#include <e/timer.h>

// HyperDex
#include <hyperdex/datalayer.h>
#include <hyperdex/logical.h>
#include <hyperdex/hyperdexd.h>
#include <hyperdex/instance.h>
#include <hyperdex/masterlink.h>
#include <hyperdex/network_worker.h>
#include <hyperdex/replication.h>

typedef std::tr1::shared_ptr<po6::threads::thread> thread_ptr;

#define NUM_THREADS 64

class hyperdexd_install_mapping
{
    public:
        hyperdexd_install_mapping(hyperdex::datalayer* data,
                                  hyperdex::logical* comm,
                                  hyperdex::replication* repl)
            : m_data(data)
            , m_comm(comm)
            , m_repl(repl)
        {
        }

    public:
        void operator () (const hyperdex::configuration& config)
        {
            using hyperdex::configuration;

            // Prepare for our new configuration.
            // These operations should assume that there will be network
            // activity, and that the network threads will be in full force..
            m_comm->prepare(config);
            m_data->prepare(config, m_comm->inst());
            m_repl->prepare(config, m_comm->inst());

            // Reconfigure to the new configuration.
            // These operations may assume that there will be no network
            // activity.
            e::guard g = e::makeobjguard(*m_comm, &hyperdex::logical::unpause);
            LOG(INFO) << "Pausing communication to reconfigure.";
            m_comm->pause();

            // Make sure that we wait until everyone is paused.
            while (m_comm->num_paused() < NUM_THREADS)
            {
                e::sleep_ms(10);
            }

            __sync_synchronize();

            m_comm->reconfigure(config);
            m_data->reconfigure(config, m_comm->inst());
            m_repl->reconfigure(config, m_comm->inst());

            __sync_synchronize();

            m_comm->unpause();
            LOG(INFO) << "Reconfiguration complete; unpausing communication.";
            g.dismiss();

            // Cleanup anything not specified by our new configuration.
            // These operations should assume that there will be network
            m_repl->cleanup(config, m_comm->inst());
            m_data->cleanup(config, m_comm->inst());
            m_comm->cleanup(config);
        }

    private:
        hyperdex::datalayer* m_data;
        hyperdex::logical* m_comm;
        hyperdex::replication* m_repl;
};

hyperdex :: hyperdexd :: hyperdexd()
    : m_continue(true)
{
}

hyperdex :: hyperdexd :: ~hyperdexd()
{
}

void
hyperdex :: hyperdexd :: run()
{
    // Setup HyperDex.
    ev::default_loop dl;
    // Catch signals.
    ev::sig sighup(dl);
    sighup.set<hyperdexd, &hyperdexd::HUP>(this);
    sighup.set(SIGHUP);
    sighup.start();
    ev::sig sigint(dl);
    sigint.set<hyperdexd, &hyperdexd::INT>(this);
    sigint.set(SIGINT);
    sigint.start();
    ev::sig sigquit(dl);
    sigquit.set<hyperdexd, &hyperdexd::QUIT>(this);
    sigquit.set(SIGQUIT);
    sigquit.start();
    ev::sig sigterm(dl);
    sigterm.set<hyperdexd, &hyperdexd::TERM>(this);
    sigterm.set(SIGTERM);
    sigterm.start();
    ev::sig sigusr1(dl);
    sigusr1.set<hyperdexd, &hyperdexd::USR1>(this);
    sigusr1.set(SIGUSR1);
    sigusr1.start();
    ev::sig sigusr2(dl);
    sigusr2.set<hyperdexd, &hyperdexd::USR2>(this);
    sigusr2.set(SIGUSR2);
    sigusr2.start();
    // Setup the data layer.
    hyperdex::datalayer data;
    // Setup the communications layer.
    hyperdex::logical comm(dl, "127.0.0.1"); // XXX don't hardcode localhost
    // Setup the replication layer.
    hyperdex::replication repl(&data, &comm);
    // Setup the link with the master.
    std::ostringstream ostr;
    ostr << "instance\t" << comm.inst().inbound << "\t"
                         << comm.inst().outbound
                         << "\n";
    hyperdex::masterlink ml(po6::net::location("127.0.0.1", 1234),
                            ostr.str(),
                            hyperdexd_install_mapping(&data, &comm, &repl));
    // Start the network_worker threads.
    hyperdex::network_worker nw(&data, &comm, &repl);
    std::tr1::function<void (hyperdex::network_worker*)> fnw(&hyperdex::network_worker::run);
    std::vector<thread_ptr> threads;

    for (size_t i = 0; i < NUM_THREADS; ++i)
    {
        thread_ptr t(new po6::threads::thread(std::tr1::bind(fnw, &nw)));
        t->start();
        threads.push_back(t);
    }

    while (m_continue)
    {
        try
        {
            dl.loop(EVLOOP_ONESHOT);
        }
        catch (std::exception& e)
        {
            LOG(INFO) << "Uncaught exception in event loop: " << e.what();
        }
    }

    // Cleanup HyperDex.
    //
    // XXX This is not proper network procedure.  A proper shutdown is:
    //  - The server receives the shutdown notice.
    //  - Every row leader agrees not to accept more updates.
    //  - Every row leader notifies the master when stable.
    //  - All instances flush to disk.
    //  - All instances terminate.
    //
    // Turn off the network.
    comm.shutdown();
    // Cleanup the network_worker threads.
    nw.shutdown();
    // Cleanup the master thread.
    ml.shutdown();

    for (std::vector<thread_ptr>::iterator t = threads.begin();
            t != threads.end(); ++t)
    {
        (*t)->join();
    }
}

void
hyperdex :: hyperdexd :: HUP(ev::sig&, int)
{
    LOG(ERROR) << "SIGHUP received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: INT(ev::sig&, int)
{
    LOG(ERROR) << "SIGINT received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: QUIT(ev::sig&, int)
{
    LOG(ERROR) << "SIGQUIT received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: TERM(ev::sig&, int)
{
    LOG(ERROR) << "SIGTERM received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: USR1(ev::sig&, int)
{
    LOG(INFO) << "SIGUSR1 received.  This does nothing.";
}

void
hyperdex :: hyperdexd :: USR2(ev::sig&, int)
{
    LOG(INFO) << "SIGUSR2 received.  This does nothing.";
}
<commit_msg>Shutdown repl and data layers in hyperdexd.<commit_after>// Copyright (c) 2011, Cornell University
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of HyperDex nor the names of its contributors may be
//       used to endorse or promote products derived from this software without
//       specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

// POSIX
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>

// C++
#include <iostream>

// STL
#include <sstream>
#include <tr1/functional>
#include <tr1/memory>

// Google Log
#include <glog/logging.h>

// Libev
#include <ev++.h>

// po6
#include <po6/threads/thread.h>

// e
#include <e/guard.h>
#include <e/timer.h>

// HyperDex
#include <hyperdex/datalayer.h>
#include <hyperdex/logical.h>
#include <hyperdex/hyperdexd.h>
#include <hyperdex/instance.h>
#include <hyperdex/masterlink.h>
#include <hyperdex/network_worker.h>
#include <hyperdex/replication.h>

typedef std::tr1::shared_ptr<po6::threads::thread> thread_ptr;

#define NUM_THREADS 64

class hyperdexd_install_mapping
{
    public:
        hyperdexd_install_mapping(hyperdex::datalayer* data,
                                  hyperdex::logical* comm,
                                  hyperdex::replication* repl)
            : m_data(data)
            , m_comm(comm)
            , m_repl(repl)
        {
        }

    public:
        void operator () (const hyperdex::configuration& config)
        {
            using hyperdex::configuration;

            // Prepare for our new configuration.
            // These operations should assume that there will be network
            // activity, and that the network threads will be in full force..
            m_comm->prepare(config);
            m_data->prepare(config, m_comm->inst());
            m_repl->prepare(config, m_comm->inst());

            // Reconfigure to the new configuration.
            // These operations may assume that there will be no network
            // activity.
            e::guard g = e::makeobjguard(*m_comm, &hyperdex::logical::unpause);
            LOG(INFO) << "Pausing communication to reconfigure.";
            m_comm->pause();

            // Make sure that we wait until everyone is paused.
            while (m_comm->num_paused() < NUM_THREADS)
            {
                e::sleep_ms(10);
            }

            __sync_synchronize();

            m_comm->reconfigure(config);
            m_data->reconfigure(config, m_comm->inst());
            m_repl->reconfigure(config, m_comm->inst());

            __sync_synchronize();

            m_comm->unpause();
            LOG(INFO) << "Reconfiguration complete; unpausing communication.";
            g.dismiss();

            // Cleanup anything not specified by our new configuration.
            // These operations should assume that there will be network
            m_repl->cleanup(config, m_comm->inst());
            m_data->cleanup(config, m_comm->inst());
            m_comm->cleanup(config);
        }

    private:
        hyperdex::datalayer* m_data;
        hyperdex::logical* m_comm;
        hyperdex::replication* m_repl;
};

hyperdex :: hyperdexd :: hyperdexd()
    : m_continue(true)
{
}

hyperdex :: hyperdexd :: ~hyperdexd()
{
}

void
hyperdex :: hyperdexd :: run()
{
    // Setup HyperDex.
    ev::default_loop dl;
    // Catch signals.
    ev::sig sighup(dl);
    sighup.set<hyperdexd, &hyperdexd::HUP>(this);
    sighup.set(SIGHUP);
    sighup.start();
    ev::sig sigint(dl);
    sigint.set<hyperdexd, &hyperdexd::INT>(this);
    sigint.set(SIGINT);
    sigint.start();
    ev::sig sigquit(dl);
    sigquit.set<hyperdexd, &hyperdexd::QUIT>(this);
    sigquit.set(SIGQUIT);
    sigquit.start();
    ev::sig sigterm(dl);
    sigterm.set<hyperdexd, &hyperdexd::TERM>(this);
    sigterm.set(SIGTERM);
    sigterm.start();
    ev::sig sigusr1(dl);
    sigusr1.set<hyperdexd, &hyperdexd::USR1>(this);
    sigusr1.set(SIGUSR1);
    sigusr1.start();
    ev::sig sigusr2(dl);
    sigusr2.set<hyperdexd, &hyperdexd::USR2>(this);
    sigusr2.set(SIGUSR2);
    sigusr2.start();
    // Setup the data layer.
    hyperdex::datalayer data;
    // Setup the communications layer.
    hyperdex::logical comm(dl, "127.0.0.1"); // XXX don't hardcode localhost
    // Setup the replication layer.
    hyperdex::replication repl(&data, &comm);
    // Setup the link with the master.
    std::ostringstream ostr;
    ostr << "instance\t" << comm.inst().inbound << "\t"
                         << comm.inst().outbound
                         << "\n";
    hyperdex::masterlink ml(po6::net::location("127.0.0.1", 1234),
                            ostr.str(),
                            hyperdexd_install_mapping(&data, &comm, &repl));
    // Start the network_worker threads.
    hyperdex::network_worker nw(&data, &comm, &repl);
    std::tr1::function<void (hyperdex::network_worker*)> fnw(&hyperdex::network_worker::run);
    std::vector<thread_ptr> threads;

    for (size_t i = 0; i < NUM_THREADS; ++i)
    {
        thread_ptr t(new po6::threads::thread(std::tr1::bind(fnw, &nw)));
        t->start();
        threads.push_back(t);
    }

    while (m_continue)
    {
        try
        {
            dl.loop(EVLOOP_ONESHOT);
        }
        catch (std::exception& e)
        {
            LOG(INFO) << "Uncaught exception in event loop: " << e.what();
        }
    }

    // Cleanup HyperDex.
    //
    // XXX This is not proper network procedure.  A proper shutdown is:
    //  - The server receives the shutdown notice.
    //  - Every row leader agrees not to accept more updates.
    //  - Every row leader notifies the master when stable.
    //  - All instances flush to disk.
    //  - All instances terminate.
    //
    // Stop replication.
    repl.shutdown();
    // Turn off the network.
    comm.shutdown();
    // Cleanup the network_worker threads.
    nw.shutdown();
    // Cleanup the master thread.
    ml.shutdown();
    // Stop the data layer.
    data.shutdown();

    for (std::vector<thread_ptr>::iterator t = threads.begin();
            t != threads.end(); ++t)
    {
        (*t)->join();
    }
}

void
hyperdex :: hyperdexd :: HUP(ev::sig&, int)
{
    LOG(ERROR) << "SIGHUP received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: INT(ev::sig&, int)
{
    LOG(ERROR) << "SIGINT received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: QUIT(ev::sig&, int)
{
    LOG(ERROR) << "SIGQUIT received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: TERM(ev::sig&, int)
{
    LOG(ERROR) << "SIGTERM received; exiting.";
    m_continue = false;
}

void
hyperdex :: hyperdexd :: USR1(ev::sig&, int)
{
    LOG(INFO) << "SIGUSR1 received.  This does nothing.";
}

void
hyperdex :: hyperdexd :: USR2(ev::sig&, int)
{
    LOG(INFO) << "SIGUSR2 received.  This does nothing.";
}
<|endoftext|>


<commit_before>#ifndef _FILINPSTR_HXX_
#define _FILINPSTR_HXX_

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _CPPUHELPER_WEAK_HXX_
#include <cppuhelper/weak.hxx>
#endif
#ifndef _UCBHELPER_MACROS_HXX
#include <ucbhelper/macros.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_
#include <com/sun/star/uno/XInterface.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_
#include <com/sun/star/lang/XTypeProvider.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
#include <com/sun/star/io/XSeekable.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_
#include <com/sun/star/ucb/XContentProvider.hpp>
#endif

namespace fileaccess {

    // forward declaration

    class shell;

    class XInputStream_impl
        : public cppu::OWeakObject,
          public com::sun::star::lang::XTypeProvider,
          public com::sun::star::lang::XServiceInfo,
          public com::sun::star::io::XInputStream,
          public com::sun::star::io::XSeekable
    {
    public:

        XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath );

        virtual ~XInputStream_impl();

        /**
         *  Returns an error code as given by filerror.hxx
         */

        sal_Int32 SAL_CALL CtorSuccess();
        sal_Int32 SAL_CALL getMinorError();

        // XTypeProvider

        XTYPEPROVIDER_DECL()

        // XServiceInfo
        virtual rtl::OUString SAL_CALL
        getImplementationName()
            throw( com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL
        supportsService( const rtl::OUString& ServiceName )
            throw( com::sun::star::uno::RuntimeException);

        virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
        getSupportedServiceNames()
            throw( com::sun::star::uno::RuntimeException );

        virtual com::sun::star::uno::Any SAL_CALL
        queryInterface(
            const com::sun::star::uno::Type& rType )
            throw( com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL
        acquire(
            void )
            throw();

        virtual void SAL_CALL
        release(
            void )
            throw();

        virtual sal_Int32 SAL_CALL
        readBytes(
            com::sun::star::uno::Sequence< sal_Int8 >& aData,
            sal_Int32 nBytesToRead )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL
        readSomeBytes(
            com::sun::star::uno::Sequence< sal_Int8 >& aData,
            sal_Int32 nMaxBytesToRead )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL
        skipBytes(
            sal_Int32 nBytesToSkip )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int32 SAL_CALL
        available(
            void )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL
        closeInput(
            void )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL
        seek(
            sal_Int64 location )
            throw( com::sun::star::lang::IllegalArgumentException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int64 SAL_CALL
        getPosition(
            void )
            throw( com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int64 SAL_CALL
        getLength(
            void )
            throw( com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

    private:

        shell*                                             m_pMyShell;
        com::sun::star::uno::Reference<
        com::sun::star::ucb::XContentProvider >            m_xProvider;
        sal_Bool                                           m_nIsOpen;
        osl::File                                          m_aFile;

        sal_Int32                                          m_nErrorCode;
        sal_Int32                                          m_nMinorErrorCode;
    };

} // end namespace XInputStream_impl

#endif
<commit_msg>INTEGRATION: CWS abi08 (1.3.188); FILE MERGED 2004/10/22 14:34:06 abi 1.3.188.1: #i31221,95725# flush now syncs, headers included<commit_after> /*************************************************************************
 *
 *  $RCSfile: filinpstr.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2004-11-17 09:55:57 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _FILINPSTR_HXX_
#define _FILINPSTR_HXX_

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _CPPUHELPER_WEAK_HXX_
#include <cppuhelper/weak.hxx>
#endif
#ifndef _UCBHELPER_MACROS_HXX
#include <ucbhelper/macros.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_
#include <com/sun/star/uno/XInterface.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_
#include <com/sun/star/lang/XTypeProvider.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
#include <com/sun/star/io/XSeekable.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_
#include <com/sun/star/ucb/XContentProvider.hpp>
#endif

namespace fileaccess {

    // forward declaration

    class shell;

    class XInputStream_impl
        : public cppu::OWeakObject,
          public com::sun::star::lang::XTypeProvider,
          public com::sun::star::lang::XServiceInfo,
          public com::sun::star::io::XInputStream,
          public com::sun::star::io::XSeekable
    {
    public:

        XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath );

        virtual ~XInputStream_impl();

        /**
         *  Returns an error code as given by filerror.hxx
         */

        sal_Int32 SAL_CALL CtorSuccess();
        sal_Int32 SAL_CALL getMinorError();

        // XTypeProvider

        XTYPEPROVIDER_DECL()

        // XServiceInfo
        virtual rtl::OUString SAL_CALL
        getImplementationName()
            throw( com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL
        supportsService( const rtl::OUString& ServiceName )
            throw( com::sun::star::uno::RuntimeException);

        virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
        getSupportedServiceNames()
            throw( com::sun::star::uno::RuntimeException );

        virtual com::sun::star::uno::Any SAL_CALL
        queryInterface(
            const com::sun::star::uno::Type& rType )
            throw( com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL
        acquire(
            void )
            throw();

        virtual void SAL_CALL
        release(
            void )
            throw();

        virtual sal_Int32 SAL_CALL
        readBytes(
            com::sun::star::uno::Sequence< sal_Int8 >& aData,
            sal_Int32 nBytesToRead )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL
        readSomeBytes(
            com::sun::star::uno::Sequence< sal_Int8 >& aData,
            sal_Int32 nMaxBytesToRead )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL
        skipBytes(
            sal_Int32 nBytesToSkip )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::BufferSizeExceededException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int32 SAL_CALL
        available(
            void )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL
        closeInput(
            void )
            throw( com::sun::star::io::NotConnectedException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL
        seek(
            sal_Int64 location )
            throw( com::sun::star::lang::IllegalArgumentException,
                   com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int64 SAL_CALL
        getPosition(
            void )
            throw( com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

        virtual sal_Int64 SAL_CALL
        getLength(
            void )
            throw( com::sun::star::io::IOException,
                   com::sun::star::uno::RuntimeException );

    private:

        shell*                                             m_pMyShell;
        com::sun::star::uno::Reference<
        com::sun::star::ucb::XContentProvider >            m_xProvider;
        sal_Bool                                           m_nIsOpen;
        osl::File                                          m_aFile;

        sal_Int32                                          m_nErrorCode;
        sal_Int32                                          m_nMinorErrorCode;
    };

} // end namespace XInputStream_impl

#endif
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/utils/checker.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file checker.H
/// @brief Contains common functions that perform checks
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP FW Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#ifndef _CHECKER_H_
#define _CHECKER_H_

#include <fapi2.H>
#include "../shared/mss_const.H"
#include <mss_attribute_accessors.H>

namespace mss
{
namespace check
{
///
/// @brief      Checks homogenous DDR4 dimm configuration (e.g. DDR4)
/// @param[in]  i_target_mcs  const fapi2::Target<fapi2::TARGET_TYPE_MCS>&
/// @return     FAPI2_RC_SUCCESS iff ok
///
inline fapi2::ReturnCode dram_type(const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target_mcs)
{
    uint8_t l_dram_gen[PORTS_PER_MCS][MAX_DIMM_PER_PORT] = {0};

    // Retrieve DDR4 dimm attributes
    FAPI_TRY(eff_dram_gen(i_target_mcs, &(l_dram_gen[0][0])));

    // Make sure all DRAMs are DDR4 or throw an error
    // Iterate through MCA's/ports
    for (auto p : i_target_mcs.getChildren<fapi2::TARGET_TYPE_MCA>())
    {
        auto port_num = mss::index(p);

        // Iterate through DIMM targets
        for (auto d : p.getChildren<fapi2::TARGET_TYPE_DIMM>())
        {
            auto dimm_num = mss::index(d);

            FAPI_INF("%s DRAM device type is %llX",
                     mss::c_str(d),
                     l_dram_gen[port_num][dimm_num]);

            // Nimbus supports only DDR4
            FAPI_ASSERT(l_dram_gen[port_num][dimm_num] == fapi2::ENUM_ATTR_EFF_DRAM_GEN_DDR4,
                        fapi2::MSS_UNSUPPORTED_DEV_TYPE().
                        set_DEV_TYPE(l_dram_gen[port_num][dimm_num]),
                        "%s Incorrect DRAM device generation, DRAM generation is %llx",
                        mss::c_str(d),
                        l_dram_gen[port_num][dimm_num]);
        }

    }

fapi_try_exit:
    return fapi2::current_err;
}// dram_type

///
/// @brief Check if there is DIMM mixing (and deconfigures unsupported mixing ?? - AAM)
/// @return FAPI2_RC_SUCCESS iff ok
/// @note Functionality currently unknown
///
inline fapi2::ReturnCode dimm_mixing(void)
{
    //FIX p8 ported  code
    //Need to complete and figure out how to implement for p9 - AAM

    // Anuwat pushed Warren to say IBM systems will not support DIMM mixing
    // Now DIMM deconfig rules? - AAM
#if 0

    std::vector<uint8_t> l_module_type_vector;
    uint8_t l_module_type[mss::PORTS_PER_MCS][mss::MAX_DIMM_PER_PORT] = {0};
    uint8_t lr_dimm_count;
    uint8_t r_dimm_count;
    uint8_t u_dimm_count;

    FAPI_TRY(mss::spd_module_type(i_target_mcs, &l_module_type[0][0]),
             "Unable to read the SPD module type.");

    for(size_t l_port = 0; l_port < mss::PORTS_PER_MCS; l_port++)
    {
        for (size_t l_dimm = 0; l_dimm < mss::MAX_DIMM_PER_PORT; l_dimm++)
        {
            l_module_type_vector.push_back(l_module_type[l_port][l_dimm]);
        }
    }

    lr_dimm_count = std::count(l_module_type_vector.begin(),
                               l_module_type_vector.end(),
                               fapi2::ENUM_ATTR_SPD_MODULE_TYPE_LRDIMM);
    r_dimm_count = std::count(l_module_type_vector.begin(),
                              l_module_type_vector.end(),
                              fapi2::ENUM_ATTR_SPD_MODULE_TYPE_RDIMM);
    u_dimm_count = std::count(l_module_type_vector.begin(),
                              l_module_type_vector.end(),
                              fapi2::ENUM_ATTR_SPD_MODULE_TYPE_UDIMM); // Not supported? - AAM

    count(l_module_type_vector.begin(), l_module_type_vector.end(), fapi2::SO_DIMM); // Not supported? - AAM

    uint8_t temp = std::max({lr_dimm_count, r_dimm_count, u_dimm_count});

    return (temp == r_dimm_count) ? fapi2::RDIMM : fapi2::LRDIMM

#endif

           return fapi2::FAPI2_RC_SUCCESS;
}// dimm_mixing

///
/// @brief      Checks what type of system is configured (i.e., single drop, dual drop)
/// @return     FAPI2_RC_SUCCESS iff ok
/// @warning    Functionality currently unknown. Used in mss_freq
///
inline fapi2::ReturnCode system_drop_type(void)
{

    //Update for P9, how will we check if a system is single/dual drop?? - AAM

#if 0
    //Determining the cnfg for imposing any cnfg speed limitations
    if ( (cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
         && (cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_EMPTY) )
    {
        plug_config = MSS_FREQ_SINGLE_DROP;
        num_ranks_total = num_ranks[0][0][0] + 1;
    }
    else if (((cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
              && (cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_EMPTY)) ||
             ((cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID) && (cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_EMPTY)))
    {
        plug_config = MSS_FREQ_SINGLE_DROP;
        num_ranks_total = num_ranks[1][0][0] + 1;
    }
    else if ((cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
             && (cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_VALID))
    {
        plug_config = MSS_FREQ_DUAL_DROP;
        num_ranks_total = (num_ranks[0][0][0] + 1) + (num_ranks[0][0][1] + 1);
    }
    else if ((cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
             && (cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID))
    {
        plug_config = MSS_FREQ_DUAL_DROP;
        num_ranks_total = (num_ranks[1][0][0] + 1) + (num_ranks[1][0][1] + 1);
    }
    else
    {
        plug_config = MSS_FREQ_EMPTY;
    }

    FAPI_INF( "PLUG CONFIG(from SPD): %d, Type of Dimm(from SPD): 0x%02X, Num Ranks(from SPD): %d",
              plug_config, module_type, num_ranks_total);
fapi_try_exit:
    return fapi2::current_err;

#endif

    return fapi2::FAPI2_RC_SUCCESS;
}// system_drop_type

///
/// @brief      Checks nominal voltage is correct for all DIMMs
/// @param[in]  i_target_mcs the fapi2 target
/// @param[in]  i_dimm_state (i.e. functional or non-functional)
/// @return     ReturnCode
///
inline fapi2::ReturnCode module_nominal_voltage(const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target_mcs,
        fapi2::TargetState i_dimm_state)
{

    uint64_t l_module_nom_voltage[mss::PORTS_PER_MCS][mss::MAX_DIMM_PER_PORT] = {0};

    FAPI_TRY(mss::spd_module_nominal_voltage(i_target_mcs, &l_module_nom_voltage[0][0]));

    for (auto p : i_target_mcs.getChildren<fapi2::TARGET_TYPE_MCA>())
    {
        auto port_num = mss::index(p);

        // Iterate through DIMM targets
        for (auto d : p.getChildren<fapi2::TARGET_TYPE_DIMM>(i_dimm_state))
        {
            auto dimm_num = mss::index(d);

            FAPI_INF("%s DRAM nominal voltage (in milliseconds) is %d",
                     mss::c_str(d),
                     l_module_nom_voltage[port_num][dimm_num]);

            // All DIMMs have to be operable at 1.2 V, else don't IPL (according to Warren)
            FAPI_ASSERT( l_module_nom_voltage[port_num][dimm_num] == fapi2::ENUM_ATTR_SPD_MODULE_NOMINAL_VOLTAGE_OPERABLE,
                         fapi2::MSS_VOLT_DDR_TYPE_REQUIRED_VOLTAGE().
                         set_DIMM_VOLTAGE(l_module_nom_voltage[port_num][dimm_num]),
                         "%s.Failed conditional, data returned:o %d.",
                         mss::c_str(d),
                         l_module_nom_voltage[port_num][dimm_num] );
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}// module_nominal_voltage

namespace spd
{

///
/// @brief      Checks conditional passes and implements traces & exits if it fails
/// @tparam     T input data of any size
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_conditional conditional that we are testing against
/// @param[in]  i_spd_byte_index current SPD byte
/// @param[in]  i_spd_data debug data
/// @param[in]  i_err_str error string to print out when conditional fails
/// @return     ReturnCode
///
template< typename T >
inline fapi2::ReturnCode fail_for_invalid_value(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
        bool i_conditional,
        size_t i_spd_byte_index,
        T i_spd_data,
        const char* i_err_str)
{
    FAPI_ASSERT(i_conditional,
                fapi2::MSS_BAD_SPD().
                set_VALUE(i_spd_data).
                set_BYTE(i_spd_byte_index).
                set_DIMM_TARGET(i_target),
                "%s %s Byte %d, Data returned: %d.",
                c_str(i_target),
                i_err_str,
                i_spd_byte_index,
                i_spd_data);

fapi_try_exit:
    return fapi2::current_err;

} // fail_for_invalid_value()

///
/// @brief      Checks conditional passes and implements traces if it fails. No FFDC collected.
/// @tparam     T input data of any size
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_conditional that we are testing against
/// @param[in]  i_spd_byte_index
/// @param[in]  i_spd_data debug data
/// @param[in]  i_err_str string to print out when conditional fails
/// @return     void
///
template< typename T >
inline void warn_for_invalid_value(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                                   bool i_conditional,
                                   size_t i_spd_byte_index,
                                   T i_spd_data,
                                   const char* i_err_str)
{
    // Don't print warning conditional is true
    if(!i_conditional)
    {
        FAPI_IMP("%s. %s. Byte %d, Data returned: %d.",
                 c_str(i_target),
                 i_err_str,
                 i_spd_byte_index,
                 i_spd_data );
    }
}// warn_for_invalid_value

///
/// @brief      Checks if valid factory parameters are given
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_dimm_type DIMM type enumeration
/// @param[in]  i_encoding_rev SPD encoding level rev number
/// @param[in]  i_additions_rev SPD additions level rev number
/// @param[in]  i_err_str string to print out when conditional fails
/// @return     fapi2::ReturnCode
///
inline fapi2::ReturnCode invalid_factory_sel(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
        uint8_t i_dimm_type,
        uint8_t i_encoding_rev,
        uint8_t i_additions_rev,
        const char* i_err_str)
{
    FAPI_ASSERT(false,
                fapi2::MSS_INVALID_DIMM_REV_COMBO().
                set_DIMM_TYPE(i_dimm_type).
                set_ENCODING_REV(i_encoding_rev).
                set_ADDITIONS_REV(i_additions_rev).
                set_DIMM_TARGET(i_target),
                "%s. %s. Invalid combination for dimm type: %d, rev: %d.%d",
                c_str(i_target),
                i_err_str,
                i_dimm_type,
                i_encoding_rev,
                i_additions_rev);
fapi_try_exit:
    return fapi2::current_err;
}// invalid_factory_sel

}// spd
}// check
}// mss

#endif
<commit_msg>Change include paths in memory/lib, tests<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/utils/checker.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file checker.H
/// @brief Contains common functions that perform checks
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP FW Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#ifndef _CHECKER_H_
#define _CHECKER_H_

#include <fapi2.H>

#include <mss_attribute_accessors.H>
#include <lib/shared/mss_const.H>

namespace mss
{
namespace check
{
///
/// @brief      Checks homogenous DDR4 dimm configuration (e.g. DDR4)
/// @param[in]  i_target_mcs  const fapi2::Target<fapi2::TARGET_TYPE_MCS>&
/// @return     FAPI2_RC_SUCCESS iff ok
///
inline fapi2::ReturnCode dram_type(const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target_mcs)
{
    uint8_t l_dram_gen[PORTS_PER_MCS][MAX_DIMM_PER_PORT] = {0};

    // Retrieve DDR4 dimm attributes
    FAPI_TRY(eff_dram_gen(i_target_mcs, &(l_dram_gen[0][0])));

    // Make sure all DRAMs are DDR4 or throw an error
    // Iterate through MCA's/ports
    for (auto p : i_target_mcs.getChildren<fapi2::TARGET_TYPE_MCA>())
    {
        auto port_num = mss::index(p);

        // Iterate through DIMM targets
        for (auto d : p.getChildren<fapi2::TARGET_TYPE_DIMM>())
        {
            auto dimm_num = mss::index(d);

            FAPI_INF("%s DRAM device type is %llX",
                     mss::c_str(d),
                     l_dram_gen[port_num][dimm_num]);

            // Nimbus supports only DDR4
            FAPI_ASSERT(l_dram_gen[port_num][dimm_num] == fapi2::ENUM_ATTR_EFF_DRAM_GEN_DDR4,
                        fapi2::MSS_UNSUPPORTED_DEV_TYPE().
                        set_DEV_TYPE(l_dram_gen[port_num][dimm_num]),
                        "%s Incorrect DRAM device generation, DRAM generation is %llx",
                        mss::c_str(d),
                        l_dram_gen[port_num][dimm_num]);
        }

    }

fapi_try_exit:
    return fapi2::current_err;
}// dram_type

///
/// @brief Check if there is DIMM mixing (and deconfigures unsupported mixing ?? - AAM)
/// @return FAPI2_RC_SUCCESS iff ok
/// @note Functionality currently unknown
///
inline fapi2::ReturnCode dimm_mixing(void)
{
    //FIX p8 ported  code
    //Need to complete and figure out how to implement for p9 - AAM

    // Anuwat pushed Warren to say IBM systems will not support DIMM mixing
    // Now DIMM deconfig rules? - AAM
#if 0

    std::vector<uint8_t> l_module_type_vector;
    uint8_t l_module_type[mss::PORTS_PER_MCS][mss::MAX_DIMM_PER_PORT] = {0};
    uint8_t lr_dimm_count;
    uint8_t r_dimm_count;
    uint8_t u_dimm_count;

    FAPI_TRY(mss::spd_module_type(i_target_mcs, &l_module_type[0][0]),
             "Unable to read the SPD module type.");

    for(size_t l_port = 0; l_port < mss::PORTS_PER_MCS; l_port++)
    {
        for (size_t l_dimm = 0; l_dimm < mss::MAX_DIMM_PER_PORT; l_dimm++)
        {
            l_module_type_vector.push_back(l_module_type[l_port][l_dimm]);
        }
    }

    lr_dimm_count = std::count(l_module_type_vector.begin(),
                               l_module_type_vector.end(),
                               fapi2::ENUM_ATTR_SPD_MODULE_TYPE_LRDIMM);
    r_dimm_count = std::count(l_module_type_vector.begin(),
                              l_module_type_vector.end(),
                              fapi2::ENUM_ATTR_SPD_MODULE_TYPE_RDIMM);
    u_dimm_count = std::count(l_module_type_vector.begin(),
                              l_module_type_vector.end(),
                              fapi2::ENUM_ATTR_SPD_MODULE_TYPE_UDIMM); // Not supported? - AAM

    count(l_module_type_vector.begin(), l_module_type_vector.end(), fapi2::SO_DIMM); // Not supported? - AAM

    uint8_t temp = std::max({lr_dimm_count, r_dimm_count, u_dimm_count});

    return (temp == r_dimm_count) ? fapi2::RDIMM : fapi2::LRDIMM

#endif

           return fapi2::FAPI2_RC_SUCCESS;
}// dimm_mixing

///
/// @brief      Checks what type of system is configured (i.e., single drop, dual drop)
/// @return     FAPI2_RC_SUCCESS iff ok
/// @warning    Functionality currently unknown. Used in mss_freq
///
inline fapi2::ReturnCode system_drop_type(void)
{

    //Update for P9, how will we check if a system is single/dual drop?? - AAM

#if 0
    //Determining the cnfg for imposing any cnfg speed limitations
    if ( (cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
         && (cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_EMPTY) )
    {
        plug_config = MSS_FREQ_SINGLE_DROP;
        num_ranks_total = num_ranks[0][0][0] + 1;
    }
    else if (((cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
              && (cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_EMPTY)) ||
             ((cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID) && (cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_EMPTY)))
    {
        plug_config = MSS_FREQ_SINGLE_DROP;
        num_ranks_total = num_ranks[1][0][0] + 1;
    }
    else if ((cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
             && (cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_VALID))
    {
        plug_config = MSS_FREQ_DUAL_DROP;
        num_ranks_total = (num_ranks[0][0][0] + 1) + (num_ranks[0][0][1] + 1);
    }
    else if ((cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
             && (cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID))
    {
        plug_config = MSS_FREQ_DUAL_DROP;
        num_ranks_total = (num_ranks[1][0][0] + 1) + (num_ranks[1][0][1] + 1);
    }
    else
    {
        plug_config = MSS_FREQ_EMPTY;
    }

    FAPI_INF( "PLUG CONFIG(from SPD): %d, Type of Dimm(from SPD): 0x%02X, Num Ranks(from SPD): %d",
              plug_config, module_type, num_ranks_total);
fapi_try_exit:
    return fapi2::current_err;

#endif

    return fapi2::FAPI2_RC_SUCCESS;
}// system_drop_type

///
/// @brief      Checks nominal voltage is correct for all DIMMs
/// @param[in]  i_target_mcs the fapi2 target
/// @param[in]  i_dimm_state (i.e. functional or non-functional)
/// @return     ReturnCode
///
inline fapi2::ReturnCode module_nominal_voltage(const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target_mcs,
        fapi2::TargetState i_dimm_state)
{

    uint64_t l_module_nom_voltage[mss::PORTS_PER_MCS][mss::MAX_DIMM_PER_PORT] = {0};

    FAPI_TRY(mss::spd_module_nominal_voltage(i_target_mcs, &l_module_nom_voltage[0][0]));

    for (auto p : i_target_mcs.getChildren<fapi2::TARGET_TYPE_MCA>())
    {
        auto port_num = mss::index(p);

        // Iterate through DIMM targets
        for (auto d : p.getChildren<fapi2::TARGET_TYPE_DIMM>(i_dimm_state))
        {
            auto dimm_num = mss::index(d);

            FAPI_INF("%s DRAM nominal voltage (in milliseconds) is %d",
                     mss::c_str(d),
                     l_module_nom_voltage[port_num][dimm_num]);

            // All DIMMs have to be operable at 1.2 V, else don't IPL (according to Warren)
            FAPI_ASSERT( l_module_nom_voltage[port_num][dimm_num] == fapi2::ENUM_ATTR_SPD_MODULE_NOMINAL_VOLTAGE_OPERABLE,
                         fapi2::MSS_VOLT_DDR_TYPE_REQUIRED_VOLTAGE().
                         set_DIMM_VOLTAGE(l_module_nom_voltage[port_num][dimm_num]),
                         "%s.Failed conditional, data returned:o %d.",
                         mss::c_str(d),
                         l_module_nom_voltage[port_num][dimm_num] );
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}// module_nominal_voltage

namespace spd
{

///
/// @brief      Checks conditional passes and implements traces & exits if it fails
/// @tparam     T input data of any size
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_conditional conditional that we are testing against
/// @param[in]  i_spd_byte_index current SPD byte
/// @param[in]  i_spd_data debug data
/// @param[in]  i_err_str error string to print out when conditional fails
/// @return     ReturnCode
///
template< typename T >
inline fapi2::ReturnCode fail_for_invalid_value(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
        bool i_conditional,
        size_t i_spd_byte_index,
        T i_spd_data,
        const char* i_err_str)
{
    FAPI_ASSERT(i_conditional,
                fapi2::MSS_BAD_SPD().
                set_VALUE(i_spd_data).
                set_BYTE(i_spd_byte_index).
                set_DIMM_TARGET(i_target),
                "%s %s Byte %d, Data returned: %d.",
                c_str(i_target),
                i_err_str,
                i_spd_byte_index,
                i_spd_data);

fapi_try_exit:
    return fapi2::current_err;

} // fail_for_invalid_value()

///
/// @brief      Checks conditional passes and implements traces if it fails. No FFDC collected.
/// @tparam     T input data of any size
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_conditional that we are testing against
/// @param[in]  i_spd_byte_index
/// @param[in]  i_spd_data debug data
/// @param[in]  i_err_str string to print out when conditional fails
/// @return     void
///
template< typename T >
inline void warn_for_invalid_value(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                                   bool i_conditional,
                                   size_t i_spd_byte_index,
                                   T i_spd_data,
                                   const char* i_err_str)
{
    // Don't print warning conditional is true
    if(!i_conditional)
    {
        FAPI_IMP("%s. %s. Byte %d, Data returned: %d.",
                 c_str(i_target),
                 i_err_str,
                 i_spd_byte_index,
                 i_spd_data );
    }
}// warn_for_invalid_value

///
/// @brief      Checks if valid factory parameters are given
/// @param[in]  i_target fapi2 dimm target
/// @param[in]  i_dimm_type DIMM type enumeration
/// @param[in]  i_encoding_rev SPD encoding level rev number
/// @param[in]  i_additions_rev SPD additions level rev number
/// @param[in]  i_err_str string to print out when conditional fails
/// @return     fapi2::ReturnCode
///
inline fapi2::ReturnCode invalid_factory_sel(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
        uint8_t i_dimm_type,
        uint8_t i_encoding_rev,
        uint8_t i_additions_rev,
        const char* i_err_str)
{
    FAPI_ASSERT(false,
                fapi2::MSS_INVALID_DIMM_REV_COMBO().
                set_DIMM_TYPE(i_dimm_type).
                set_ENCODING_REV(i_encoding_rev).
                set_ADDITIONS_REV(i_additions_rev).
                set_DIMM_TARGET(i_target),
                "%s. %s. Invalid combination for dimm type: %d, rev: %d.%d",
                c_str(i_target),
                i_err_str,
                i_dimm_type,
                i_encoding_rev,
                i_additions_rev);
fapi_try_exit:
    return fapi2::current_err;
}// invalid_factory_sel

}// spd
}// check
}// mss

#endif
<|endoftext|>