Implement msd_context_execute_command_buffer_with_resources

Remove the implementation of msd_context_execute_command_buffer, since
it isn't used anymore.

Change-Id: I31d2b0ab3144ce96e866d92c64715939c296f4f7
diff --git a/fuchsia/msd_entrypoints.cc b/fuchsia/msd_entrypoints.cc
index 6a1956c..99ccdf2 100644
--- a/fuchsia/msd_entrypoints.cc
+++ b/fuchsia/msd_entrypoints.cc
@@ -126,9 +126,7 @@
 				   msd_semaphore_t** wait_semaphores,
 				   msd_semaphore_t** signal_semaphores)
 {
-	MsdImgConnection* connection = MsdImgContext::cast(ctx)->connection();
-
-	return connection->ExecuteCommandBuffer(cmd_buf, exec_resources, signal_semaphores);
+	return MAGMA_STATUS_UNIMPLEMENTED;
 }
 
 magma_status_t msd_context_execute_command_buffer_with_resources(
@@ -137,7 +135,9 @@
     struct msd_buffer_t** buffers, struct msd_semaphore_t** wait_semaphores,
     struct msd_semaphore_t** signal_semaphores)
 {
-	return MAGMA_STATUS_UNIMPLEMENTED;
+	MsdImgConnection* connection = MsdImgContext::cast(ctx)->connection();
+
+	return connection->ExecuteCommandBuffer(command_buffer, exec_resources, buffers, signal_semaphores);
 }
 
 magma_status_t
diff --git a/fuchsia/msd_img_connection.cc b/fuchsia/msd_img_connection.cc
index 6805358..351ebc9 100644
--- a/fuchsia/msd_img_connection.cc
+++ b/fuchsia/msd_img_connection.cc
@@ -76,29 +76,16 @@
 }
 
 magma_status_t
-MsdImgConnection::ProcessCommandBuffer(msd_buffer_t *cmd_buf,
-				       msd_buffer_t **exec_resources,
+MsdImgConnection::ProcessCommandBuffer(magma_system_command_buffer *command_buffer,
+				       magma_system_exec_resource *exec_resources,
+				       msd_buffer_t **buffers,
 				       msd_semaphore_t **signal_semaphores,
 				       PVRSRV_BRIDGE_PACKAGE *package_out,
 				       volatile FuchsiaImgCommandPayload **payload_out,
 				       std::vector<std::shared_ptr<MsdImgSemaphore>> *semaphores_out)
 {
-	auto abi_command_buffer = MsdImgAbiBuffer::cast(cmd_buf);
-	if (!abi_command_buffer)
-	{
-		return DRET_MSG(MAGMA_STATUS_INVALID_ARGS, "No cmd_buf");
-	}
-	magma::PlatformBuffer *command_buffer = abi_command_buffer->base_ptr()->platform_buffer();
-	void *command_buffer_data;
-	if (!command_buffer->MapCpu(&command_buffer_data))
-	{
-		return DRET_MSG(MAGMA_STATUS_INVALID_ARGS, "Can't map cmd_buf");
-	}
-
-	auto sys_command_buffer = reinterpret_cast<magma_system_command_buffer *>(command_buffer_data);
-	uint32_t num_resources = sys_command_buffer->num_resources;
-	uint32_t num_semaphores = sys_command_buffer->signal_semaphore_count;
-	command_buffer->UnmapCpu();
+	uint32_t num_resources = command_buffer->num_resources;
+	uint32_t num_semaphores = command_buffer->signal_semaphore_count;
 
 	// Array and payload buffers.
 	constexpr uint32_t kExpectedResourceCount = 1;
@@ -112,7 +99,7 @@
 	}
 
 	// Assume the exec resources are in this order.
-	std::shared_ptr<MsdImgBuffer> payload_buffer = MsdImgAbiBuffer::cast(exec_resources[0])->base_ptr();
+	std::shared_ptr<MsdImgBuffer> payload_buffer = MsdImgAbiBuffer::cast(buffers[0])->base_ptr();
 
 	volatile FuchsiaImgCommandPayload *payload;
 	if (payload_buffer->platform_buffer()->size() < sizeof(*payload))
@@ -158,7 +145,7 @@
 
 	if (num_resources > kExpectedResourceCount)
 	{
-		additional_buffer_ = MsdImgAbiBuffer::cast(exec_resources[1])->base_ptr();
+		additional_buffer_ = MsdImgAbiBuffer::cast(buffers[1])->base_ptr();
 	}
 	return MAGMA_STATUS_OK;
 }
@@ -183,15 +170,16 @@
 }
 
 magma_status_t
-MsdImgConnection::ExecuteCommandBuffer(msd_buffer_t *cmd_buf,
-				       msd_buffer_t **exec_resources,
+MsdImgConnection::ExecuteCommandBuffer(magma_system_command_buffer *command_buffer,
+				       magma_system_exec_resource *exec_resources,
+				       msd_buffer_t **buffers,
 				       msd_semaphore_t **signal_semaphores)
 {
 	PVRSRV_BRIDGE_PACKAGE package;
 	volatile FuchsiaImgCommandPayload *payload;
 	std::vector<std::shared_ptr<MsdImgSemaphore>> semaphores;
-	magma_status_t status =
-		ProcessCommandBuffer(cmd_buf, exec_resources, signal_semaphores, &package, &payload, &semaphores);
+	magma_status_t status = ProcessCommandBuffer(command_buffer, exec_resources, buffers, signal_semaphores, &package,
+						     &payload, &semaphores);
 	if (status != MAGMA_STATUS_OK)
 		return DRET(status);
 
diff --git a/fuchsia/msd_img_connection.h b/fuchsia/msd_img_connection.h
index f971fc8..53745bf 100644
--- a/fuchsia/msd_img_connection.h
+++ b/fuchsia/msd_img_connection.h
@@ -45,8 +45,10 @@
 	}
 
 	bool Init();
-	magma_status_t
-	ExecuteCommandBuffer(msd_buffer_t* cmd_buf, msd_buffer_t** exec_resources, msd_semaphore_t** signal_semaphores);
+	magma_status_t ExecuteCommandBuffer(magma_system_command_buffer* command_buffer,
+					    magma_system_exec_resource* exec_resources,
+					    msd_buffer_t** buffers,
+					    msd_semaphore_t** signal_semaphores);
 	bool CopyFromUser(void* dest, const void* src, uint32_t size);
 	bool CopyToUser(void* dest, const void* src, uint32_t size);
 
@@ -88,8 +90,9 @@
 	friend class TestMsdImgConnection;
 	friend class TestOsFunc;
 
-	magma_status_t ProcessCommandBuffer(msd_buffer_t* cmd_buf,
-					    msd_buffer_t** exec_resources,
+	magma_status_t ProcessCommandBuffer(magma_system_command_buffer* command_buffer,
+					    magma_system_exec_resource* exec_resources,
+					    msd_buffer_t** buffers,
 					    msd_semaphore_t** signal_semaphores,
 					    PVRSRV_BRIDGE_PACKAGE* package_out,
 					    volatile FuchsiaImgCommandPayload** payload_out,
diff --git a/test/test_msd_img_connection.cc b/test/test_msd_img_connection.cc
index cb274de..499d541 100644
--- a/test/test_msd_img_connection.cc
+++ b/test/test_msd_img_connection.cc
@@ -27,34 +27,34 @@
 		FakeOwner owner;
 		MsdImgConnection connection(&owner, 1);
 		constexpr uint32_t kBufferSize = 4096;
-		auto cmd_buf = MsdImgAbiBuffer(MsdImgBuffer::Create(kBufferSize, "cmd-buf"));
 		auto payload_buf = MsdImgAbiBuffer(MsdImgBuffer::Create(kBufferSize, "payload"));
 		auto additional_buf = MsdImgAbiBuffer(MsdImgBuffer::Create(kBufferSize, "array"));
 
 		auto normal_semaphore = MsdImgAbiSemaphore(MsdImgSemaphore::Create());
 		auto additional_semaphore = MsdImgAbiSemaphore(MsdImgSemaphore::Create());
 
-		void* mapped_cpu_addr;
-		ASSERT_TRUE(cmd_buf.base_ptr()->platform_buffer()->MapCpu(&mapped_cpu_addr));
-		auto system_buf = reinterpret_cast<magma_system_command_buffer*>(mapped_cpu_addr);
+		magma_system_command_buffer command_buffer;
 
-		msd_buffer_t* exec_resources[3] = { &payload_buf, &additional_buf };
+		msd_buffer_t* buffers[3] = { &payload_buf, &additional_buf };
 		msd_semaphore_t* semaphore_resources[2] = { &normal_semaphore, &additional_semaphore };
+		// Exec resource doesn't really matter.
+		magma_system_exec_resource exec_resource[1] = {};
 
 		PVRSRV_BRIDGE_PACKAGE package;
 		volatile FuchsiaImgCommandPayload* payload;
 		std::vector<std::shared_ptr<MsdImgSemaphore>> semaphores;
 
 		// Need at least 1 resource
-		system_buf->num_resources = 0;
+		command_buffer.num_resources = 0;
 		EXPECT_EQ(MAGMA_STATUS_INVALID_ARGS,
-			  connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources, &package, &payload,
-							  &semaphores));
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 		EXPECT_FALSE(connection.payload_buffer_);
 
-		system_buf->num_resources = 1;
-		system_buf->signal_semaphore_count = 1;
+		command_buffer.num_resources = 1;
+		command_buffer.signal_semaphore_count = 1;
 
+		void* mapped_cpu_addr;
 		ASSERT_TRUE(payload_buf.base_ptr()->platform_buffer()->MapCpu(&mapped_cpu_addr));
 
 		auto payload_buf_data = reinterpret_cast<FuchsiaImgCommandPayload*>(mapped_cpu_addr);
@@ -63,15 +63,15 @@
 		// in_data_size is larger than payload, &semaphores buffer.
 		payload_buf_data->in_data_size = kValidDataSize + 1;
 		EXPECT_EQ(MAGMA_STATUS_INVALID_ARGS,
-			  connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources, &package, &payload,
-							  &semaphores));
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 		EXPECT_FALSE(connection.payload_buffer_);
 
 		// in_data_size is way larger than payload, &semaphores buffer and could cause overflow.
 		payload_buf_data->in_data_size = 0xffffffff;
 		EXPECT_EQ(MAGMA_STATUS_INVALID_ARGS,
-			  connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources, &package, &payload,
-							  &semaphores));
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 		EXPECT_FALSE(connection.payload_buffer_);
 
 		constexpr uint64_t kThreadId = 0x8765432187654321ul;
@@ -81,16 +81,17 @@
 		payload_buf_data->in_data_size = kValidDataSize;
 		payload_buf_data->out_data_size = kValidDataSize;
 
-		system_buf->signal_semaphore_count = 0;
+		command_buffer.signal_semaphore_count = 0;
 
 		// Not enough signal semaphores
 		EXPECT_EQ(MAGMA_STATUS_INVALID_ARGS,
-			  connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources, &package, &payload,
-							  &semaphores));
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 
-		system_buf->signal_semaphore_count = 1;
-		EXPECT_EQ(MAGMA_STATUS_OK, connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources,
-									   &package, &payload, &semaphores));
+		command_buffer.signal_semaphore_count = 1;
+		EXPECT_EQ(MAGMA_STATUS_OK,
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 
 		EXPECT_EQ(kThreadId, connection.current_client_thread_id_);
 		EXPECT_EQ(1u, package.ui32BridgeID);
@@ -113,12 +114,13 @@
 
 		// 2 resources are given, so the last should be used as the
 		// additional buffer.
-		system_buf->num_resources = 2;
+		command_buffer.num_resources = 2;
 		semaphores.resize(0);
 		// Last semaphore should be used as an additional semaphore
-		system_buf->signal_semaphore_count = 2;
-		EXPECT_EQ(MAGMA_STATUS_OK, connection.ProcessCommandBuffer(&cmd_buf, exec_resources, semaphore_resources,
-									   &package, &payload, &semaphores));
+		command_buffer.signal_semaphore_count = 2;
+		EXPECT_EQ(MAGMA_STATUS_OK,
+			  connection.ProcessCommandBuffer(&command_buffer, exec_resource, buffers, semaphore_resources,
+							  &package, &payload, &semaphores));
 		EXPECT_EQ(1u, semaphores.size());
 		EXPECT_EQ(additional_buf.base_ptr(), connection.TakeAdditionalBuffer());
 		EXPECT_EQ(nullptr, connection.TakeAdditionalBuffer());