diff options
| author | 2017-02-05 10:22:13 +0200 | |
|---|---|---|
| committer | 2017-02-05 10:22:13 +0200 | |
| commit | a1393dc70c74c3ca414c2360acaa5042bce84c91 (patch) | |
| tree | a0938f34e95cf06bc8ca79eed424db44332d8f48 /src/core/hle/ipc.h | |
| parent | Fix Microprofile in MinGW (#2530) (diff) | |
| parent | fix wwylele's comment and use typename in templates (diff) | |
| download | yuzu-a1393dc70c74c3ca414c2360acaa5042bce84c91.tar.gz yuzu-a1393dc70c74c3ca414c2360acaa5042bce84c91.tar.xz yuzu-a1393dc70c74c3ca414c2360acaa5042bce84c91.zip | |
Merge pull request #2027 from Lectem/ipcrefactor
IPC helper
Diffstat (limited to 'src/core/hle/ipc.h')
| -rw-r--r-- | src/core/hle/ipc.h | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index 4e094faa7..4535b61c0 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h | |||
| @@ -18,12 +18,26 @@ static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of | |||
| 18 | * the thread's TLS to an intermediate buffer in kernel memory, and then copied again to | 18 | * the thread's TLS to an intermediate buffer in kernel memory, and then copied again to |
| 19 | * the service handler process' memory. | 19 | * the service handler process' memory. |
| 20 | * @param offset Optional offset into command buffer | 20 | * @param offset Optional offset into command buffer |
| 21 | * @param offset Optional offset into command buffer (in bytes) | ||
| 21 | * @return Pointer to command buffer | 22 | * @return Pointer to command buffer |
| 22 | */ | 23 | */ |
| 23 | inline u32* GetCommandBuffer(const int offset = 0) { | 24 | inline u32* GetCommandBuffer(const int offset = 0) { |
| 24 | return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + | 25 | return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + |
| 25 | offset); | 26 | offset); |
| 26 | } | 27 | } |
| 28 | |||
| 29 | static const int kStaticBuffersOffset = | ||
| 30 | 0x100; ///< Offset into static buffers, relative to command buffer header | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Returns a pointer to the static buffers area in the current thread's TLS | ||
| 34 | * TODO(Subv): cf. GetCommandBuffer | ||
| 35 | * @param offset Optional offset into static buffers area (in bytes) | ||
| 36 | * @return Pointer to static buffers area | ||
| 37 | */ | ||
| 38 | inline u32* GetStaticBuffers(const int offset = 0) { | ||
| 39 | return GetCommandBuffer(kStaticBuffersOffset + offset); | ||
| 40 | } | ||
| 27 | } | 41 | } |
| 28 | 42 | ||
| 29 | namespace IPC { | 43 | namespace IPC { |
| @@ -40,10 +54,17 @@ enum DescriptorType : u32 { | |||
| 40 | CallingPid = 0x20, | 54 | CallingPid = 0x20, |
| 41 | }; | 55 | }; |
| 42 | 56 | ||
| 57 | union Header { | ||
| 58 | u32 raw; | ||
| 59 | BitField<0, 6, u32> translate_params_size; | ||
| 60 | BitField<6, 6, u32> normal_params_size; | ||
| 61 | BitField<16, 16, u32> command_id; | ||
| 62 | }; | ||
| 63 | |||
| 43 | /** | 64 | /** |
| 44 | * @brief Creates a command header to be used for IPC | 65 | * @brief Creates a command header to be used for IPC |
| 45 | * @param command_id ID of the command to create a header for. | 66 | * @param command_id ID of the command to create a header for. |
| 46 | * @param normal_params Size of the normal parameters in words. Up to 63. | 67 | * @param normal_params_size Size of the normal parameters in words. Up to 63. |
| 47 | * @param translate_params_size Size of the translate parameters in words. Up to 63. | 68 | * @param translate_params_size Size of the translate parameters in words. Up to 63. |
| 48 | * @return The created IPC header. | 69 | * @return The created IPC header. |
| 49 | * | 70 | * |
| @@ -51,24 +72,16 @@ enum DescriptorType : u32 { | |||
| 51 | * through modifications and checks by the kernel. | 72 | * through modifications and checks by the kernel. |
| 52 | * The translate parameters are described by headers generated with the IPC::*Desc functions. | 73 | * The translate parameters are described by headers generated with the IPC::*Desc functions. |
| 53 | * | 74 | * |
| 54 | * @note While #normal_params is equivalent to the number of normal parameters, | 75 | * @note While #normal_params_size is equivalent to the number of normal parameters, |
| 55 | * #translate_params_size includes the size occupied by the translate parameters headers. | 76 | * #translate_params_size includes the size occupied by the translate parameters headers. |
| 56 | */ | 77 | */ |
| 57 | constexpr u32 MakeHeader(u16 command_id, unsigned int normal_params, | 78 | inline u32 MakeHeader(u16 command_id, unsigned int normal_params_size, |
| 58 | unsigned int translate_params_size) { | 79 | unsigned int translate_params_size) { |
| 59 | return (u32(command_id) << 16) | ((u32(normal_params) & 0x3F) << 6) | | 80 | Header header; |
| 60 | (u32(translate_params_size) & 0x3F); | 81 | header.command_id.Assign(command_id); |
| 61 | } | 82 | header.normal_params_size.Assign(normal_params_size); |
| 62 | 83 | header.translate_params_size.Assign(translate_params_size); | |
| 63 | union Header { | 84 | return header.raw; |
| 64 | u32 raw; | ||
| 65 | BitField<0, 6, u32> translate_params_size; | ||
| 66 | BitField<6, 6, u32> normal_params; | ||
| 67 | BitField<16, 16, u32> command_id; | ||
| 68 | }; | ||
| 69 | |||
| 70 | inline Header ParseHeader(u32 header) { | ||
| 71 | return {header}; | ||
| 72 | } | 85 | } |
| 73 | 86 | ||
| 74 | constexpr u32 MoveHandleDesc(u32 num_handles = 1) { | 87 | constexpr u32 MoveHandleDesc(u32 num_handles = 1) { |
| @@ -83,7 +96,7 @@ constexpr u32 CallingPidDesc() { | |||
| 83 | return CallingPid; | 96 | return CallingPid; |
| 84 | } | 97 | } |
| 85 | 98 | ||
| 86 | constexpr bool isHandleDescriptor(u32 descriptor) { | 99 | constexpr bool IsHandleDescriptor(u32 descriptor) { |
| 87 | return (descriptor & 0xF) == 0x0; | 100 | return (descriptor & 0xF) == 0x0; |
| 88 | } | 101 | } |
| 89 | 102 | ||
| @@ -91,18 +104,19 @@ constexpr u32 HandleNumberFromDesc(u32 handle_descriptor) { | |||
| 91 | return (handle_descriptor >> 26) + 1; | 104 | return (handle_descriptor >> 26) + 1; |
| 92 | } | 105 | } |
| 93 | 106 | ||
| 94 | constexpr u32 StaticBufferDesc(u32 size, u8 buffer_id) { | ||
| 95 | return StaticBuffer | (size << 14) | ((buffer_id & 0xF) << 10); | ||
| 96 | } | ||
| 97 | |||
| 98 | union StaticBufferDescInfo { | 107 | union StaticBufferDescInfo { |
| 99 | u32 raw; | 108 | u32 raw; |
| 109 | BitField<0, 4, u32> descriptor_type; | ||
| 100 | BitField<10, 4, u32> buffer_id; | 110 | BitField<10, 4, u32> buffer_id; |
| 101 | BitField<14, 18, u32> size; | 111 | BitField<14, 18, u32> size; |
| 102 | }; | 112 | }; |
| 103 | 113 | ||
| 104 | inline StaticBufferDescInfo ParseStaticBufferDesc(const u32 desc) { | 114 | inline u32 StaticBufferDesc(u32 size, u8 buffer_id) { |
| 105 | return {desc}; | 115 | StaticBufferDescInfo info; |
| 116 | info.descriptor_type.Assign(StaticBuffer); | ||
| 117 | info.buffer_id.Assign(buffer_id); | ||
| 118 | info.size.Assign(size); | ||
| 119 | return info.raw; | ||
| 106 | } | 120 | } |
| 107 | 121 | ||
| 108 | /** | 122 | /** |
| @@ -122,29 +136,30 @@ inline u32 PXIBufferDesc(u32 size, unsigned buffer_id, bool is_read_only) { | |||
| 122 | return type | (size << 8) | ((buffer_id & 0xF) << 4); | 136 | return type | (size << 8) | ((buffer_id & 0xF) << 4); |
| 123 | } | 137 | } |
| 124 | 138 | ||
| 125 | enum MappedBufferPermissions { | 139 | enum MappedBufferPermissions : u32 { |
| 126 | R = 1, | 140 | R = 1, |
| 127 | W = 2, | 141 | W = 2, |
| 128 | RW = R | W, | 142 | RW = R | W, |
| 129 | }; | 143 | }; |
| 130 | 144 | ||
| 131 | constexpr u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { | ||
| 132 | return MappedBuffer | (size << 4) | (u32(perms) << 1); | ||
| 133 | } | ||
| 134 | |||
| 135 | union MappedBufferDescInfo { | 145 | union MappedBufferDescInfo { |
| 136 | u32 raw; | 146 | u32 raw; |
| 137 | BitField<4, 28, u32> size; | 147 | BitField<0, 4, u32> flags; |
| 138 | BitField<1, 2, MappedBufferPermissions> perms; | 148 | BitField<1, 2, MappedBufferPermissions> perms; |
| 149 | BitField<4, 28, u32> size; | ||
| 139 | }; | 150 | }; |
| 140 | 151 | ||
| 141 | inline MappedBufferDescInfo ParseMappedBufferDesc(const u32 desc) { | 152 | inline u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { |
| 142 | return {desc}; | 153 | MappedBufferDescInfo info; |
| 154 | info.flags.Assign(MappedBuffer); | ||
| 155 | info.perms.Assign(perms); | ||
| 156 | info.size.Assign(size); | ||
| 157 | return info.raw; | ||
| 143 | } | 158 | } |
| 144 | 159 | ||
| 145 | inline DescriptorType GetDescriptorType(u32 descriptor) { | 160 | inline DescriptorType GetDescriptorType(u32 descriptor) { |
| 146 | // Note: Those checks must be done in this order | 161 | // Note: Those checks must be done in this order |
| 147 | if (isHandleDescriptor(descriptor)) | 162 | if (IsHandleDescriptor(descriptor)) |
| 148 | return (DescriptorType)(descriptor & 0x30); | 163 | return (DescriptorType)(descriptor & 0x30); |
| 149 | 164 | ||
| 150 | // handle the fact that the following descriptors can have rights | 165 | // handle the fact that the following descriptors can have rights |