From 924292f2cc7f7f766fdaa8d7d35bfe752b3f4bd1 Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 24 May 2017 12:45:36 +0300 Subject: cam: use IPCHelper --- src/core/hle/service/cam/cam.cpp | 516 ++++++++++++++++++--------------------- 1 file changed, 238 insertions(+), 278 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index 95665e754..957013d5b 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -55,7 +55,7 @@ struct PortConfig { u16 x1; // x-coordinate of ending position for trimming u16 y1; // y-coordinate of ending position for trimming - u32 transfer_bytes; + u16 transfer_bytes; Kernel::SharedPtr completion_event; Kernel::SharedPtr buffer_error_interrupt_event; @@ -244,9 +244,10 @@ using CameraSet = CommandParamBitSet<3>; } // namespace void StartCapture(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x01, 1, 0); + const PortSet port_select(rp.Pop()); - const PortSet port_select(cmd_buff[1]); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { @@ -267,21 +268,20 @@ void StartCapture(Service::Interface* self) { LOG_WARNING(Service_CAM, "port %u already started", i); } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x1, 1, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void StopCapture(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x02, 1, 0); + const PortSet port_select(rp.Pop()); - const PortSet port_select(cmd_buff[1]); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { @@ -293,21 +293,20 @@ void StopCapture(Service::Interface* self) { LOG_WARNING(Service_CAM, "port %u already stopped", i); } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x2, 1, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void IsBusy(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0); + const PortSet port_select(rp.Pop()); - const PortSet port_select(cmd_buff[1]); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsValid()) { bool is_busy = true; @@ -315,80 +314,74 @@ void IsBusy(Service::Interface* self) { for (int i : port_select) { is_busy &= ports[i].is_busy; } - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = is_busy ? 1 : 0; + rb.Push(RESULT_SUCCESS); + rb.Push(is_busy); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.Skip(1, false); } - cmd_buff[0] = IPC::MakeHeader(0x3, 2, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void ClearBuffer(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x04, 1, 0); + const PortSet port_select(rp.Pop()); - cmd_buff[0] = IPC::MakeHeader(0x4, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); LOG_WARNING(Service_CAM, "(STUBBED) called, port_select=%u", port_select.m_val); } void GetVsyncInterruptEvent(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x05, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = IPC::CopyHandleDesc(); - cmd_buff[3] = Kernel::g_handle_table.Create(ports[port].vsync_interrupt_event).MoveFrom(); + rb.Push(RESULT_SUCCESS); + rb.PushCopyHandles( + Kernel::g_handle_table.Create(ports[port].vsync_interrupt_event).MoveFrom()); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; - cmd_buff[2] = IPC::CopyHandleDesc(); - cmd_buff[2] = 0; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.PushCopyHandles(0); } - cmd_buff[0] = IPC::MakeHeader(0x5, 1, 2); - LOG_WARNING(Service_CAM, "(STUBBED) called, port_select=%u", port_select.m_val); } void GetBufferErrorInterruptEvent(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x06, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = IPC::CopyHandleDesc(); - cmd_buff[3] = - Kernel::g_handle_table.Create(ports[port].buffer_error_interrupt_event).MoveFrom(); + rb.Push(RESULT_SUCCESS); + rb.PushCopyHandles( + Kernel::g_handle_table.Create(ports[port].buffer_error_interrupt_event).MoveFrom()); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; - cmd_buff[2] = IPC::CopyHandleDesc(); - cmd_buff[2] = 0; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.PushCopyHandles(0); } LOG_WARNING(Service_CAM, "(STUBBED) called, port_select=%u", port_select.m_val); } void SetReceiving(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const VAddr dest = cmd_buff[1]; - const PortSet port_select(cmd_buff[2]); - const u32 image_size = cmd_buff[3]; - const u32 trans_unit = cmd_buff[4] & 0xFFFF; - + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x07, 4, 2); + const VAddr dest = rp.Pop(); + const PortSet port_select(rp.Pop()); + const u32 image_size = rp.Pop(); + const u16 trans_unit = rp.Pop(); + rp.PopHandle(); // Handle to destination process. not used + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); if (port_select.IsSingle()) { int port_id = *port_select.begin(); PortConfig& port = ports[port_id]; @@ -403,149 +396,143 @@ void SetReceiving(Service::Interface* self) { port.is_pending_receiving = true; } - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = IPC::CopyHandleDesc(); - cmd_buff[3] = Kernel::g_handle_table.Create(port.completion_event).MoveFrom(); + rb.Push(RESULT_SUCCESS); + rb.PushCopyHandles(Kernel::g_handle_table.Create(port.completion_event).MoveFrom()); } else { - LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.PushCopyHandles(0); } - cmd_buff[0] = IPC::MakeHeader(0x7, 1, 2); - LOG_DEBUG(Service_CAM, "called, addr=0x%X, port_select=%u, image_size=%u, trans_unit=%u", dest, port_select.m_val, image_size, trans_unit); } void IsFinishedReceiving(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x08, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = (ports[port].is_receiving || ports[port].is_pending_receiving) ? 0 : 1; + rb.Push(RESULT_SUCCESS); + rb.Push(ports[port].is_receiving || ports[port].is_pending_receiving); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.Skip(1, false); } - cmd_buff[0] = IPC::MakeHeader(0x8, 2, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void SetTransferLines(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); - const u32 transfer_lines = cmd_buff[2] & 0xFFFF; - const u32 width = cmd_buff[3] & 0xFFFF; - const u32 height = cmd_buff[4] & 0xFFFF; + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x09, 4, 0); + const PortSet port_select(rp.Pop()); + const u16 transfer_lines = rp.Pop(); + const u16 width = rp.Pop(); + const u16 height = rp.Pop(); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { ports[i].transfer_bytes = transfer_lines * width * 2; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x9, 1, 0); - LOG_WARNING(Service_CAM, "(STUBBED) called, port_select=%u, lines=%u, width=%u, height=%u", port_select.m_val, transfer_lines, width, height); } void GetMaxLines(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0A, 2, 0); + const u16 width = rp.Pop(); + const u16 height = rp.Pop(); - const u32 width = cmd_buff[1] & 0xFFFF; - const u32 height = cmd_buff[2] & 0xFFFF; + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); // Note: the result of the algorithm below are hwtested with width < 640 and with height < 480 constexpr u32 MIN_TRANSFER_UNIT = 256; constexpr u32 MAX_BUFFER_SIZE = 2560; if (width * height * 2 % MIN_TRANSFER_UNIT != 0) { - cmd_buff[1] = ERROR_OUT_OF_RANGE.raw; + rb.Push(ERROR_OUT_OF_RANGE); + rb.Skip(1, false); } else { u32 lines = MAX_BUFFER_SIZE / width; if (lines > height) { lines = height; } - cmd_buff[1] = RESULT_SUCCESS.raw; + ResultCode result = RESULT_SUCCESS; while (height % lines != 0 || (lines * width * 2 % MIN_TRANSFER_UNIT != 0)) { --lines; if (lines == 0) { - cmd_buff[1] = ERROR_OUT_OF_RANGE.raw; + result = ERROR_OUT_OF_RANGE; break; } } - cmd_buff[2] = lines; + rb.Push(result); + rb.Push(lines); } - cmd_buff[0] = IPC::MakeHeader(0xA, 2, 0); - LOG_DEBUG(Service_CAM, "called, width=%u, height=%u", width, height); } void SetTransferBytes(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); - const u32 transfer_bytes = cmd_buff[2] & 0xFFFF; - const u32 width = cmd_buff[3] & 0xFFFF; - const u32 height = cmd_buff[4] & 0xFFFF; + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0B, 4, 0); + const PortSet port_select(rp.Pop()); + const u16 transfer_bytes = rp.Pop(); + const u16 width = rp.Pop(); + const u16 height = rp.Pop(); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { ports[i].transfer_bytes = transfer_bytes; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0xB, 1, 0); - LOG_WARNING(Service_CAM, "(STUBBED)called, port_select=%u, bytes=%u, width=%u, height=%u", port_select.m_val, transfer_bytes, width, height); } void GetTransferBytes(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0C, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = ports[port].transfer_bytes; + rb.Push(RESULT_SUCCESS.raw); + rb.Push(ports[port].transfer_bytes); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.Skip(1, false); } - cmd_buff[0] = IPC::MakeHeader(0xC, 2, 0); - LOG_WARNING(Service_CAM, "(STUBBED)called, port_select=%u", port_select.m_val); } void GetMaxBytes(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0D, 2, 0); + const u16 width = rp.Pop(); + const u16 height = rp.Pop(); - const u32 width = cmd_buff[1] & 0xFFFF; - const u32 height = cmd_buff[2] & 0xFFFF; + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); // Note: the result of the algorithm below are hwtested with width < 640 and with height < 480 constexpr u32 MIN_TRANSFER_UNIT = 256; constexpr u32 MAX_BUFFER_SIZE = 2560; if (width * height * 2 % MIN_TRANSFER_UNIT != 0) { - cmd_buff[1] = ERROR_OUT_OF_RANGE.raw; + rb.Push(ERROR_OUT_OF_RANGE); + rb.Skip(1, false); } else { u32 bytes = MAX_BUFFER_SIZE; @@ -553,63 +540,59 @@ void GetMaxBytes(Service::Interface* self) { bytes -= MIN_TRANSFER_UNIT; } - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = bytes; + rb.Push(RESULT_SUCCESS); + rb.Push(bytes); } - cmd_buff[0] = IPC::MakeHeader(0xD, 2, 0); LOG_DEBUG(Service_CAM, "called, width=%u, height=%u", width, height); } void SetTrimming(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); - const bool trim = (cmd_buff[2] & 0xFF) != 0; + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0E, 2, 0); + const PortSet port_select(rp.Pop()); + const bool trim = rp.Pop(); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { ports[i].is_trimming = trim; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0xE, 1, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u, trim=%d", port_select.m_val, trim); } void IsTrimming(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0F, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = ports[port].is_trimming; + rb.Push(RESULT_SUCCESS); + rb.Push(ports[port].is_trimming); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.Skip(1, false); } - cmd_buff[0] = IPC::MakeHeader(0xF, 2, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void SetTrimmingParams(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); - const u16 x0 = static_cast(cmd_buff[2] & 0xFFFF); - const u16 y0 = static_cast(cmd_buff[3] & 0xFFFF); - const u16 x1 = static_cast(cmd_buff[4] & 0xFFFF); - const u16 y1 = static_cast(cmd_buff[5] & 0xFFFF); - + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x10, 5, 0); + const PortSet port_select(rp.Pop()); + const u16 x0 = rp.Pop(); + const u16 y0 = rp.Pop(); + const u16 x1 = rp.Pop(); + const u16 y1 = rp.Pop(); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { ports[i].x0 = x0; @@ -617,49 +600,46 @@ void SetTrimmingParams(Service::Interface* self) { ports[i].x1 = x1; ports[i].y1 = y1; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x10, 1, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u, x0=%u, y0=%u, x1=%u, y1=%u", port_select.m_val, x0, y0, x1, y1); } void GetTrimmingParams(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x11, 1, 0); + const PortSet port_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(5, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = ports[port].x0; - cmd_buff[3] = ports[port].y0; - cmd_buff[4] = ports[port].x1; - cmd_buff[5] = ports[port].y1; + rb.Push(RESULT_SUCCESS); + rb.Push(ports[port].x0); + rb.Push(ports[port].y0); + rb.Push(ports[port].x1); + rb.Push(ports[port].y1); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); + rb.Skip(4, false); } - cmd_buff[0] = IPC::MakeHeader(0x11, 5, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u", port_select.m_val); } void SetTrimmingParamsCenter(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const PortSet port_select(cmd_buff[1]); - const u16 trim_w = static_cast(cmd_buff[2] & 0xFFFF); - const u16 trim_h = static_cast(cmd_buff[3] & 0xFFFF); - const u16 cam_w = static_cast(cmd_buff[4] & 0xFFFF); - const u16 cam_h = static_cast(cmd_buff[5] & 0xFFFF); - + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x12, 5, 0); + const PortSet port_select(rp.Pop()); + const u16 trim_w = rp.Pop(); + const u16 trim_h = rp.Pop(); + const u16 cam_w = rp.Pop(); + const u16 cam_h = rp.Pop(); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (port_select.IsValid()) { for (int i : port_select) { ports[i].x0 = (cam_w - trim_w) / 2; @@ -667,23 +647,21 @@ void SetTrimmingParamsCenter(Service::Interface* self) { ports[i].x1 = ports[i].x0 + trim_w; ports[i].y1 = ports[i].y0 + trim_h; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x12, 1, 0); - LOG_DEBUG(Service_CAM, "called, port_select=%u, trim_w=%u, trim_h=%u, cam_w=%u, cam_h=%u", port_select.m_val, trim_w, trim_h, cam_w, cam_h); } void Activate(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x13, 1, 0); + const CameraSet camera_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid()) { if (camera_select.m_val == 0) { // deactive all for (int i = 0; i < 2; ++i) { @@ -694,10 +672,10 @@ void Activate(Service::Interface* self) { } ports[i].is_active = false; } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else if (camera_select[0] && camera_select[1]) { LOG_ERROR(Service_CAM, "camera 0 and 1 can't be both activated"); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } else { if (camera_select[0]) { ActivatePort(0, 0); @@ -708,24 +686,22 @@ void Activate(Service::Interface* self) { if (camera_select[2]) { ActivatePort(1, 2); } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u", camera_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x13, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u", camera_select.m_val); } void SwitchContext(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const ContextSet context_select(cmd_buff[2]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x14, 2, 0); + const CameraSet camera_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsSingle()) { int context = *context_select.begin(); for (int camera : camera_select) { @@ -736,26 +712,24 @@ void SwitchContext(Service::Interface* self) { cameras[camera].impl->SetFormat(context_config.format); cameras[camera].impl->SetResolution(context_config.resolution); } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x14, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); } void FlipImage(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const Flip flip = static_cast(cmd_buff[2] & 0xFF); - const ContextSet context_select(cmd_buff[3]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1D, 3, 0); + const CameraSet camera_select(rp.Pop()); + const Flip flip = static_cast(rp.Pop()); + const ContextSet context_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera : camera_select) { for (int context : context_select) { @@ -765,32 +739,30 @@ void FlipImage(Service::Interface* self) { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x1D, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, flip=%d, context_select=%u", camera_select.m_val, static_cast(flip), context_select.m_val); } void SetDetailSize(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1E, 8, 0); + const CameraSet camera_select(rp.Pop()); Resolution resolution; - resolution.width = static_cast(cmd_buff[2] & 0xFFFF); - resolution.height = static_cast(cmd_buff[3] & 0xFFFF); - resolution.crop_x0 = static_cast(cmd_buff[4] & 0xFFFF); - resolution.crop_y0 = static_cast(cmd_buff[5] & 0xFFFF); - resolution.crop_x1 = static_cast(cmd_buff[6] & 0xFFFF); - resolution.crop_y1 = static_cast(cmd_buff[7] & 0xFFFF); - const ContextSet context_select(cmd_buff[8]); - + resolution.width = rp.Pop(); + resolution.height = rp.Pop(); + resolution.crop_x0 = rp.Pop(); + resolution.crop_y0 = rp.Pop(); + resolution.crop_x1 = rp.Pop(); + resolution.crop_y1 = rp.Pop(); + const ContextSet context_select(rp.Pop()); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera : camera_select) { for (int context : context_select) { @@ -800,15 +772,13 @@ void SetDetailSize(Service::Interface* self) { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x1E, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, width=%u, height=%u, crop_x0=%u, crop_y0=%u, " "crop_x1=%u, crop_y1=%u, context_select=%u", camera_select.m_val, resolution.width, resolution.height, resolution.crop_x0, @@ -816,12 +786,12 @@ void SetDetailSize(Service::Interface* self) { } void SetSize(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const u32 size = cmd_buff[2] & 0xFF; - const ContextSet context_select(cmd_buff[3]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1F, 3, 0); + const CameraSet camera_select(rp.Pop()); + const u8 size = rp.Pop(); + const ContextSet context_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera : camera_select) { for (int context : context_select) { @@ -831,49 +801,45 @@ void SetSize(Service::Interface* self) { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x1F, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, size=%u, context_select=%u", camera_select.m_val, size, context_select.m_val); } void SetFrameRate(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const FrameRate frame_rate = static_cast(cmd_buff[2] & 0xFF); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x20, 2, 0); + const CameraSet camera_select(rp.Pop()); + const FrameRate frame_rate = static_cast(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid()) { for (int camera : camera_select) { cameras[camera].frame_rate = frame_rate; // TODO(wwylele): consider hinting the actual camera with the expected frame rate } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u", camera_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x20, 1, 0); - LOG_WARNING(Service_CAM, "(STUBBED) called, camera_select=%u, frame_rate=%d", camera_select.m_val, static_cast(frame_rate)); } void SetEffect(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const Effect effect = static_cast(cmd_buff[2] & 0xFF); - const ContextSet context_select(cmd_buff[3]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x22, 3, 0); + const CameraSet camera_select(rp.Pop()); + const Effect effect = static_cast(rp.Pop()); + const ContextSet context_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera : camera_select) { for (int context : context_select) { @@ -883,26 +849,24 @@ void SetEffect(Service::Interface* self) { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x22, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, effect=%d, context_select=%u", camera_select.m_val, static_cast(effect), context_select.m_val); } void SetOutputFormat(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const CameraSet camera_select(cmd_buff[1]); - const OutputFormat format = static_cast(cmd_buff[2] & 0xFF); - const ContextSet context_select(cmd_buff[3]); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x25, 3, 0); + const CameraSet camera_select(rp.Pop()); + const OutputFormat format = static_cast(rp.Pop()); + const ContextSet context_select(rp.Pop()); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera : camera_select) { for (int context : context_select) { @@ -912,34 +876,32 @@ void SetOutputFormat(Service::Interface* self) { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", camera_select.m_val, context_select.m_val); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(0x25, 1, 0); - LOG_DEBUG(Service_CAM, "called, camera_select=%u, format=%d, context_select=%u", camera_select.m_val, static_cast(format), context_select.m_val); } void SynchronizeVsyncTiming(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - const u32 camera_select1 = cmd_buff[1] & 0xFF; - const u32 camera_select2 = cmd_buff[2] & 0xFF; + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x29, 2, 0); + const u8 camera_select1 = rp.Pop(); + const u8 camera_select2 = rp.Pop(); - cmd_buff[0] = IPC::MakeHeader(0x29, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); LOG_WARNING(Service_CAM, "(STUBBED) called, camera_select1=%u, camera_select2=%u", camera_select1, camera_select2); } void GetStereoCameraCalibrationData(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestBuilder rb = + IPC::RequestParser(Kernel::GetCommandBuffer(), 0x2B, 0, 0).MakeBuilder(17, 0); // Default values taken from yuriks' 3DS. Valid data is required here or games using the // calibration get stuck in an infinite CPU loop. @@ -958,35 +920,37 @@ void GetStereoCameraCalibrationData(Service::Interface* self) { data.imageWidth = 640; data.imageHeight = 480; - cmd_buff[0] = IPC::MakeHeader(0x2B, 17, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; - memcpy(&cmd_buff[2], &data, sizeof(data)); + rb.Push(RESULT_SUCCESS); + rb.PushRaw(data); LOG_TRACE(Service_CAM, "called"); } void SetPackageParameterWithoutContext(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x33, 11, 0); PackageParameterWithoutContext package; - std::memcpy(&package, cmd_buff + 1, sizeof(package)); + rp.PopRaw(package); + rp.Skip(4, false); - cmd_buff[0] = IPC::MakeHeader(0x33, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); LOG_WARNING(Service_CAM, "(STUBBED) called"); } -template +template static void SetPackageParameter() { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), command_id, param_length, 0); PackageParameterType package; - std::memcpy(&package, cmd_buff + 1, sizeof(package)); + rp.PopRaw(package); + rp.Skip(param_length - (sizeof(PackageParameterType) + 3) / 4, false); const CameraSet camera_select(static_cast(package.camera_select)); const ContextSet context_select(static_cast(package.context_select)); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera_id : camera_select) { CameraConfig& camera = cameras[camera_id]; @@ -1002,15 +966,13 @@ static void SetPackageParameter() { } } } - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", package.camera_select, package.context_select); - cmd_buff[1] = ERROR_INVALID_ENUM_VALUE.raw; + rb.Push(ERROR_INVALID_ENUM_VALUE); } - cmd_buff[0] = IPC::MakeHeader(command_id, 1, 0); - LOG_DEBUG(Service_CAM, "called"); } @@ -1019,36 +981,35 @@ Resolution PackageParameterWithContext::GetResolution() { } void SetPackageParameterWithContext(Service::Interface* self) { - SetPackageParameter(); + SetPackageParameter(); } void SetPackageParameterWithContextDetail(Service::Interface* self) { - SetPackageParameter(); + SetPackageParameter(); } void GetSuitableY2rStandardCoefficient(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - cmd_buff[0] = IPC::MakeHeader(0x36, 2, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = 0; + IPC::RequestBuilder rb = + IPC::RequestParser(Kernel::GetCommandBuffer(), 0x36, 0, 0).MakeBuilder(2, 0); + rb.Push(RESULT_SUCCESS); + rb.Push(0); LOG_WARNING(Service_CAM, "(STUBBED) called"); } void PlayShutterSound(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - u8 sound_id = cmd_buff[1] & 0xFF; + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x38, 1, 0); + u8 sound_id = rp.Pop(); - cmd_buff[0] = IPC::MakeHeader(0x38, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); LOG_WARNING(Service_CAM, "(STUBBED) called, sound_id=%d", sound_id); } void DriverInitialize(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestBuilder rb = + IPC::RequestParser(Kernel::GetCommandBuffer(), 0x39, 0, 0).MakeBuilder(1, 0); for (int camera_id = 0; camera_id < NumCameras; ++camera_id) { CameraConfig& camera = cameras[camera_id]; @@ -1074,14 +1035,14 @@ void DriverInitialize(Service::Interface* self) { port.Clear(); } - cmd_buff[0] = IPC::MakeHeader(0x39, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); LOG_DEBUG(Service_CAM, "called"); } void DriverFinalize(Service::Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); + IPC::RequestBuilder rb = + IPC::RequestParser(Kernel::GetCommandBuffer(), 0x3A, 0, 0).MakeBuilder(1, 0); CancelReceiving(0); CancelReceiving(1); @@ -1090,8 +1051,7 @@ void DriverFinalize(Service::Interface* self) { camera.impl = nullptr; } - cmd_buff[0] = IPC::MakeHeader(0x3A, 1, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; + rb.Push(RESULT_SUCCESS); LOG_DEBUG(Service_CAM, "called"); } -- cgit v1.2.3 From 8cd9522526de290865094c7ff102db8e2872b471 Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 24 May 2017 12:50:19 +0300 Subject: cam: move u32->u8 trancation to IPCHelper --- src/core/hle/service/cam/cam.cpp | 67 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index 957013d5b..342a0edeb 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -225,8 +225,7 @@ static void ActivatePort(int port_id, int camera_id) { template class CommandParamBitSet : public BitSet8 { public: - explicit CommandParamBitSet(u32 command_param) - : BitSet8(static_cast(command_param & 0xFF)) {} + explicit CommandParamBitSet(u8 command_param) : BitSet8(command_param) {} bool IsValid() const { return m_val < (1 << max_index); @@ -245,7 +244,7 @@ using CameraSet = CommandParamBitSet<3>; void StartCapture(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x01, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -279,7 +278,7 @@ void StartCapture(Service::Interface* self) { void StopCapture(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x02, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -304,7 +303,7 @@ void StopCapture(Service::Interface* self) { void IsBusy(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); @@ -327,7 +326,7 @@ void IsBusy(Service::Interface* self) { void ClearBuffer(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x04, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); @@ -337,7 +336,7 @@ void ClearBuffer(Service::Interface* self) { void GetVsyncInterruptEvent(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x05, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); if (port_select.IsSingle()) { @@ -356,7 +355,7 @@ void GetVsyncInterruptEvent(Service::Interface* self) { void GetBufferErrorInterruptEvent(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x06, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); if (port_select.IsSingle()) { @@ -376,7 +375,7 @@ void GetBufferErrorInterruptEvent(Service::Interface* self) { void SetReceiving(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x07, 4, 2); const VAddr dest = rp.Pop(); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const u32 image_size = rp.Pop(); const u16 trans_unit = rp.Pop(); rp.PopHandle(); // Handle to destination process. not used @@ -409,7 +408,7 @@ void SetReceiving(Service::Interface* self) { void IsFinishedReceiving(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x08, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { @@ -427,7 +426,7 @@ void IsFinishedReceiving(Service::Interface* self) { void SetTransferLines(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x09, 4, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const u16 transfer_lines = rp.Pop(); const u16 width = rp.Pop(); const u16 height = rp.Pop(); @@ -482,7 +481,7 @@ void GetMaxLines(Service::Interface* self) { void SetTransferBytes(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0B, 4, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const u16 transfer_bytes = rp.Pop(); const u16 width = rp.Pop(); const u16 height = rp.Pop(); @@ -504,7 +503,7 @@ void SetTransferBytes(Service::Interface* self) { void GetTransferBytes(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0C, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { @@ -549,7 +548,7 @@ void GetMaxBytes(Service::Interface* self) { void SetTrimming(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0E, 2, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const bool trim = rp.Pop(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -568,7 +567,7 @@ void SetTrimming(Service::Interface* self) { void IsTrimming(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x0F, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { @@ -586,7 +585,7 @@ void IsTrimming(Service::Interface* self) { void SetTrimmingParams(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x10, 5, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const u16 x0 = rp.Pop(); const u16 y0 = rp.Pop(); const u16 x1 = rp.Pop(); @@ -612,7 +611,7 @@ void SetTrimmingParams(Service::Interface* self) { void GetTrimmingParams(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x11, 1, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(5, 0); if (port_select.IsSingle()) { @@ -633,7 +632,7 @@ void GetTrimmingParams(Service::Interface* self) { void SetTrimmingParamsCenter(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x12, 5, 0); - const PortSet port_select(rp.Pop()); + const PortSet port_select(rp.Pop()); const u16 trim_w = rp.Pop(); const u16 trim_h = rp.Pop(); const u16 cam_w = rp.Pop(); @@ -659,7 +658,7 @@ void SetTrimmingParamsCenter(Service::Interface* self) { void Activate(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x13, 1, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid()) { @@ -698,8 +697,8 @@ void Activate(Service::Interface* self) { void SwitchContext(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x14, 2, 0); - const CameraSet camera_select(rp.Pop()); - const ContextSet context_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsSingle()) { @@ -725,9 +724,9 @@ void SwitchContext(Service::Interface* self) { void FlipImage(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1D, 3, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); const Flip flip = static_cast(rp.Pop()); - const ContextSet context_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { @@ -752,7 +751,7 @@ void FlipImage(Service::Interface* self) { void SetDetailSize(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1E, 8, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); Resolution resolution; resolution.width = rp.Pop(); resolution.height = rp.Pop(); @@ -760,7 +759,7 @@ void SetDetailSize(Service::Interface* self) { resolution.crop_y0 = rp.Pop(); resolution.crop_x1 = rp.Pop(); resolution.crop_y1 = rp.Pop(); - const ContextSet context_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { @@ -787,9 +786,9 @@ void SetDetailSize(Service::Interface* self) { void SetSize(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1F, 3, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); const u8 size = rp.Pop(); - const ContextSet context_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { @@ -814,7 +813,7 @@ void SetSize(Service::Interface* self) { void SetFrameRate(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x20, 2, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); const FrameRate frame_rate = static_cast(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -835,9 +834,9 @@ void SetFrameRate(Service::Interface* self) { void SetEffect(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x22, 3, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); const Effect effect = static_cast(rp.Pop()); - const ContextSet context_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { @@ -862,9 +861,9 @@ void SetEffect(Service::Interface* self) { void SetOutputFormat(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x25, 3, 0); - const CameraSet camera_select(rp.Pop()); + const CameraSet camera_select(rp.Pop()); const OutputFormat format = static_cast(rp.Pop()); - const ContextSet context_select(rp.Pop()); + const ContextSet context_select(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { @@ -947,8 +946,8 @@ static void SetPackageParameter() { rp.PopRaw(package); rp.Skip(param_length - (sizeof(PackageParameterType) + 3) / 4, false); - const CameraSet camera_select(static_cast(package.camera_select)); - const ContextSet context_select(static_cast(package.context_select)); + const CameraSet camera_select(package.camera_select); + const ContextSet context_select(package.context_select); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { -- cgit v1.2.3 From 857510a7c084daa337c6e4a1d8a8eafc06253197 Mon Sep 17 00:00:00 2001 From: wwylele Date: Thu, 25 May 2017 16:49:09 +0300 Subject: fixup!cam: use IPCHelper --- src/core/hle/service/cam/cam.cpp | 60 +++++++++++++++++++++++----------------- src/core/hle/service/cam/cam.h | 13 +++++---- 2 files changed, 43 insertions(+), 30 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index 342a0edeb..85af70a3f 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -398,6 +398,7 @@ void SetReceiving(Service::Interface* self) { rb.Push(RESULT_SUCCESS); rb.PushCopyHandles(Kernel::g_handle_table.Create(port.completion_event).MoveFrom()); } else { + LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); rb.Push(ERROR_INVALID_ENUM_VALUE); rb.PushCopyHandles(0); } @@ -413,8 +414,9 @@ void IsFinishedReceiving(Service::Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); + bool is_busy = ports[port].is_receiving || ports[port].is_pending_receiving; rb.Push(RESULT_SUCCESS); - rb.Push(ports[port].is_receiving || ports[port].is_pending_receiving); + rb.Push(!is_busy); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); rb.Push(ERROR_INVALID_ENUM_VALUE); @@ -508,7 +510,7 @@ void GetTransferBytes(Service::Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); if (port_select.IsSingle()) { int port = *port_select.begin(); - rb.Push(RESULT_SUCCESS.raw); + rb.Push(RESULT_SUCCESS); rb.Push(ports[port].transfer_bytes); } else { LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); @@ -930,7 +932,6 @@ void SetPackageParameterWithoutContext(Service::Interface* self) { PackageParameterWithoutContext package; rp.PopRaw(package); - rp.Skip(4, false); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); @@ -938,18 +939,11 @@ void SetPackageParameterWithoutContext(Service::Interface* self) { LOG_WARNING(Service_CAM, "(STUBBED) called"); } -template -static void SetPackageParameter() { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), command_id, param_length, 0); - - PackageParameterType package; - rp.PopRaw(package); - rp.Skip(param_length - (sizeof(PackageParameterType) + 3) / 4, false); - +template +static ResultCode SetPackageParameter(const PackageParameterType& package) { const CameraSet camera_select(package.camera_select); const ContextSet context_select(package.context_select); - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (camera_select.IsValid() && context_select.IsValid()) { for (int camera_id : camera_select) { CameraConfig& camera = cameras[camera_id]; @@ -965,31 +959,47 @@ static void SetPackageParameter() { } } } - rb.Push(RESULT_SUCCESS); + return RESULT_SUCCESS; } else { LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", package.camera_select, package.context_select); - rb.Push(ERROR_INVALID_ENUM_VALUE); + return ERROR_INVALID_ENUM_VALUE; } - - LOG_DEBUG(Service_CAM, "called"); } -Resolution PackageParameterWithContext::GetResolution() { +Resolution PackageParameterWithContext::GetResolution() const { return PRESET_RESOLUTION[static_cast(size)]; } void SetPackageParameterWithContext(Service::Interface* self) { - SetPackageParameter(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x34, 5, 0); + + PackageParameterWithContext package; + rp.PopRaw(package); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + ResultCode result = SetPackageParameter(package); + rb.Push(result); + + LOG_DEBUG(Service_CAM, "called"); } void SetPackageParameterWithContextDetail(Service::Interface* self) { - SetPackageParameter(); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x35, 7, 0); + + PackageParameterWithContextDetail package; + rp.PopRaw(package); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + ResultCode result = SetPackageParameter(package); + rb.Push(result); + + LOG_DEBUG(Service_CAM, "called"); } void GetSuitableY2rStandardCoefficient(Service::Interface* self) { - IPC::RequestBuilder rb = - IPC::RequestParser(Kernel::GetCommandBuffer(), 0x36, 0, 0).MakeBuilder(2, 0); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x36, 0, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); rb.Push(0); @@ -1007,8 +1017,8 @@ void PlayShutterSound(Service::Interface* self) { } void DriverInitialize(Service::Interface* self) { - IPC::RequestBuilder rb = - IPC::RequestParser(Kernel::GetCommandBuffer(), 0x39, 0, 0).MakeBuilder(1, 0); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x39, 0, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); for (int camera_id = 0; camera_id < NumCameras; ++camera_id) { CameraConfig& camera = cameras[camera_id]; @@ -1040,8 +1050,8 @@ void DriverInitialize(Service::Interface* self) { } void DriverFinalize(Service::Interface* self) { - IPC::RequestBuilder rb = - IPC::RequestParser(Kernel::GetCommandBuffer(), 0x3A, 0, 0).MakeBuilder(1, 0); + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x3A, 0, 0); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); CancelReceiving(0); CancelReceiving(1); diff --git a/src/core/hle/service/cam/cam.h b/src/core/hle/service/cam/cam.h index 34a9c8479..b6da721d8 100644 --- a/src/core/hle/service/cam/cam.h +++ b/src/core/hle/service/cam/cam.h @@ -184,9 +184,10 @@ struct PackageParameterWithoutContext { s16 auto_white_balance_window_y; s16 auto_white_balance_window_width; s16 auto_white_balance_window_height; + INSERT_PADDING_WORDS(4); }; -static_assert(sizeof(PackageParameterWithoutContext) == 28, +static_assert(sizeof(PackageParameterWithoutContext) == 44, "PackageParameterCameraWithoutContext structure size is wrong"); struct PackageParameterWithContext { @@ -196,11 +197,12 @@ struct PackageParameterWithContext { Effect effect; Size size; INSERT_PADDING_BYTES(3); + INSERT_PADDING_WORDS(3); - Resolution GetResolution(); + Resolution GetResolution() const; }; -static_assert(sizeof(PackageParameterWithContext) == 8, +static_assert(sizeof(PackageParameterWithContext) == 20, "PackageParameterWithContext structure size is wrong"); struct PackageParameterWithContextDetail { @@ -209,13 +211,14 @@ struct PackageParameterWithContextDetail { Flip flip; Effect effect; Resolution resolution; + INSERT_PADDING_WORDS(3); - Resolution GetResolution() { + Resolution GetResolution() const { return resolution; } }; -static_assert(sizeof(PackageParameterWithContextDetail) == 16, +static_assert(sizeof(PackageParameterWithContextDetail) == 28, "PackageParameterWithContextDetail structure size is wrong"); /** -- cgit v1.2.3