<commit_before>#ifndef affogatoNode_H
#define affogatoNode_H
/** Affogato node class stores data for a single scene graph
 *  item.
 *
 *  @file
 *
 *  @par License:
 *  Copyright (C) 2006 Rising Sun Pictures Pty. Ltd.
 *  @par
 *  This plugin is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later
 *  version.
 *  @par
 *  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.
 *  @par
 *  You should have received a copy of the GNU Lesser General Public
 *  License (http://www.gnu.org/licenses/lgpl.txt) along with this
 *  library; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *  @author Moritz Moeller (moritz.moeller@rsp.com.au)
 *
 *  @par Disclaimer:
 *  Rising Sun Pictures Pty. Ltd., hereby disclaims all copyright
 *  interest in the plugin 'Affogato' (a plugin to translate 3D
 *  scenes to a 3D renderer) written by Moritz Moeller.
 *  @par
 *  Any one who uses this code does so completely at their own risk.
 *  Rising Sun Pictures doesn't warrant that this code does anything
 *  at all but if it does something and you don't like it, then we
 *  are not responsible.
 *  @par
 *  Have a nice day!
 */

// Standard headers
#include <vector>
#include <map>

// Boosy headers
#include <boost/shared_ptr.hpp>

// XSI headers
#include <xsi_property.h>
#include <xsi_value.h>

// Affogato headers
#include "affogatoHairData.hpp"
#include "affogatoGlobals.hpp"
#include "affogatoData.hpp"
#include "affogatoRenderer.hpp"
#include "affogatoShader.hpp"
#include "affogatoTokenValue.hpp"

namespace affogato {

	using namespace boost;
	using namespace std;
	using namespace ueberMan;
	using namespace XSI::MATH;

	/** Stores node data and handles motion samples.
	 *
	 *  Affogato is able to hold a copy of the entire scene in memory
	 *  before writing anything out to the renderer. The node class is
	 *  the basic container for this data. The feature to hold the entire
	 *  scene in memory is currently not used, but might come handy if
	 *  Afogato was to be proted to anothe 3d app, like Maya.
	 */
	class node {

		public:
					/** Extracts Affogato-relevant data from an X3DObject.
					 */
							node( const X3DObject &obj );
						   ~node();
					/** Writes just the node's attributes out for rendering.
					 */
					void	writeAttributes() const;
					/** Writes just the node's transformation out for rendering.
					 */
					void	writeTransform() const;
					/** Writes just the node's geometry out for rendering.
					 */
					void	writeGeometry() const;
					/** Writes the node out for rendering.
					 */
					void	write() const;
					/** Returns the node's bounding box.
					 *
					 *  @return A vector of floats with 6 elements: X min, X max, Y min, Y max, Z min, Z max.
					 */
			vector< float >	getBoundingBox() const;
					bool	isArchive() const;
					bool	isDataBox() const;
			static	void	setLookContext( const context& ctx );

		private:
					/** Helper function to delete an attribute from the node's attribute map.
					 *
					 *  @param element  The name of the element to delete from the map.
					 */
					void	deleteAttributeMapElement( const string& element );

					/** Scans a property for attributes understood by Affogato.
					 *
					 *  @param prop       The property to scan.
					 *  @param attribMap  A map that will be filled with the attributes found.
					 *                    If the map already contains an entry for an attribute, this attribute will be skipped.
					 */
					void 	scanForAttributes( const Property& prop, map< string, shared_ptr< tokenValue > >& attribMap,
								shared_ptr< shader >& surface, shared_ptr< shader >& displacement,  shared_ptr< shader >& volume );

			enum nodeType {
				nodeUndefined = 0,
				nodeLight,
				nodeSpace,
				nodeMesh,
				nodeNurb,
				nodeCurves,
				nodeHair,
				nodeParticle,
				nodeArchive,
				nodeHub,
				nodeNull,
				nodeSphere
			} node::type;

			string name;
			string fileName;
			string archive;
			string databox;
			unsigned short transformMotionSamples;
			unsigned short deformMotionSamples;
			vector< float > transformSampleTimes;
			vector< float > deformSampleTimes;
			vector< float > bound; // BBox

			bool usePref;
			double prefTime;
			string groupName;

			bool isStatic;
			long staticFrame;

#ifdef RSP
			unsigned hub, hdb;
#endif

			map< string, shared_ptr< tokenValue > >attributeMap;
			shared_ptr< shader > surface, displacement, volume;

			vector< shared_ptr< CMatrix4 > > transformSamples;
			vector< shared_ptr< data > > geometrySamples;
			map< string, vector< shared_ptr< Property > > > lookVectorMap;

			static context lookContext;

			// No support for motion blurred attributes as of now
	};
}

#endif
<commit_msg>Apparently this isn't legal in C++ and gcc 4.1 is more strict prevent it from compiling<commit_after>#ifndef affogatoNode_H
#define affogatoNode_H
/** Affogato node class stores data for a single scene graph
 *  item.
 *
 *  @file
 *
 *  @par License:
 *  Copyright (C) 2006 Rising Sun Pictures Pty. Ltd.
 *  @par
 *  This plugin is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later
 *  version.
 *  @par
 *  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.
 *  @par
 *  You should have received a copy of the GNU Lesser General Public
 *  License (http://www.gnu.org/licenses/lgpl.txt) along with this
 *  library; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *  @author Moritz Moeller (moritz.moeller@rsp.com.au)
 *
 *  @par Disclaimer:
 *  Rising Sun Pictures Pty. Ltd., hereby disclaims all copyright
 *  interest in the plugin 'Affogato' (a plugin to translate 3D
 *  scenes to a 3D renderer) written by Moritz Moeller.
 *  @par
 *  Any one who uses this code does so completely at their own risk.
 *  Rising Sun Pictures doesn't warrant that this code does anything
 *  at all but if it does something and you don't like it, then we
 *  are not responsible.
 *  @par
 *  Have a nice day!
 */

// Standard headers
#include <vector>
#include <map>

// Boosy headers
#include <boost/shared_ptr.hpp>

// XSI headers
#include <xsi_property.h>
#include <xsi_value.h>

// Affogato headers
#include "affogatoHairData.hpp"
#include "affogatoGlobals.hpp"
#include "affogatoData.hpp"
#include "affogatoRenderer.hpp"
#include "affogatoShader.hpp"
#include "affogatoTokenValue.hpp"

namespace affogato {

	using namespace boost;
	using namespace std;
	using namespace ueberMan;
	using namespace XSI::MATH;

	/** Stores node data and handles motion samples.
	 *
	 *  Affogato is able to hold a copy of the entire scene in memory
	 *  before writing anything out to the renderer. The node class is
	 *  the basic container for this data. The feature to hold the entire
	 *  scene in memory is currently not used, but might come handy if
	 *  Afogato was to be proted to anothe 3d app, like Maya.
	 */
	class node {

		public:
					/** Extracts Affogato-relevant data from an X3DObject.
					 */
							node( const X3DObject &obj );
						   ~node();
					/** Writes just the node's attributes out for rendering.
					 */
					void	writeAttributes() const;
					/** Writes just the node's transformation out for rendering.
					 */
					void	writeTransform() const;
					/** Writes just the node's geometry out for rendering.
					 */
					void	writeGeometry() const;
					/** Writes the node out for rendering.
					 */
					void	write() const;
					/** Returns the node's bounding box.
					 *
					 *  @return A vector of floats with 6 elements: X min, X max, Y min, Y max, Z min, Z max.
					 */
			vector< float >	getBoundingBox() const;
					bool	isArchive() const;
					bool	isDataBox() const;
			static	void	setLookContext( const context& ctx );

		private:
					/** Helper function to delete an attribute from the node's attribute map.
					 *
					 *  @param element  The name of the element to delete from the map.
					 */
					void	deleteAttributeMapElement( const string& element );

					/** Scans a property for attributes understood by Affogato.
					 *
					 *  @param prop       The property to scan.
					 *  @param attribMap  A map that will be filled with the attributes found.
					 *                    If the map already contains an entry for an attribute, this attribute will be skipped.
					 */
					void 	scanForAttributes( const Property& prop, map< string, shared_ptr< tokenValue > >& attribMap,
								shared_ptr< shader >& surface, shared_ptr< shader >& displacement,  shared_ptr< shader >& volume );

			enum nodeType {
				nodeUndefined = 0,
				nodeLight,
				nodeSpace,
				nodeMesh,
				nodeNurb,
				nodeCurves,
				nodeHair,
				nodeParticle,
				nodeArchive,
				nodeHub,
				nodeNull,
				nodeSphere
			} type;

			string name;
			string fileName;
			string archive;
			string databox;
			unsigned short transformMotionSamples;
			unsigned short deformMotionSamples;
			vector< float > transformSampleTimes;
			vector< float > deformSampleTimes;
			vector< float > bound; // BBox

			bool usePref;
			double prefTime;
			string groupName;

			bool isStatic;
			long staticFrame;

#ifdef RSP
			unsigned hub, hdb;
#endif

			map< string, shared_ptr< tokenValue > >attributeMap;
			shared_ptr< shader > surface, displacement, volume;

			vector< shared_ptr< CMatrix4 > > transformSamples;
			vector< shared_ptr< data > > geometrySamples;
			map< string, vector< shared_ptr< Property > > > lookVectorMap;

			static context lookContext;

			// No support for motion blurred attributes as of now
	};
}

#endif
<|endoftext|>


<commit_before>#include <atlconv.h>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <boost/program_options.hpp>

using namespace boost::program_options;

#define TARGET_WIN_NAME1 _T("VOICEROID{ 䂩 EX")
#define TARGET_WIN_NAME2 _T("VOICEROID{ 䂩 EX*")
#define SAVE_DIALOG_NAME _T("t@C̕ۑ")
#define WAIT_TIME 1500

HWND yukari;
HWND saveDialog;
HWND confirmationOverwriteDialog;

// "VOICEROID{ 䂩 EX" EBhET
BOOL CALLBACK SearchYukari(HWND hwnd, LPARAM lp);

// "t@C̕ۑ" _CAOT
BOOL CALLBACK SearchSaveDialog(HWND hwnd, LPARAM lp);

// ㏑mF_CAO
BOOL CALLBACK SearchConfirmationOverwriteDialog(HWND hwnd, LPARAM lp);

// "eLXgGA" T
HWND CALLBACK SearchTextArea(HWND mainWindow);

// "Đ{^" T
HWND CALLBACK SearchPlayButton(HWND mainWindow);

// "~{^" T
HWND CALLBACK SearchStopButton(HWND mainWindow);

// "ۑ{^" T
HWND CALLBACK SearchSaveButton(HWND mainWindow);

// "t@C:" T
HWND CALLBACK SearchSaveFilePath(HWND savaDialog);

// "ۑ(S)" T
HWND CALLBACK SearchSaveButtonInSaveDialog(HWND savaDialog);

// ㏑mF_CAÓu͂v{^T
HWND CALLBACK SearchYesButtonInConfirmationOverwriteDialog(HWND confirmationOverwriteDialog);

// w肵nh text 𑗐M
void sendText(HWND hwnd, TCHAR* text);

int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_CTYPE, "");
	std::ios::sync_with_stdio(true);

	options_description opt("IvV");
	// R}hC`
	opt.add_options()
		("help,h", "wv\")
		("output-file,o", value<std::string>()->default_value(""), "o̓t@CpX")
		("input-file,i", value<std::string>()->default_value(""), "̓t@CpX")
		("sync,s", "[h(ĐEۑ܂őҋ@܂)");

	// R}hC
	variables_map argmap;
	auto pr = parse_command_line(argc, argv, opt);
	store(pr, argmap);
	notify(argmap);

	// ͌ʎ擾
	std::string output_file = argmap["output-file"].as<std::string>();
	std::string input_file = argmap["input-file"].as<std::string>();
	bool is_sync_mode = !argmap["sync"].empty();
	std::wstring echo_text = _T("");

	// IvVȊÕR}hC擾
	for (auto const& str : collect_unrecognized(pr.options, include_positional)) {
		echo_text.append(_T(" "));
		echo_text.append(str);
	}

	// wv\w肪邩A
	// echo_text, input_file Ƃ̏ꍇAwv\ďI
	if (argmap.count("help") ||
		(echo_text.compare(_T("")) == 0
			&& input_file.compare("") == 0)) {
		_TCHAR drive[_MAX_DRIVE];
		_TCHAR dir[_MAX_DIR];
		_TCHAR filename[_MAX_FNAME];
		_TCHAR ext[_MAX_EXT];
		_tsplitpath(argv[0], drive, dir, filename, ext);

		wprintf(L"Usage: %s%s [options] [text]\n", filename, ext);

		std::stringstream helpStream;
		helpStream << opt << std::endl;
		printf(helpStream.str().c_str());

		exit(1);
	}

	// "VOICEROID{ 䂩 EX" T
	EnumWindows(SearchYukari, 0x0);

	if (yukari == NULL) {
		fwprintf(stderr, _T("VOICEROID ܂B\n"));
		fwprintf(stderr, _T("VOICEROID NĂB\n"));

		exit(1);
	}

	HWND textArea = SearchTextArea(yukari);

	// ȂŃeLXgGA...
	SendMessage(textArea, WM_SETTEXT, (WPARAM)_T(""), NULL);

	sendText(textArea, W2T((LPWSTR)echo_text.c_str()));

	// "ۑ{^" Tĉ
	HWND save_button = SearchSaveButton(yukari);
	PostMessage(save_button, BM_CLICK, 0, 0);
	Sleep(WAIT_TIME);

	// "t@C̕ۑ" EBhET
	EnumWindows(SearchSaveDialog, 0x0);

	// t@CeLXgGAT
	HWND saveFilePath = SearchSaveFilePath(saveDialog);

	// t@C
	// t@C wstring ɕϊ
	wchar_t *wcs = new wchar_t[output_file.length() + 1];
	mbstowcs(wcs, output_file.c_str(), output_file.length() + 1);

    // t@CeLXgGAɑ}
	sendText(saveFilePath, W2T((LPWSTR)wcs));
	delete [] wcs;

	// "ۑ(S)" {^
	HWND save_button_in_save_dialog = SearchSaveButtonInSaveDialog(saveDialog);
	PostMessage(save_button_in_save_dialog, BM_CLICK, 0, 0);

	Sleep(WAIT_TIME);

	// "VOICEROID{ 䂩 EX" T
	EnumWindows(SearchConfirmationOverwriteDialog, 0x0);
	if (confirmationOverwriteDialog != NULL) {
		HWND yes_button_in_confirmation_overwrite_dialog = SearchYesButtonInConfirmationOverwriteDialog(confirmationOverwriteDialog);
		PostMessage(yes_button_in_confirmation_overwrite_dialog, BM_CLICK, 0, 0);
	}

	exit(0);
}

// "VOICEROID{ 䂩 EX" EBhET
BOOL CALLBACK SearchYukari(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(TARGET_WIN_NAME1, strWindowText) == 0
		    || _tcscmp(TARGET_WIN_NAME2, strWindowText) == 0)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		yukari = hwnd;
		return false;
	}

	return true;
}

// "t@C̕ۑ" _CAOT
BOOL CALLBACK SearchSaveDialog(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(SAVE_DIALOG_NAME, strWindowText) == 0)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		saveDialog = hwnd;
		return false;
	}

	return true;
}

// ㏑mF_CAOT
BOOL CALLBACK SearchConfirmationOverwriteDialog(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(SAVE_DIALOG_NAME, strWindowText) == 0
			&& saveDialog != hwnd)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		confirmationOverwriteDialog = hwnd;
		return false;
	}

	return true;
}

// "eLXgGA" T
HWND CALLBACK SearchTextArea(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "Đ{^" T
HWND CALLBACK SearchPlayButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "~{^" T
HWND CALLBACK SearchStopButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// "ۑ{^" T
HWND CALLBACK SearchSaveButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// "t@C:" T
HWND CALLBACK SearchSaveFilePath(HWND savaDialog) {
	HWND tmp = GetWindow(saveDialog, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "ۑ(S){^" T
HWND CALLBACK SearchSaveButtonInSaveDialog(HWND savaDialog) {
	HWND tmp = GetWindow(saveDialog, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// ㏑mF_CAÓu͂v{^T
HWND CALLBACK SearchYesButtonInConfirmationOverwriteDialog(HWND confirmationOverwriteDialog) {
	return GetWindow(confirmationOverwriteDialog, GW_CHILD);
}

// w肵nh text 𑗐M
void sendText(HWND hwnd, TCHAR* text) {
	for (int i = 0; i < _tcslen(text); i++) {
		SendMessage(hwnd, WM_CHAR, (WPARAM)text[i], 0);
	}
}

<commit_msg>Implemented echo/save logic.<commit_after>#include <atlconv.h>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <boost/program_options.hpp>

using namespace boost::program_options;

#define TARGET_WIN_NAME1 _T("VOICEROID{ 䂩 EX")
#define TARGET_WIN_NAME2 _T("VOICEROID{ 䂩 EX*")
#define SAVE_DIALOG_NAME _T("t@C̕ۑ")
#define PLAY_BUTTON_NAME _T(" Đ")

#define WAIT_TIME 1500
#define END_PLAY_CHECK_INTERVAL 1000

HWND yukari;
HWND saveDialog;
HWND confirmationOverwriteDialog;

// eLXgǂݏグ
void echo(BOOL is_sync_mode);

// ǂݏグt@Cɕۑ
void save(std::string output_file);

// "VOICEROID{ 䂩 EX" EBhET
BOOL CALLBACK SearchYukari(HWND hwnd, LPARAM lp);

// "t@C̕ۑ" _CAOT
BOOL CALLBACK SearchSaveDialog(HWND hwnd, LPARAM lp);

// ㏑mF_CAO
BOOL CALLBACK SearchConfirmationOverwriteDialog(HWND hwnd, LPARAM lp);

// "eLXgGA" T
HWND CALLBACK SearchTextArea(HWND mainWindow);

// "Đ{^" T
HWND CALLBACK SearchPlayButton(HWND mainWindow);

// "~{^" T
HWND CALLBACK SearchStopButton(HWND mainWindow);

// "ۑ{^" T
HWND CALLBACK SearchSaveButton(HWND mainWindow);

// "t@C:" T
HWND CALLBACK SearchSaveFilePath(HWND savaDialog);

// "ۑ(S)" T
HWND CALLBACK SearchSaveButtonInSaveDialog(HWND savaDialog);

// ㏑mF_CAÓu͂v{^T
HWND CALLBACK SearchYesButtonInConfirmationOverwriteDialog(HWND confirmationOverwriteDialog);

// w肵nh text 𑗐M
void sendText(HWND hwnd, TCHAR* text);

int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_CTYPE, "");
	std::ios::sync_with_stdio(true);

	options_description opt("IvV");
	// R}hC`
	opt.add_options()
		("help,h", "wv\")
		("output-file,o", value<std::string>()->default_value(""), "o̓t@CpX")
		("input-file,i", value<std::string>()->default_value(""), "̓t@CpX")
		("sync,s", "[h(ĐEۑ܂őҋ@܂)");

	// R}hC
	variables_map argmap;
	auto pr = parse_command_line(argc, argv, opt);
	store(pr, argmap);
	notify(argmap);

	// ͌ʎ擾
	std::string output_file = argmap["output-file"].as<std::string>();
	std::string input_file = argmap["input-file"].as<std::string>();
	bool is_sync_mode = !argmap["sync"].empty();
	std::wstring echo_text = _T("");

	// IvVȊÕR}hC擾
	for (auto const& str : collect_unrecognized(pr.options, include_positional)) {
		echo_text.append(_T(" "));
		echo_text.append(str);
	}

	// wv\w肪邩A
	// echo_text, input_file Ƃ̏ꍇAwv\ďI
	if (argmap.count("help") ||
		(echo_text.compare(_T("")) == 0
			&& input_file.compare("") == 0)) {
		_TCHAR drive[_MAX_DRIVE];
		_TCHAR dir[_MAX_DIR];
		_TCHAR filename[_MAX_FNAME];
		_TCHAR ext[_MAX_EXT];
		_tsplitpath(argv[0], drive, dir, filename, ext);

		wprintf(L"Usage: %s%s [options] [text]\n", filename, ext);

		std::stringstream helpStream;
		helpStream << opt << std::endl;
		printf(helpStream.str().c_str());

		exit(1);
	}

	// "VOICEROID{ 䂩 EX" T
	EnumWindows(SearchYukari, 0x0);

	if (yukari == NULL) {
		fwprintf(stderr, _T("VOICEROID ܂B\n"));
		fwprintf(stderr, _T("VOICEROID NĂB\n"));

		exit(1);
	}

	HWND textArea = SearchTextArea(yukari);

	// ȂŃeLXgGA...
	SendMessage(textArea, WM_SETTEXT, (WPARAM)_T(""), NULL);

	sendText(textArea, W2T((LPWSTR)echo_text.c_str()));

	// ǂݏグ邩t@Cɕۑ邩
	if (output_file.length() == 0) {
		// ǂݏグ
		echo(is_sync_mode);
	} else {
		// t@Cɕۑ
		save(output_file);
	}

	exit(0);
}

// ǂݏグt@Cɕۑ
void save(std::string output_file) {
	// "ۑ{^" Tĉ
	HWND save_button = SearchSaveButton(yukari);
	PostMessage(save_button, BM_CLICK, 0, 0);
	Sleep(WAIT_TIME);

	// "t@C̕ۑ" EBhET
	EnumWindows(SearchSaveDialog, 0x0);

	// t@CeLXgGAT
	HWND saveFilePath = SearchSaveFilePath(saveDialog);

	// t@C
	// t@C wstring ɕϊ
	wchar_t *wcs = new wchar_t[output_file.length() + 1];
	mbstowcs(wcs, output_file.c_str(), output_file.length() + 1);

	// t@CeLXgGAɑ}
	sendText(saveFilePath, W2T((LPWSTR)wcs));
	delete [] wcs;

	// "ۑ(S)" {^
	HWND save_button_in_save_dialog = SearchSaveButtonInSaveDialog(saveDialog);
	PostMessage(save_button_in_save_dialog, BM_CLICK, 0, 0);

	Sleep(WAIT_TIME);

	// "VOICEROID{ 䂩 EX" T
	EnumWindows(SearchConfirmationOverwriteDialog, 0x0);
	if (confirmationOverwriteDialog != NULL) {
		HWND yes_button_in_confirmation_overwrite_dialog = SearchYesButtonInConfirmationOverwriteDialog(confirmationOverwriteDialog);
		PostMessage(yes_button_in_confirmation_overwrite_dialog, BM_CLICK, 0, 0);
	}
}

// eLXgǂݏグ
void echo(BOOL is_sync_mode) {
	// "Đ" {^T
	HWND play_button = SearchPlayButton(yukari);

	if (is_sync_mode) {
		// ĐI܂ő҂
		// TODO: ^CAEg邩
		SendMessage(play_button, BM_CLICK, 0, 0);

		while (1) {
			Sleep(END_PLAY_CHECK_INTERVAL);
			TCHAR strWindowText[1024];

			GetWindowText(play_button, strWindowText, 1024);

			if (_tcscmp(PLAY_BUTTON_NAME, strWindowText) == 0) {
				break;
			}
		}
	} else {
		// ĐI܂ő҂Ȃ
		PostMessage(play_button, BM_CLICK, 0, 0);
	}
}

// "VOICEROID{ 䂩 EX" EBhET
BOOL CALLBACK SearchYukari(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(TARGET_WIN_NAME1, strWindowText) == 0
		    || _tcscmp(TARGET_WIN_NAME2, strWindowText) == 0)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		yukari = hwnd;
		return false;
	}

	return true;
}

// "t@C̕ۑ" _CAOT
BOOL CALLBACK SearchSaveDialog(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(SAVE_DIALOG_NAME, strWindowText) == 0)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		saveDialog = hwnd;
		return false;
	}

	return true;
}

// ㏑mF_CAOT
BOOL CALLBACK SearchConfirmationOverwriteDialog(HWND hwnd, LPARAM lp) {
	TCHAR strWindowText[1024];
	GetWindowText(hwnd, strWindowText, 1024);

	if (_tcscmp(SAVE_DIALOG_NAME, strWindowText) == 0
			&& saveDialog != hwnd)
	{
		_tprintf(_T("%s ܂B\n"), strWindowText);
		confirmationOverwriteDialog = hwnd;
		return false;
	}

	return true;
}

// "eLXgGA" T
HWND CALLBACK SearchTextArea(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "Đ{^" T
HWND CALLBACK SearchPlayButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "~{^" T
HWND CALLBACK SearchStopButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// "ۑ{^" T
HWND CALLBACK SearchSaveButton(HWND mainWindow) {
	HWND tmp = GetWindow(mainWindow, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// "t@C:" T
HWND CALLBACK SearchSaveFilePath(HWND savaDialog) {
	HWND tmp = GetWindow(saveDialog, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);
	tmp = GetWindow(tmp, GW_CHILD);

	return tmp;
}

// "ۑ(S){^" T
HWND CALLBACK SearchSaveButtonInSaveDialog(HWND savaDialog) {
	HWND tmp = GetWindow(saveDialog, GW_CHILD);
	tmp = GetWindow(tmp, GW_HWNDNEXT);
	tmp = GetWindow(tmp, GW_HWNDNEXT);

	return tmp;
}

// ㏑mF_CAÓu͂v{^T
HWND CALLBACK SearchYesButtonInConfirmationOverwriteDialog(HWND confirmationOverwriteDialog) {
	return GetWindow(confirmationOverwriteDialog, GW_CHILD);
}

// w肵nh text 𑗐M
void sendText(HWND hwnd, TCHAR* text) {
	for (int i = 0; i < _tcslen(text); i++) {
		SendMessage(hwnd, WM_CHAR, (WPARAM)text[i], 0);
	}
}

<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9_cxa_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */
#include "p9_cxa_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr uint64_t literal_0 = 0;
constexpr uint64_t literal_0x801B1F98C8717000 = 0x801B1F98C8717000;
constexpr uint64_t literal_1 = 1;
constexpr uint64_t literal_0x801B1F98D8717000 = 0x801B1F98D8717000;
constexpr uint64_t literal_0x0000000000000 = 0x0000000000000;
constexpr uint64_t literal_0x2080000020080 = 0x2080000020080;
constexpr uint64_t literal_0b0000 = 0b0000;
constexpr uint64_t literal_0b111 = 0b111;
constexpr uint64_t literal_0b0010 = 0b0010;
constexpr uint64_t literal_0b0001 = 0b0001;

fapi2::ReturnCode p9_cxa_scom(const fapi2::Target<fapi2::TARGET_TYPE_CAPP>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1, const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& TGT2)
{
    {
        fapi2::ATTR_EC_Type   l_chip_ec;
        fapi2::ATTR_NAME_Type l_chip_id;
        FAPI_TRY(FAPI_ATTR_GET_PRIVILEGED(fapi2::ATTR_NAME, TGT2, l_chip_id));
        FAPI_TRY(FAPI_ATTR_GET_PRIVILEGED(fapi2::ATTR_EC, TGT2, l_chip_ec));
        fapi2::ATTR_CHIP_EC_FEATURE_HW414700_Type l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700;
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_EC_FEATURE_HW414700, TGT2, l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700));
        fapi2::ATTR_PROC_FABRIC_PUMP_MODE_Type l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE;
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_PUMP_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE));
        fapi2::buffer<uint64_t> l_scom_buffer;
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010803ull, l_scom_buffer ));

            if ((l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700 != literal_0))
            {
                l_scom_buffer.insert<0, 53, 0, uint64_t>(literal_0x801B1F98C8717000 );
            }
            else if (literal_1)
            {
                l_scom_buffer.insert<0, 53, 0, uint64_t>(literal_0x801B1F98D8717000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010803ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010806ull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 52, 12, uint64_t>(literal_0x0000000000000 );
            }
            else if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21))
                     || ((l_chip_id == 0x6) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 53, 11, uint64_t>(literal_0x0000000000000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010806ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010807ull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 52, 12, uint64_t>(literal_0x2080000020080 );
            }
            else if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21))
                     || ((l_chip_id == 0x6) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 53, 11, uint64_t>(literal_0x2080000020080 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010807ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010818ull, l_scom_buffer ));

            constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF = 0x0;
            l_scom_buffer.insert<1, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF );

            if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_GROUP))
            {
                constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON = 0x1;
                l_scom_buffer.insert<6, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON );
            }
            else if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_NODE))
            {
                constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF = 0x0;
                l_scom_buffer.insert<6, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010818ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010819ull, l_scom_buffer ));

            l_scom_buffer.insert<4, 4, 60, uint64_t>(literal_0b0000 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x2010819ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x201081bull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<45, 3, 61, uint64_t>(literal_0b111 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21)) || ((l_chip_id == 0x6)
                    && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<45, 3, 61, uint64_t>(literal_0b111 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<48, 4, 60, uint64_t>(literal_0b0010 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21)) || ((l_chip_id == 0x6)
                    && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<48, 4, 60, uint64_t>(literal_0b0010 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x201081bull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x201081cull, l_scom_buffer ));

            l_scom_buffer.insert<18, 4, 60, uint64_t>(literal_0b0001 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x201081cull, l_scom_buffer));
        }

    };
fapi_try_exit:
    return fapi2::current_err;
}
<commit_msg>TP, Nest FIR updates -- DD2 updates to match RAS XML<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9_cxa_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */
#include "p9_cxa_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr uint64_t literal_0 = 0;
constexpr uint64_t literal_0x801B1F98C8717000 = 0x801B1F98C8717000;
constexpr uint64_t literal_1 = 1;
constexpr uint64_t literal_0x801B1F98D8717000 = 0x801B1F98D8717000;
constexpr uint64_t literal_0x0000000000000 = 0x0000000000000;
constexpr uint64_t literal_0b1 = 0b1;
constexpr uint64_t literal_0b0000 = 0b0000;
constexpr uint64_t literal_0b111 = 0b111;
constexpr uint64_t literal_0b0010 = 0b0010;
constexpr uint64_t literal_0b0001 = 0b0001;

fapi2::ReturnCode p9_cxa_scom(const fapi2::Target<fapi2::TARGET_TYPE_CAPP>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1, const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& TGT2)
{
    {
        fapi2::ATTR_EC_Type   l_chip_ec;
        fapi2::ATTR_NAME_Type l_chip_id;
        FAPI_TRY(FAPI_ATTR_GET_PRIVILEGED(fapi2::ATTR_NAME, TGT2, l_chip_id));
        FAPI_TRY(FAPI_ATTR_GET_PRIVILEGED(fapi2::ATTR_EC, TGT2, l_chip_ec));
        fapi2::ATTR_CHIP_EC_FEATURE_HW414700_Type l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700;
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_EC_FEATURE_HW414700, TGT2, l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700));
        fapi2::ATTR_PROC_FABRIC_PUMP_MODE_Type l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE;
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_PUMP_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE));
        fapi2::buffer<uint64_t> l_scom_buffer;
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010803ull, l_scom_buffer ));

            if ((l_TGT2_ATTR_CHIP_EC_FEATURE_HW414700 != literal_0))
            {
                l_scom_buffer.insert<0, 53, 0, uint64_t>(literal_0x801B1F98C8717000 );
            }
            else if (literal_1)
            {
                l_scom_buffer.insert<0, 53, 0, uint64_t>(literal_0x801B1F98D8717000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010803ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010806ull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 52, 12, uint64_t>(literal_0x0000000000000 );
            }
            else if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21))
                     || ((l_chip_id == 0x6) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<0, 53, 11, uint64_t>(literal_0x0000000000000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010806ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010807ull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<2, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<34, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<44, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<8, 1, 63, uint64_t>(literal_0b1 );
            }
            else if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21))
                     || ((l_chip_id == 0x6) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<2, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<34, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<44, 1, 63, uint64_t>(literal_0b1 );
                l_scom_buffer.insert<8, 1, 63, uint64_t>(literal_0b1 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010807ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010818ull, l_scom_buffer ));

            constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF = 0x0;
            l_scom_buffer.insert<1, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF );

            if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_GROUP))
            {
                constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON = 0x1;
                l_scom_buffer.insert<6, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON );
            }
            else if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_NODE))
            {
                constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF = 0x0;
                l_scom_buffer.insert<6, 1, 63, uint64_t>(l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x2010818ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x2010819ull, l_scom_buffer ));

            l_scom_buffer.insert<4, 4, 60, uint64_t>(literal_0b0000 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x2010819ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x201081bull, l_scom_buffer ));

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<45, 3, 61, uint64_t>(literal_0b111 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21)) || ((l_chip_id == 0x6)
                    && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<45, 3, 61, uint64_t>(literal_0b111 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<48, 4, 60, uint64_t>(literal_0b0010 );
            }

            if (((l_chip_id == 0x5) && (l_chip_ec == 0x20)) || ((l_chip_id == 0x5) && (l_chip_ec == 0x21)) || ((l_chip_id == 0x6)
                    && (l_chip_ec == 0x10)) )
            {
                l_scom_buffer.insert<48, 4, 60, uint64_t>(literal_0b0010 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x201081bull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x201081cull, l_scom_buffer ));

            l_scom_buffer.insert<18, 4, 60, uint64_t>(literal_0b0001 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x201081cull, l_scom_buffer));
        }

    };
fapi_try_exit:
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>#pragma once

#include "macro.hpp"

#include <utility>

/**
 * \class ScopeFunc
 * A RAII class that takes a single functor object, executing the object's operator()
 * in the ScopeFunc object's destructor when the ScopeFunc object is destroyed.
*/
template<class Functor_T>
class ScopeFunc
{
private:
    Functor_T m_Functor;

public:
    ScopeFunc(Functor_T && p_rrFunctor) : m_Functor(p_rrFunctor) {}
    ~ScopeFunc(void) { m_Functor(); }

};

template<class Functor_T>
ScopeFunc<Functor_T> makeScopeFunc(Functor_T && p_rrFunctor)
{
    return ScopeFunc<Functor_T>(std::forward<Functor_T>(p_rrFunctor));
}

#define MakeScopeFunc(x) auto MAKE_UNIQUE_NAME() = makeScopeFunc(x);
#define BH_MakeScopeFunc(x) MakeScopeFunc(x);
<commit_msg>Update ScopeFunc.hpp<commit_after>#pragma once

#include "macro.hpp"

#include <utility>

namespace bh
{

namespace detail
{

template<typename ... T> class ScopeFuncImpl;
template<> class ScopeFuncImpl<> {};
template<typename First_T, typename ... Rest_T>
class ScopeFuncImpl<First_T, Rest_T...>
    : private ScopeFuncImpl<Rest_T...>
{
private:
    using BaseType = ScopeFuncImpl<Rest_T...>;

    First_T m_Functor;

public:
    ScopeFuncImpl(First_T && p_Functor, Rest_T && ... p_Functors)
        : BaseType(std::forward<Rest_T>(p_Functors)...), m_Functor(p_Functor) {}

    ~ScopeFuncImpl(void) { m_Functor(); }
}; // ScopeFuncImpl

} // detail ns

/**
 * \class ScopeFunc
 * A RAII class that takes an arbitrary number of functor objects, executing the objects' operator()
 * in the ScopeFunc object's destructor when the ScopeFunc object is destroyed.
*/
template<typename ... Functor_T>
class ScopeFunc
    : private detail::ScopeFuncImpl<Functor_T...>
{
private:
    using BaseType = detail::ScopeFuncImpl<Functor_T...>;

public:
    ScopeFunc(Functor_T && ... p_Functors)
        : BaseType(std::forward<Functor_T>(p_Functors)...) {}
};

template<typename ... Functor_T>
ScopeFunc<Functor_T...> makeScopeFunc(Functor_T && ... p_rrFunctor)
{
    return ScopeFunc<Functor_T...>(std::forward<Functor_T>(p_rrFunctor) ... );
}

} // BH ns

#define MakeScopeFunc(...) auto MAKE_UNIQUE_NAME() = makeScopeFunc(__VA_ARGS__);
#define BH_MakeScopeFunc(...) MakeScopeFunc(__VA_ARGS__);
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/p9_mss_memdiag.C $  */
/*                                                                        */
/* 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 p9_mss_memdiag.C
/// @brief Mainstore pattern testing
///
// *HWP HWP Owner: Stephen Glancy <sglancy@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: FSP:HB

#include <fapi2.H>
#include <p9_mss_memdiag.H>

#include <lib/utils/poll.H>
#include <generic/memory/lib/utils/find.H>
#include <generic/memory/lib/utils/count_dimm.H>
#include <lib/mcbist/address.H>
#include <lib/mcbist/memdiags.H>
#include <lib/mcbist/mcbist.H>
#include <lib/mc/port.H>
#include <lib/ecc/ecc.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_SYSTEM;
using fapi2::TARGET_TYPE_MCA;

extern "C"
{
    ///
    /// @brief Pattern test the DRAM
    /// @param[in] i_target the McBIST of the ports of the dram you're training
    /// @return FAPI2_RC_SUCCESS iff ok
    ///
    fapi2::ReturnCode p9_mss_memdiag( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
    {
        FAPI_INF("Start memdiag");

        // If there are no DIMM we don't need to bother. In fact, we can't as we didn't setup
        // attributes for the PHY, etc.
        if (mss::count_dimm(i_target) == 0)
        {
            FAPI_INF("... skipping mem_diags %s - no DIMM ...", mss::c_str(i_target));
            return fapi2::FAPI2_RC_SUCCESS;
        }

        uint8_t l_sim = false;
        FAPI_TRY( mss::is_simulation( l_sim) );

        // Read the bad_dq_bitmap attribute and place corresponding symbol and chip marks
        for (const auto& l_mca : mss::find_targets<TARGET_TYPE_MCA>(i_target))
        {
            fapi2::buffer<uint8_t> l_repairs_applied;
            fapi2::buffer<uint8_t> l_repairs_exceeded;
            std::vector<uint64_t> l_ranks;

            FAPI_TRY( mss::restore_repairs( l_mca, l_repairs_applied, l_repairs_exceeded) );

            // assert if we have exceeded the allowed repairs
            for (const auto& l_dimm : mss::find_targets<fapi2::TARGET_TYPE_DIMM>(l_mca))
            {
                // Note: using MCA here as the scoms used to collect FFDC data fail on the DIMM level target
                FAPI_ASSERT( !(l_repairs_exceeded.getBit(mss::index(l_dimm))),
                             fapi2::MSS_MEMDIAGS_REPAIRS_EXCEEDED().set_MCA_TARGET(l_mca),
                             "p9_mss_memdiag bad bit repairs exceeded %s", mss::c_str(l_mca) );
            }

#ifdef __HOSTBOOT_MODULE
            // assert if both chip and symbol marks exist for any given rank
            FAPI_TRY( mss::rank::ranks(l_mca, l_ranks) );

            for (const auto l_rank : l_ranks)
            {
                if (l_repairs_applied.getBit(l_rank))
                {
                    uint64_t l_galois = 0;
                    mss::states l_confirmed = mss::NO;
                    // check for chip mark in hardware mark store
                    FAPI_TRY( mss::ecc::get_hwms(l_mca, l_rank, l_galois, l_confirmed) );

                    if (l_confirmed)
                    {
                        auto l_type = mss::ecc::fwms::mark_type::CHIP;
                        auto l_region = mss::ecc::fwms::mark_region::DISABLED;
                        auto l_addr = mss::mcbist::address(0);
                        // check for symbol mark in firmware mark store
                        FAPI_TRY( mss::ecc::get_fwms(l_mca, l_rank, l_galois, l_type, l_region, l_addr) );

                        FAPI_ASSERT( l_region == mss::ecc::fwms::mark_region::DISABLED,
                                     fapi2::MSS_MEMDIAGS_CHIPMARK_AND_SYMBOLMARK().set_MCA_TARGET(l_mca).set_RANK(l_rank),
                                     "p9_mss_memdiag both chip mark and symbol mark on rank %d: %s", l_rank, mss::c_str(l_mca) );
                    }
                }
            }

#endif
        }

        // We start the sf_init (write 0's) and it'll tickle the MCBIST complete FIR. PRD will see that
        // and start a background scrub.
        FAPI_TRY( mss::memdiags::sf_init(i_target, mss::mcbist::PATTERN_0) );

        // If we're in the sim, we want to poll for the FIR bit. I don't think this ever really happens
        // unless we're expressly testing this API.
        if (l_sim)
        {
            // Poll for the fir bit. We expect this to be set ...
            fapi2::buffer<uint64_t> l_status;

            // A small vector of addresses to poll during the polling loop
            const std::vector<mss::poll_probe<fapi2::TARGET_TYPE_MCBIST>> l_probes =
            {
                {i_target, "mcbist current address", MCBIST_MCBMCATQ},
            };

            mss::poll_parameters l_poll_parameters;
            bool l_poll_results = mss::poll(i_target, MCBIST_MCBISTFIRQ, l_poll_parameters,
                                            [&l_status](const size_t poll_remaining,
                                                    const fapi2::buffer<uint64_t>& stat_reg) -> bool
            {
                FAPI_DBG("mcbist firq 0x%llx, remaining: %d", stat_reg, poll_remaining);
                l_status = stat_reg;
                return l_status.getBit<MCBIST_MCBISTFIRQ_MCBIST_PROGRAM_COMPLETE>() == true;
            },
            l_probes);

            FAPI_ASSERT( l_poll_results == true,
                         fapi2::MSS_MEMDIAGS_SUPERFAST_INIT_FAILED_TO_INIT().set_MCBIST_TARGET(i_target),
                         "p9_mss_memdiags timedout %s", mss::c_str(i_target) );
        }

    fapi_try_exit:
        FAPI_INF("End memdiag");
        return fapi2::current_err;
    }
}
<commit_msg>Added p9_mss_memdiag for cronus ipl and modified scrub for step 16<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/p9_mss_memdiag.C $  */
/*                                                                        */
/* 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 p9_mss_memdiag.C
/// @brief HW Procedure pattern testing
///
// *HWP HWP Owner: Matthew Hickman <Matthew.Hickman@ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#include <fapi2.H>
#include <p9_mss_memdiag.H>

#include <lib/dimm/rank.H>
#include <lib/utils/poll.H>
#include <generic/memory/lib/utils/find.H>
#include <generic/memory/lib/utils/count_dimm.H>
#include <lib/mcbist/address.H>
#include <lib/mcbist/patterns.H>
#include <lib/mcbist/memdiags.H>
#include <lib/mcbist/mcbist.H>
#include <lib/mc/port.H>
#include <lib/mcbist/sim.H>
#include <lib/ecc/ecc.H>
#include <lib/fir/memdiags_fir.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_SYSTEM;
using fapi2::TARGET_TYPE_MCA;
using fapi2::FAPI2_RC_SUCCESS;

extern "C"
{
    ///
    /// @brief Begin background scrub and run pattern tests
    /// @param[in] i_target MCBIST
    /// @return FAPI2_RC_SUCCESS iff ok
    ///
    fapi2::ReturnCode p9_mss_memdiag( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
    {
        FAPI_INF("Start mss memdiags on: %s", mss::c_str( i_target ));

        // If there are no DIMM we don't need to bother. In fact, we can't as we didn't setup
        // attributes for the PHY, etc.
        if (mss::count_dimm(i_target) == 0)
        {
            FAPI_INF("... skipping mem_diags %s - no DIMM ...", mss::c_str(i_target));
            return fapi2::FAPI2_RC_SUCCESS;
        }

        // If we're running in the simulator, we want to only touch the addresses which training touched
        uint8_t l_sim = false;
        bool l_poll_results = false;
        fapi2::buffer<uint64_t> l_status;

        // Set poll parameter values for max time to complete sf_init
        constexpr uint64_t INITIAL_DELAY = 0;
        constexpr uint64_t INITIAL_SIM_DELAY = 200;
        constexpr uint64_t DELAY_TIME = 100 * mss::DELAY_1MS;
        constexpr uint64_t SIM_DELAY_TIME = 200;
        constexpr uint64_t MAX_POLL_COUNT = 10000;

        // A small vector of addresses to poll during the polling loop
        const std::vector<mss::poll_probe<fapi2::TARGET_TYPE_MCBIST>> l_probes =
        {
            {i_target, "mcbist current address", MCBIST_MCBMCATQ},
        };

        // We'll fill in the initial delay below
        mss::poll_parameters l_poll_parameters(INITIAL_DELAY, INITIAL_SIM_DELAY, DELAY_TIME, SIM_DELAY_TIME, MAX_POLL_COUNT);
        uint64_t l_memory_size = 0;

        FAPI_TRY( mss::eff_memory_size(i_target, l_memory_size) );
        l_poll_parameters.iv_initial_delay = mss::calculate_initial_delay(i_target, (l_memory_size * mss::BYTES_PER_GB));

        FAPI_TRY( mss::is_simulation( l_sim) );

        if (l_sim)
        {
            // Use some sort of pattern in sim in case the verification folks need to look for something
            FAPI_INF("running mss sim init in place of memdiags");
            FAPI_TRY ( mss::mcbist::sim::sf_init(i_target, mss::mcbist::PATTERN_0) );

            // Unmask firs and turn off FIFO mode before returning
            FAPI_TRY ( mss::unmask::after_memdiags( i_target ) );
            FAPI_TRY ( mss::reset_reorder_queue_settings(i_target) );

            return fapi2::FAPI2_RC_SUCCESS;
        }

        // Unsure if redundant code? Wasn't called before to my knowledge
        // Only major difference between old mss_scrub and old mss_memdiag
        // Read the bad_dq_bitmap attribute and place corresponding symbol and chip marks
        for (const auto& l_mca : mss::find_targets<TARGET_TYPE_MCA>(i_target))
        {
            fapi2::buffer<uint8_t> l_repairs_applied;
            fapi2::buffer<uint8_t> l_repairs_exceeded;
            std::vector<uint64_t> l_ranks;

            FAPI_TRY( mss::restore_repairs( l_mca, l_repairs_applied, l_repairs_exceeded) );

            // assert if we have exceeded the allowed repairs
            for (const auto& l_dimm : mss::find_targets<fapi2::TARGET_TYPE_DIMM>(l_mca))
            {
                // Note: using MCA here as the scoms used to collect FFDC data fail on the DIMM level target
                FAPI_ASSERT( !(l_repairs_exceeded.getBit(mss::index(l_dimm))),
                             fapi2::MSS_MEMDIAGS_REPAIRS_EXCEEDED().set_MCA_TARGET(l_mca),
                             "p9_mss_memdiag bad bit repairs exceeded %s", mss::c_str(l_mca) );
            }

#ifdef __HOSTBOOT_MODULE
            // assert if both chip and symbol marks exist for any given rank
            FAPI_TRY( mss::rank::ranks(l_mca, l_ranks) );

            for (const auto l_rank : l_ranks)
            {
                if (l_repairs_applied.getBit(l_rank))
                {
                    uint64_t l_galois = 0;
                    mss::states l_confirmed = mss::NO;
                    // check for chip mark in hardware mark store
                    FAPI_TRY( mss::ecc::get_hwms(l_mca, l_rank, l_galois, l_confirmed) );

                    if (l_confirmed)
                    {
                        auto l_type = mss::ecc::fwms::mark_type::CHIP;
                        auto l_region = mss::ecc::fwms::mark_region::DISABLED;
                        auto l_addr = mss::mcbist::address(0);
                        // check for symbol mark in firmware mark store
                        FAPI_TRY( mss::ecc::get_fwms(l_mca, l_rank, l_galois, l_type, l_region, l_addr) );

                        FAPI_ASSERT( l_region == mss::ecc::fwms::mark_region::DISABLED,
                                     fapi2::MSS_MEMDIAGS_CHIPMARK_AND_SYMBOLMARK().set_MCA_TARGET(l_mca).set_RANK(l_rank),
                                     "p9_mss_memdiag both chip mark and symbol mark on rank %d: %s", l_rank, mss::c_str(l_mca) );
                    }
                }
            }

#endif
        }

        // In Cronus on hardware (which is how we got here - f/w doesn't call this) we want
        // to call sf_init (0's)
        FAPI_TRY( mss::memdiags::sf_init(i_target, mss::mcbist::PATTERN_0) );

        // Poll for completion.
        l_poll_results = mss::poll(i_target, MCBIST_MCBISTFIRQ, l_poll_parameters,
                                   [&l_status](const size_t poll_remaining,
                                               const fapi2::buffer<uint64_t>& stat_reg) -> bool
        {
            FAPI_DBG("mcbist firq 0x%016llx, remaining: %d", stat_reg, poll_remaining);
            l_status = stat_reg;
            return l_status.getBit<MCBIST_MCBISTFIRQ_MCBIST_PROGRAM_COMPLETE>() == true;
        },
        l_probes);

        FAPI_ASSERT( l_poll_results == true,
                     fapi2::MSS_MEMDIAGS_SUPERFAST_INIT_FAILED_TO_INIT().set_MCBIST_TARGET(i_target),
                     "p9_mss_memdiag (init) timedout %s", mss::c_str(i_target) );

        // Unmask firs after memdiags and turn off FIFO mode
        FAPI_TRY ( mss::unmask::after_memdiags( i_target ) );
        FAPI_TRY ( mss::reset_reorder_queue_settings(i_target) );

    fapi_try_exit:
        FAPI_INF("End memdiag");
        return fapi2::current_err;
    }
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/perv/p9_mem_pll_reset.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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  p9_mem_pll_initf.C
///
/// @brief Reset pll for MC Chiplets
//------------------------------------------------------------------------------
// *HWP HW Owner        : Anusha Reddy Rangareddygari <anusrang@in.ibm.com>
// *HWP HW Backup Owner : Srinivas V Naga <srinivan@in.ibm.com>
// *HWP FW Owner        : Sunil Kumar <skumar8j@in.ibm.com>
// *HWP Team            : Perv
// *HWP Level           : 2
// *HWP Consumed by     : HB
//------------------------------------------------------------------------------

//## auto_generated
#include <p9_mem_pll_reset.H>
#include <p9_perv_scom_addresses.H>
#include <p9_perv_scom_addresses_fld.H>

enum P9_MEM_PLL_RESET_Private_Constants
{
    OPCG_ALIGN_SCAN_RATIO = 0b00000,             // 1:1
    OPCG_ALIGN_INOP_ALIGN = 0b0101,              // 8:1
    OPCG_ALIGN_INOP_WAIT = 0x0,
    OPCG_ALIGN_WAIT_CYCLES = 0x020,
    P9_OPCG_DONE_SCAN0_POLL_COUNT = 200,         // Scan0 Poll count
    P9_OPCG_DONE_SCAN0_HW_NS_DELAY = 16000,      // unit is nano seconds [min : 8k cycles x 4 = 8000/2 x 4 = 16000 x 10(-9) = 16 us
    //                       max : 8k cycles  =  (8000/25) x 10 (-6) = 320 us]
    P9_OPCG_DONE_SCAN0_SIM_CYCLE_DELAY = 800000  // unit is cycles, to match the poll count change ( 10000 * 8 )
};

/// @brief Scan0 PLL bndy ring to prepare for PLL re-initialization
///
/// --Write Clock Region Register
/// --Write Scan Select Register
/// --Set OPCG_REG0 register bit 0='0' / 2='1' to trigger scan0
/// --Poll OPCG done bit to check for scan0 completeness
/// --Clear Clock Region register
/// --Clear Scan Select register
///
/// @param[in] i_target Reference to TARGET_TYPE_PERV
///
/// @return FAPI2_RC_SUCCESS if success, else error code.
fapi2::ReturnCode
p9_mem_pll_reset_scan0_bndy(const fapi2::Target<fapi2::TARGET_TYPE_PERV>& i_target)
{
    FAPI_DBG("Entering ...");
    uint8_t l_timeout = P9_OPCG_DONE_SCAN0_POLL_COUNT;
    fapi2::buffer<uint64_t> l_clk_region = 0;
    fapi2::buffer<uint64_t> l_scan_region = 0;
    fapi2::buffer<uint64_t> l_opcg_reg0 = 0;
    fapi2::buffer<uint64_t> l_cplt_stat0 = 0;

    // configure clock region register (region=PLL, all tholds)
    l_clk_region.setBit<PERV_1_SCAN_REGION_TYPE_UNIT10>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_SL>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_NSL>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_ARY>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_CLK_REGION, l_clk_region),
             "Error from putScom (PERV_CLK_REGION)");

    // configure scan region register (region=PLL, type=BNDY)
    l_scan_region.setBit<PERV_1_SCAN_REGION_TYPE_UNIT10>();
    l_scan_region.setBit<PERV_1_SCAN_REGION_TYPE_BNDY>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_SCAN_REGION_TYPE, l_scan_region),
             "Error from putScom (PERV_SCAN_REGION_TYPE)");

    // configure OPCG reg0, trigger scan0
    FAPI_TRY(fapi2::getScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from getScom (PERV_OPCG_REG0), clear RUNN");
    l_opcg_reg0.clearBit<PERV_1_OPCG_REG0_RUNN_MODE>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from putScom (PERV_OPCG_REG0), clear RUNN");
    l_opcg_reg0.setBit<PERV_1_OPCG_REG0_RUN_SCAN0>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from putScom (PERV_OPCG_REG0), trigger scan0");

    FAPI_DBG("Poll OPCG done bit to check for run-N completeness");

    while (l_timeout != 0)
    {
        FAPI_TRY(fapi2::getScom(i_target, PERV_CPLT_STAT0, l_cplt_stat0),
                 "Error from getScom (PERV_CPLT_STAT0)");

        if (l_cplt_stat0.getBit<PERV_1_CPLT_STAT0_CC_CTRL_OPCG_DONE_DC>())
        {
            break;
        }

        fapi2::delay(P9_OPCG_DONE_SCAN0_HW_NS_DELAY,
                     P9_OPCG_DONE_SCAN0_SIM_CYCLE_DELAY);
        --l_timeout;
    }

    FAPI_ASSERT(l_timeout > 0,
                fapi2::P9_MEM_PLL_RESET_SCAN0_DONE_POLL_THRESHOLD_ERR()
                .set_TARGET(i_target)
                .set_PERV_CPLT_STAT0(l_cplt_stat0)
                .set_LOOP_COUNT(l_timeout)
                .set_HW_DELAY(P9_OPCG_DONE_SCAN0_HW_NS_DELAY),
                "Timeout polling for OPCG_DONE for scan0 flush");

    // cleanup, clear clock region & scan select registers
    FAPI_TRY(fapi2::putScom(i_target, PERV_CLK_REGION, 0x0),
             "Error from putScom (PERV_CLK_REGION), clear");
    FAPI_TRY(fapi2::putScom(i_target, PERV_SCAN_REGION_TYPE, 0x0),
             "Error from putScom (PERV_SCAN_REGION_TYPE), clear");

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

fapi2::ReturnCode p9_mem_pll_reset(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target_chiplet)
{
    uint8_t l_read_attr = 0;
    fapi2::buffer<uint64_t> l_data64;

    FAPI_INF("Entering ...");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MC_SYNC_MODE, i_target_chiplet, l_read_attr));

    if ( !l_read_attr )
    {
        for (auto l_chplt_trgt :  i_target_chiplet.getChildren<fapi2::TARGET_TYPE_PERV>
             (fapi2::TARGET_FILTER_ALL_MC, fapi2::TARGET_STATE_FUNCTIONAL))
        {
            //Assert endpoint reset
            FAPI_DBG("Asserting endpoint reset");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PCB_EP_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));

            //Move MC PLL into reset state
            FAPI_DBG("Move MC PLL into reset state");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_BYPASS>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_TEST_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));

            //Assert MEM PDLY and DCC  bypass
            FAPI_DBG("Assert MEM PDLY and DCC bypass");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL1_CLK_DCC_BYPASS_EN>();
            l_data64.setBit<PERV_1_NET_CTRL1_CLK_PDLY_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WOR, l_data64));

            //Clear endpoint reset
            FAPI_DBG("Dropping endpoint reset");
            l_data64.flush<1>();
            l_data64.clearBit<PERV_1_NET_CTRL0_PCB_EP_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

            //Disable listen to sync pulse to MC chiplet, when MEM is not in sync to nest
            FAPI_DBG("Disable listen to sync pulse");
            FAPI_TRY(fapi2::getScom(l_chplt_trgt, PERV_SYNC_CONFIG, l_data64));
            l_data64.setBit<PERV_1_SYNC_CONFIG_LISTEN_TO_PULSE_DIS>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_SYNC_CONFIG, l_data64));

            //Initialize OPCG_ALIGN register
            FAPI_DBG("Initalize OPCG_ALIGN register");
            l_data64.flush<0>();
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_INOP, PERV_1_OPCG_ALIGN_INOP_LEN>(OPCG_ALIGN_INOP_ALIGN);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_INOP_WAIT, PERV_1_OPCG_ALIGN_INOP_WAIT_LEN>(OPCG_ALIGN_INOP_WAIT);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_WAIT_CYCLES, PERV_1_OPCG_ALIGN_WAIT_CYCLES_LEN>(OPCG_ALIGN_WAIT_CYCLES);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_SCAN_RATIO, PERV_1_OPCG_ALIGN_SCAN_RATIO_LEN>(OPCG_ALIGN_SCAN_RATIO);
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_OPCG_ALIGN, l_data64));

            // scan0 flush PLL boundary ring
            FAPI_DBG("Executing scan0 flush for PLL bndy ring");
            FAPI_TRY(p9_mem_pll_reset_scan0_bndy(l_chplt_trgt),
                     "Error from p9_mem_pll_reset_scan0_bndy");
        }
    }

    FAPI_INF("Exiting ...");

fapi_try_exit:
    return fapi2::current_err;
}
<commit_msg>p9_mem_pll_reset: Level 3<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/perv/p9_mem_pll_reset.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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  p9_mem_pll_initf.C
///
/// @brief Reset pll for MC Chiplets
//------------------------------------------------------------------------------
// *HWP HW Owner        : Anusha Reddy Rangareddygari <anusrang@in.ibm.com>
// *HWP HW Backup Owner : Srinivas V Naga <srinivan@in.ibm.com>
// *HWP FW Owner        : Sunil Kumar <skumar8j@in.ibm.com>
// *HWP Team            : Perv
// *HWP Level           : 3
// *HWP Consumed by     : HB
//------------------------------------------------------------------------------

//## auto_generated
#include <p9_mem_pll_reset.H>
#include <p9_perv_scom_addresses.H>
#include <p9_perv_scom_addresses_fld.H>

enum P9_MEM_PLL_RESET_Private_Constants
{
    OPCG_ALIGN_SCAN_RATIO = 0b00000,             // 1:1
    OPCG_ALIGN_INOP_ALIGN = 0b0101,              // 8:1
    OPCG_ALIGN_INOP_WAIT = 0x0,
    OPCG_ALIGN_WAIT_CYCLES = 0x020,
    P9_OPCG_DONE_SCAN0_POLL_COUNT = 200,         // Scan0 Poll count
    P9_OPCG_DONE_SCAN0_HW_NS_DELAY = 16000,      // unit is nano seconds [min : 8k cycles x 4 = 8000/2 x 4 = 16000 x 10(-9) = 16 us
    //                       max : 8k cycles  =  (8000/25) x 10 (-6) = 320 us]
    P9_OPCG_DONE_SCAN0_SIM_CYCLE_DELAY = 800000  // unit is cycles, to match the poll count change ( 10000 * 8 )
};

/// @brief Scan0 PLL bndy ring to prepare for PLL re-initialization
///
/// --Write Clock Region Register
/// --Write Scan Select Register
/// --Set OPCG_REG0 register bit 0='0' / 2='1' to trigger scan0
/// --Poll OPCG done bit to check for scan0 completeness
/// --Clear Clock Region register
/// --Clear Scan Select register
///
/// @param[in] i_target Reference to TARGET_TYPE_PERV
///
/// @return FAPI2_RC_SUCCESS if success, else error code.
fapi2::ReturnCode
p9_mem_pll_reset_scan0_bndy(const fapi2::Target<fapi2::TARGET_TYPE_PERV>& i_target)
{
    FAPI_DBG("Entering ...");
    uint8_t l_timeout = P9_OPCG_DONE_SCAN0_POLL_COUNT;
    fapi2::buffer<uint64_t> l_clk_region = 0;
    fapi2::buffer<uint64_t> l_scan_region = 0;
    fapi2::buffer<uint64_t> l_opcg_reg0 = 0;
    fapi2::buffer<uint64_t> l_cplt_stat0 = 0;

    // configure clock region register (region=PLL, all tholds)
    l_clk_region.setBit<PERV_1_SCAN_REGION_TYPE_UNIT10>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_SL>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_NSL>();
    l_clk_region.setBit<PERV_1_CLK_REGION_SEL_THOLD_ARY>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_CLK_REGION, l_clk_region),
             "Error from putScom (PERV_CLK_REGION)");

    // configure scan region register (region=PLL, type=BNDY)
    l_scan_region.setBit<PERV_1_SCAN_REGION_TYPE_UNIT10>();
    l_scan_region.setBit<PERV_1_SCAN_REGION_TYPE_BNDY>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_SCAN_REGION_TYPE, l_scan_region),
             "Error from putScom (PERV_SCAN_REGION_TYPE)");

    // configure OPCG reg0, trigger scan0
    FAPI_TRY(fapi2::getScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from getScom (PERV_OPCG_REG0), clear RUNN");
    l_opcg_reg0.clearBit<PERV_1_OPCG_REG0_RUNN_MODE>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from putScom (PERV_OPCG_REG0), clear RUNN");
    l_opcg_reg0.setBit<PERV_1_OPCG_REG0_RUN_SCAN0>();
    FAPI_TRY(fapi2::putScom(i_target, PERV_OPCG_REG0, l_opcg_reg0),
             "Error from putScom (PERV_OPCG_REG0), trigger scan0");

    FAPI_DBG("Poll OPCG done bit to check for run-N completeness");

    while (l_timeout != 0)
    {
        FAPI_TRY(fapi2::getScom(i_target, PERV_CPLT_STAT0, l_cplt_stat0),
                 "Error from getScom (PERV_CPLT_STAT0)");

        if (l_cplt_stat0.getBit<PERV_1_CPLT_STAT0_CC_CTRL_OPCG_DONE_DC>())
        {
            break;
        }

        fapi2::delay(P9_OPCG_DONE_SCAN0_HW_NS_DELAY,
                     P9_OPCG_DONE_SCAN0_SIM_CYCLE_DELAY);
        --l_timeout;
    }

    FAPI_ASSERT(l_timeout > 0,
                fapi2::SBE_SCAN0_DONE_POLL_THRESHOLD_ERR()
                .set_TARGET_CHIPLET(i_target)
                .set_PERV_CPLT_STAT0(l_cplt_stat0)
                .set_LOOP_COUNT(P9_OPCG_DONE_SCAN0_POLL_COUNT)
                .set_HW_DELAY(P9_OPCG_DONE_SCAN0_HW_NS_DELAY),
                "Timeout polling for OPCG_DONE for scan0 flush");

    // cleanup, clear clock region & scan select registers
    FAPI_TRY(fapi2::putScom(i_target, PERV_CLK_REGION, 0x0),
             "Error from putScom (PERV_CLK_REGION), clear");
    FAPI_TRY(fapi2::putScom(i_target, PERV_SCAN_REGION_TYPE, 0x0),
             "Error from putScom (PERV_SCAN_REGION_TYPE), clear");

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

fapi2::ReturnCode p9_mem_pll_reset(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target_chiplet)
{
    uint8_t l_read_attr = 0;
    fapi2::buffer<uint64_t> l_data64;

    FAPI_INF("Entering ...");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MC_SYNC_MODE, i_target_chiplet, l_read_attr));

    if ( !l_read_attr )
    {
        for (auto l_chplt_trgt :  i_target_chiplet.getChildren<fapi2::TARGET_TYPE_PERV>
             (fapi2::TARGET_FILTER_ALL_MC, fapi2::TARGET_STATE_FUNCTIONAL))
        {
            //Assert endpoint reset
            FAPI_DBG("Asserting endpoint reset");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PCB_EP_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));

            //Move MC PLL into reset state
            FAPI_DBG("Move MC PLL into reset state");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_BYPASS>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL0_PLL_TEST_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WOR, l_data64));

            //Assert MEM PDLY and DCC  bypass
            FAPI_DBG("Assert MEM PDLY and DCC bypass");
            l_data64.flush<0>();
            l_data64.setBit<PERV_1_NET_CTRL1_CLK_DCC_BYPASS_EN>();
            l_data64.setBit<PERV_1_NET_CTRL1_CLK_PDLY_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WOR, l_data64));

            //Clear endpoint reset
            FAPI_DBG("Dropping endpoint reset");
            l_data64.flush<1>();
            l_data64.clearBit<PERV_1_NET_CTRL0_PCB_EP_RESET>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

            //Disable listen to sync pulse to MC chiplet, when MEM is not in sync to nest
            FAPI_DBG("Disable listen to sync pulse");
            FAPI_TRY(fapi2::getScom(l_chplt_trgt, PERV_SYNC_CONFIG, l_data64));
            l_data64.setBit<PERV_1_SYNC_CONFIG_LISTEN_TO_PULSE_DIS>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_SYNC_CONFIG, l_data64));

            //Initialize OPCG_ALIGN register
            FAPI_DBG("Initalize OPCG_ALIGN register");
            l_data64.flush<0>();
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_INOP, PERV_1_OPCG_ALIGN_INOP_LEN>(OPCG_ALIGN_INOP_ALIGN);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_INOP_WAIT, PERV_1_OPCG_ALIGN_INOP_WAIT_LEN>(OPCG_ALIGN_INOP_WAIT);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_WAIT_CYCLES, PERV_1_OPCG_ALIGN_WAIT_CYCLES_LEN>(OPCG_ALIGN_WAIT_CYCLES);
            l_data64.insertFromRight<PERV_1_OPCG_ALIGN_SCAN_RATIO, PERV_1_OPCG_ALIGN_SCAN_RATIO_LEN>(OPCG_ALIGN_SCAN_RATIO);
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_OPCG_ALIGN, l_data64));

            // scan0 flush PLL boundary ring
            FAPI_DBG("Executing scan0 flush for PLL bndy ring");
            FAPI_TRY(p9_mem_pll_reset_scan0_bndy(l_chplt_trgt),
                     "Error from p9_mem_pll_reset_scan0_bndy");
        }
    }

    FAPI_INF("Exiting ...");

fapi_try_exit:
    return fapi2::current_err;
}
<|endoftext|>