Y2R PR cleanup (#16)

* Update the code of service y2r!

* Cleanup
This commit is contained in:
Dragios 2016-04-16 01:41:08 +08:00
parent 47ce9f29f3
commit 074ad7e9ef
2 changed files with 196 additions and 68 deletions

View File

@ -4,6 +4,7 @@
#include <cstring>
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/logging/log.h"
@ -28,7 +29,7 @@ struct ConversionParameters {
u16 input_line_width;
u16 input_lines;
StandardCoefficient standard_coefficient;
u8 reserved;
u8 padding;
u16 alpha;
};
static_assert(sizeof(ConversionParameters) == 12, "ConversionParameters struct has incorrect size");
@ -73,7 +74,7 @@ ResultCode ConversionConfiguration::SetInputLines(u16 lines) {
ResultCode ConversionConfiguration::SetStandardCoefficient(StandardCoefficient standard_coefficient) {
size_t index = static_cast<size_t>(standard_coefficient);
if (index >= 4) {
if (index >= ARRAY_SIZE(standard_coefficients)) {
return ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::CAM,
ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E053ED
}
@ -86,36 +87,76 @@ static void SetInputFormat(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
conversion.input_format = static_cast<InputFormat>(cmd_buff[1]);
LOG_DEBUG(Service_Y2R, "called input_format=%hhu", conversion.input_format);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called input_format=%hhu", conversion.input_format);
}
static void GetInputFormat(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(conversion.input_format);
LOG_DEBUG(Service_Y2R, "called Get input_format=%hhu", conversion.input_format);
}
static void SetOutputFormat(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
conversion.output_format = static_cast<OutputFormat>(cmd_buff[1]);
LOG_DEBUG(Service_Y2R, "called output_format=%hhu", conversion.output_format);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called output_format=%hhu", conversion.output_format);
}
static void GetOutputFormat(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(conversion.output_format);
LOG_DEBUG(Service_Y2R, "called Get output_format=%hhu", conversion.output_format);
}
static void SetRotation(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
conversion.rotation = static_cast<Rotation>(cmd_buff[1]);
LOG_DEBUG(Service_Y2R, "called rotation=%hhu", conversion.rotation);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called rotation=%hhu", conversion.rotation);
}
static void GetRotation(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(conversion.rotation);
LOG_DEBUG(Service_Y2R, "called Get rotation=%hhu", conversion.rotation);
}
static void SetBlockAlignment(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
conversion.block_alignment = static_cast<BlockAlignment>(cmd_buff[1]);
LOG_DEBUG(Service_Y2R, "called alignment=%hhu", conversion.block_alignment);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called block_alignment=%hhu", conversion.block_alignment);
}
static void GetBlockAlignment(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(conversion.block_alignment);
LOG_DEBUG(Service_Y2R, "called Get block_alignment=%hhu", conversion.block_alignment);
}
static void SetTransferEndInterrupt(Service::Interface* self) {
@ -123,6 +164,7 @@ static void SetTransferEndInterrupt(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0xD, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "(STUBBED) called");
}
@ -137,6 +179,7 @@ static void GetTransferEndEvent(Service::Interface* self) {
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[3] = Kernel::g_handle_table.Create(completion_event).MoveFrom();
LOG_DEBUG(Service_Y2R, "called");
}
@ -148,11 +191,12 @@ static void SetSendingY(Service::Interface* self) {
conversion.src_Y.transfer_unit = cmd_buff[3];
conversion.src_Y.gap = cmd_buff[4];
u32 src_process_handle = cmd_buff[6];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
"src_process_handle=0x%08X", conversion.src_Y.image_size,
conversion.src_Y.transfer_unit, conversion.src_Y.gap, src_process_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
static void SetSendingU(Service::Interface* self) {
@ -163,11 +207,12 @@ static void SetSendingU(Service::Interface* self) {
conversion.src_U.transfer_unit = cmd_buff[3];
conversion.src_U.gap = cmd_buff[4];
u32 src_process_handle = cmd_buff[6];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
"src_process_handle=0x%08X", conversion.src_U.image_size,
conversion.src_U.transfer_unit, conversion.src_U.gap, src_process_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
static void SetSendingV(Service::Interface* self) {
@ -178,11 +223,12 @@ static void SetSendingV(Service::Interface* self) {
conversion.src_V.transfer_unit = cmd_buff[3];
conversion.src_V.gap = cmd_buff[4];
u32 src_process_handle = cmd_buff[6];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
"src_process_handle=0x%08X", conversion.src_V.image_size,
conversion.src_V.transfer_unit, conversion.src_V.gap, src_process_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
static void SetSendingYUYV(Service::Interface* self) {
@ -193,11 +239,12 @@ static void SetSendingYUYV(Service::Interface* self) {
conversion.src_YUYV.transfer_unit = cmd_buff[3];
conversion.src_YUYV.gap = cmd_buff[4];
u32 src_process_handle = cmd_buff[6];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
"src_process_handle=0x%08X", conversion.src_YUYV.image_size,
conversion.src_YUYV.transfer_unit, conversion.src_YUYV.gap, src_process_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
static void SetReceiving(Service::Interface* self) {
@ -208,26 +255,51 @@ static void SetReceiving(Service::Interface* self) {
conversion.dst.transfer_unit = cmd_buff[3];
conversion.dst.gap = cmd_buff[4];
u32 dst_process_handle = cmd_buff[6];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
"dst_process_handle=0x%08X", conversion.dst.image_size,
conversion.dst.transfer_unit, conversion.dst.gap,
dst_process_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
static void SetInputLineWidth(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u16 width = cmd_buff[1];
cmd_buff[1] = conversion.SetInputLineWidth(width).raw;
LOG_DEBUG(Service_Y2R, "called input_line_width=%u", cmd_buff[1]);
cmd_buff[1] = conversion.SetInputLineWidth(cmd_buff[1]).raw;
}
static void GetInputLineWidth(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = conversion.input_line_width;
LOG_DEBUG(Service_Y2R, "called input_line_width=%u", conversion.input_line_width);
}
static void SetInputLines(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
LOG_DEBUG(Service_Y2R, "called input_line_number=%u", cmd_buff[1]);
cmd_buff[1] = conversion.SetInputLines(cmd_buff[1]).raw;
u16 lines = cmd_buff[1];
cmd_buff[1] = conversion.SetInputLines(lines).raw;
LOG_DEBUG(Service_Y2R, "called input_lines=%u", cmd_buff[1]);
}
static void GetInputLines(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = conversion.input_lines;
LOG_DEBUG(Service_Y2R, "called Get input_lines=%u", conversion.input_lines);
}
static void SetCoefficient(Service::Interface* self) {
@ -235,28 +307,68 @@ static void SetCoefficient(Service::Interface* self) {
const u16* coefficients = reinterpret_cast<const u16*>(&cmd_buff[1]);
std::memcpy(conversion.coefficients.data(), coefficients, sizeof(CoefficientSet));
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called coefficients=[%hX, %hX, %hX, %hX, %hX, %hX, %hX, %hX]",
coefficients[0], coefficients[1], coefficients[2], coefficients[3],
coefficients[4], coefficients[5], coefficients[6], coefficients[7]);
}
static void GetCoefficient(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
u16* coefficients = reinterpret_cast<u16*>(&cmd_buff[2]);
std::memcpy(coefficients, conversion.coefficients.data(), sizeof(CoefficientSet));
LOG_DEBUG(Service_Y2R, "called Get coefficients=[%hX, %hX, %hX, %hX, %hX, %hX, %hX, %hX]",
coefficients[0], coefficients[1], coefficients[2], coefficients[3],
coefficients[4], coefficients[5], coefficients[6], coefficients[7]);
}
static void SetStandardCoefficient(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
LOG_DEBUG(Service_Y2R, "called standard_coefficient=%u", cmd_buff[1]);
StandardCoefficient index = static_cast<StandardCoefficient>(cmd_buff[1]);
cmd_buff[1] = conversion.SetStandardCoefficient((StandardCoefficient)cmd_buff[1]).raw;
cmd_buff[1] = conversion.SetStandardCoefficient(index).raw;
LOG_DEBUG(Service_Y2R, "called standard_coefficient=%hu", index);
}
static void GetStandardCoefficientParams(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 index = cmd_buff[1];
if (index < ARRAY_SIZE(standard_coefficients)) {
cmd_buff[1] = RESULT_SUCCESS.raw;
std::memcpy(&cmd_buff[2], &standard_coefficients[index], sizeof(CoefficientSet));
LOG_DEBUG(Service_Y2R, "called Get standard_coefficient:0x%08X ", index);
} else {
cmd_buff[1] = -1;
LOG_ERROR(Service_Y2R, "called Get standard_coefficient:0x%08X The argument is invalid!", index);
}
}
static void SetAlpha(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
conversion.alpha = cmd_buff[1];
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called alpha=%hu", conversion.alpha);
}
static void GetAlpha(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = conversion.alpha;
LOG_DEBUG(Service_Y2R, "called Get alpha=%hu", conversion.alpha);
}
static void StartConversion(Service::Interface* self) {
@ -281,6 +393,7 @@ static void StopConversion(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0x27, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called");
}
@ -295,23 +408,24 @@ static void IsBusyConversion(Service::Interface* self) {
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0; // StartConversion always finishes immediately
LOG_DEBUG(Service_Y2R, "called");
}
/**
* Y2R_U::SetConversionParams service function
*/
static void SetConversionParams(Service::Interface* self) {
static void SetPackageParameter(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
auto params = reinterpret_cast<const ConversionParameters*>(&cmd_buff[1]);
LOG_DEBUG(Service_Y2R,
"called input_format=%hhu output_format=%hhu rotation=%hhu block_alignment=%hhu "
"input_line_width=%hu input_lines=%hu standard_coefficient=%hhu "
"reserved=%hhu alpha=%hX",
"padding=%hhu alpha=%hX",
params->input_format, params->output_format, params->rotation, params->block_alignment,
params->input_line_width, params->input_lines, params->standard_coefficient,
params->reserved, params->alpha);
params->padding, params->alpha);
ResultCode result = RESULT_SUCCESS;
@ -325,6 +439,7 @@ static void SetConversionParams(Service::Interface* self) {
if (result.IsError()) goto cleanup;
result = conversion.SetStandardCoefficient(params->standard_coefficient);
if (result.IsError()) goto cleanup;
conversion.padding = params->padding;
conversion.alpha = params->alpha;
cleanup:
@ -332,11 +447,21 @@ cleanup:
cmd_buff[1] = result.raw;
}
static void GetPackageParameter(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
std::memcpy(&cmd_buff[2], &conversion, sizeof(ConversionParameters));
LOG_DEBUG(Service_Y2R, "called");
}
static void PingProcess(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0;
LOG_WARNING(Service_Y2R, "(STUBBED) called");
}
@ -362,6 +487,7 @@ static void DriverInitialize(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0x2B, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called");
}
@ -370,18 +496,19 @@ static void DriverFinalize(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0x2C, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_DEBUG(Service_Y2R, "called");
}
const Interface::FunctionInfo FunctionTable[] = {
{0x00010040, SetInputFormat, "SetInputFormat"},
{0x00020000, nullptr, "GetInputFormat"},
{0x00020000, GetInputFormat, "GetInputFormat"},
{0x00030040, SetOutputFormat, "SetOutputFormat"},
{0x00040000, nullptr, "GetOutputFormat"},
{0x00040000, GetOutputFormat, "GetOutputFormat"},
{0x00050040, SetRotation, "SetRotation"},
{0x00060000, nullptr, "GetRotation"},
{0x00060000, GetRotation, "GetRotation"},
{0x00070040, SetBlockAlignment, "SetBlockAlignment"},
{0x00080000, nullptr, "GetBlockAlignment"},
{0x00080000, GetBlockAlignment, "GetBlockAlignment"},
{0x00090040, nullptr, "SetSpacialDithering"},
{0x000A0000, nullptr, "GetSpacialDithering"},
{0x000B0040, nullptr, "SetTemporalDithering"},
@ -399,25 +526,25 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x00180102, SetReceiving, "SetReceiving"},
{0x00190000, nullptr, "IsFinishedReceiving"},
{0x001A0040, SetInputLineWidth, "SetInputLineWidth"},
{0x001B0000, nullptr, "GetInputLineWidth"},
{0x001B0000, GetInputLineWidth, "GetInputLineWidth"},
{0x001C0040, SetInputLines, "SetInputLines"},
{0x001D0000, nullptr, "GetInputLines"},
{0x001D0000, GetInputLines, "GetInputLines"},
{0x001E0100, SetCoefficient, "SetCoefficient"},
{0x001F0000, nullptr, "GetCoefficient"},
{0x001F0000, GetCoefficient, "GetCoefficient"},
{0x00200040, SetStandardCoefficient, "SetStandardCoefficient"},
{0x00210040, nullptr, "GetStandardCoefficientParams"},
{0x00210040, GetStandardCoefficientParams, "GetStandardCoefficientParams"},
{0x00220040, SetAlpha, "SetAlpha"},
{0x00230000, nullptr, "GetAlpha"},
{0x00230000, GetAlpha, "GetAlpha"},
{0x00240200, nullptr, "SetDitheringWeightParams"},
{0x00250000, nullptr, "GetDitheringWeightParams"},
{0x00260000, StartConversion, "StartConversion"},
{0x00270000, StopConversion, "StopConversion"},
{0x00280000, IsBusyConversion, "IsBusyConversion"},
{0x002901C0, SetConversionParams, "SetConversionParams"},
{0x002901C0, SetPackageParameter, "SetPackageParameter"},
{0x002A0000, PingProcess, "PingProcess"},
{0x002B0000, DriverInitialize, "DriverInitialize"},
{0x002C0000, DriverFinalize, "DriverFinalize"},
{0x002D0000, nullptr, "GetPackageParameter"},
{0x002D0000, GetPackageParameter, "GetPackageParameter"},
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -97,6 +97,7 @@ struct ConversionConfiguration {
u16 input_line_width;
u16 input_lines;
CoefficientSet coefficients;
u8 padding;
u16 alpha;
/// Input parameters for the Y (luma) plane