Snap for 13290005 from e528354222 to 25Q4-release

Change-Id: I8c97e4c8d20f9880a701d0f68e2dc4be68a8d59e
This commit is contained in:
Android Build Coastguard Worker 2025-03-29 14:15:56 -07:00
commit 63b4210eed
12 changed files with 335 additions and 7 deletions

View file

@ -82,6 +82,10 @@ msm_cflags = [
]
arcvm_cflags = ["-DVIRTIO_GPU_NEXT"]
mediatek_cflags = [
"-DDRV_MEDIATEK",
]
cc_defaults {
name: "minigbm_defaults",
@ -100,6 +104,9 @@ cc_defaults {
"meson": meson_cflags,
"msm": msm_cflags,
"arcvm": arcvm_cflags,
"mt8186": mediatek_cflags + ["-DMTK_MT8186"],
"mt8188": mediatek_cflags + ["-DMTK_MT8188G"],
"mt8196": mediatek_cflags + ["-DMTK_MT8196"],
default: [],
}),
@ -323,3 +330,10 @@ cc_library_shared {
defaults: ["minigbm_cros_gralloc0_defaults"],
shared_libs: ["libminigbm_gralloc_arcvm"],
}
// mediatek
cc_library_shared {
name: "libminigbm_gralloc_mediatek",
defaults: ["minigbm_cros_gralloc_library_defaults"],
cflags: mediatek_cflags,
}

View file

@ -1,3 +1,15 @@
adelva@google.com
natsu@google.com
prahladk@google.com
include platform/system/core:main:/janitors/OWNERS
# Intel
per-file external/i915_drm.h = msturner@google.com, ryanneph@google.com
per-file external/xe_drm.h = msturner@google.com, ryanneph@google.com
per-file intel_defines.h = msturner@google.com, ryanneph@google.com
per-file i915.c = msturner@google.com, ryanneph@google.com
per-file xe.c = msturner@google.com, ryanneph@google.com
# Mediatek
per-file external/mediatek_drm.h = dbehr@google.com, zzyiwei@google.com
per-file mediatek.c = dbehr@google.com, zzyiwei@google.com

View file

@ -0,0 +1,69 @@
#ifndef CROS_GRALLOC_ARM_H
#define CROS_GRALLOC_ARM_H
#include "../drv.h"
#include "aidl/android/hardware/graphics/common/ExtendableType.h"
using aidl::android::hardware::graphics::common::ExtendableType;
/* from AIDL interface */
typedef enum {
INVALID = 0,
PLANE_FDS = 1,
FORMAT_DATA_TYPE = 2,
} ArmMetadataType;
typedef enum {
UNORM = 0,
SNORM = 1,
UINT = 2,
SINT = 3,
SFLOAT = 4,
UNKNOWN = 0xFF,
} ArmDataType;
typedef enum {
AFBC = 0,
AFRC = 1,
} ArmCompression;
#define GRALLOC_ARM_COMPRESSION_TYPE_NAME "arm.graphics.Compression"
const static ExtendableType Compression_AFBC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
static_cast<int64_t>(ArmCompression::AFBC) };
const static ExtendableType Compression_AFRC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
static_cast<int64_t>(ArmCompression::AFRC) };
#define GRALLOC_ARM_METADATA_TYPE_NAME "arm.graphics.ArmMetadataType"
#define GRALLOC_ARM_FORMAT_DATA_TYPE_NAME "arm.graphics.DataType"
static ArmDataType DataTypeFromDrmPixelFormat(uint32_t pf)
{
switch (pf) {
case DRM_FORMAT_R8:
case DRM_FORMAT_GR88:
case DRM_FORMAT_RGB565:
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
case DRM_FORMAT_XRGB2101010:
case DRM_FORMAT_XBGR2101010:
case DRM_FORMAT_ARGB2101010:
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV21:
case DRM_FORMAT_YUYV:
case DRM_FORMAT_YVU420:
case DRM_FORMAT_YVU420_ANDROID:
case DRM_FORMAT_P010:
return ArmDataType::UNORM;
case DRM_FORMAT_ABGR16161616F:
return ArmDataType::SFLOAT;
default:
return ArmDataType::UNKNOWN;
}
}
#endif // CROS_GRALLOC_ARM_H

View file

@ -142,6 +142,14 @@ uint32_t cros_gralloc_buffer::get_plane_size(uint32_t plane) const
return hnd_->sizes[plane];
}
int64_t cros_gralloc_buffer::get_plane_fd(uint32_t plane) const
{
if (plane >= hnd_->num_planes) {
return -1;
}
return hnd_->fds[plane];
}
int32_t cros_gralloc_buffer::get_android_format() const
{
return hnd_->droid_format;

View file

@ -38,6 +38,7 @@ class cros_gralloc_buffer
uint32_t get_plane_offset(uint32_t plane) const;
uint32_t get_plane_stride(uint32_t plane) const;
uint32_t get_plane_size(uint32_t plane) const;
int64_t get_plane_fd(uint32_t plane) const;
int32_t get_android_format() const;
int64_t get_android_usage() const;

View file

@ -126,6 +126,14 @@ cc_binary {
},
}
cc_binary {
name: "android.hardware.graphics.allocator@4.0-service.minigbm_mediatek",
defaults: ["minigbm_gralloc4_allocator_defaults"],
shared_libs: ["libminigbm_gralloc_mediatek"],
vintf_fragment_modules: ["android.hardware.graphics.allocator@4.0.xml"],
init_rc: ["android.hardware.graphics.allocator@4.0-service.minigbm_mediatek.rc"],
}
vintf_fragment {
name: "android.hardware.graphics.mapper@4.0.xml",
src: "android.hardware.graphics.mapper@4.0.xml",
@ -172,3 +180,11 @@ cc_library_shared {
},
},
}
cc_library_shared {
name: "android.hardware.graphics.mapper@4.0-impl.minigbm_mediatek",
defaults: ["minigbm_gralloc4_common_defaults"],
shared_libs: ["libminigbm_gralloc_mediatek"],
vintf_fragment_modules: ["android.hardware.graphics.mapper@4.0.xml"],
srcs: [":minigbm_gralloc4_mapper_files"],
}

View file

@ -16,6 +16,7 @@
#include <cutils/native_handle.h>
#include <gralloctypes/Gralloc4.h>
#include "cros_gralloc/cros_gralloc_arm.h"
#include "cros_gralloc/cros_gralloc_helpers.h"
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
@ -34,6 +35,11 @@ using android::hardware::graphics::common::V1_2::PixelFormat;
using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper;
const static IMapper::MetadataType kArmMetadataTypePlaneFds{
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::PLANE_FDS)};
const static IMapper::MetadataType kArmMetadataTypeFormatDataType{
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::FORMAT_DATA_TYPE)};
Return<void> CrosGralloc4Mapper::createDescriptor(const BufferDescriptorInfo& description,
createDescriptor_cb hidlCb) {
hidl_vec<uint8_t> descriptor;
@ -480,8 +486,18 @@ Return<void> CrosGralloc4Mapper::get(const cros_gralloc_buffer* crosBuffer,
crosBuffer->get_android_usage() & BufferUsage::PROTECTED ? 1 : 0;
status = android::gralloc4::encodeProtectedContent(hasProtectedContent, &encodedMetadata);
} else if (metadataType == android::gralloc4::MetadataType_Compression) {
status = android::gralloc4::encodeCompression(android::gralloc4::Compression_None,
&encodedMetadata);
ExtendableType compression = android::gralloc4::Compression_None;
uint64_t modifier = crosBuffer->get_format_modifier();
if (fourcc_mod_is_vendor(modifier, ARM)) {
if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFBC) {
compression = Compression_AFBC;
} else if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFRC) {
compression = Compression_AFRC;
}
}
status = android::gralloc4::encodeCompression(compression, &encodedMetadata);
} else if (metadataType == android::gralloc4::MetadataType_Interlaced) {
status = android::gralloc4::encodeInterlaced(android::gralloc4::Interlaced_None,
&encodedMetadata);
@ -557,6 +573,20 @@ Return<void> CrosGralloc4Mapper::get(const cros_gralloc_buffer* crosBuffer,
}
} else if (metadataType == android::gralloc4::MetadataType_Smpte2094_40) {
status = android::gralloc4::encodeSmpte2094_40(std::nullopt, &encodedMetadata);
} else if (metadataType == kArmMetadataTypePlaneFds) {
uint32_t num_planes = crosBuffer->get_num_planes();
int64_t plane_fds[5];
plane_fds[0] = num_planes;
for (auto plane = 0; plane < num_planes; plane++) {
plane_fds[1 + plane] = crosBuffer->get_plane_fd(plane);
}
encodedMetadata.resize(sizeof(uint64_t) * (1 + num_planes));
memcpy(encodedMetadata.data(), plane_fds, encodedMetadata.size());
} else if (metadataType == kArmMetadataTypeFormatDataType) {
uint32_t pf = crosBuffer->get_format();
int64_t fdt = static_cast<int64_t>(DataTypeFromDrmPixelFormat(pf));
encodedMetadata.resize(sizeof(fdt));
memcpy(encodedMetadata.data(), &fdt, encodedMetadata.size());
} else {
hidlCb(Error::UNSUPPORTED, encodedMetadata);
return Void();
@ -940,6 +970,18 @@ Return<void> CrosGralloc4Mapper::listSupportedMetadataTypes(listSupportedMetadat
/*isGettable=*/true,
/*isSettable=*/false,
},
{
kArmMetadataTypePlaneFds,
"Vector of file descriptors of each plane",
/*isGettable=*/true,
/*isSettable=*/false,
},
{
kArmMetadataTypeFormatDataType,
"Format data type",
/*isGettable=*/true,
/*isSettable=*/false,
},
});
hidlCb(Error::NONE, supported);

View file

@ -0,0 +1,24 @@
#
# Copyright 2025 The Android Open Source Project
#
# 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.
#
service vendor.graphics.allocator-4-0 /vendor/bin/hw/android.hardware.graphics.allocator@4.0-service.minigbm_mediatek
interface android.hardware.graphics.allocator@4.0::IAllocator default
class hal animation
user system
group graphics drmrpc
capabilities SYS_NICE
onrestart restart surfaceflinger
task_profiles ServiceCapacityLow

View file

@ -17,6 +17,7 @@
#include <memory>
#include "cros_gralloc/cros_gralloc_arm.h"
#include "cros_gralloc/cros_gralloc_driver.h"
#include "cros_gralloc/cros_gralloc_handle.h"
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
@ -49,10 +50,19 @@ static_assert(CROS_GRALLOC_BUFFER_METADATA_MAX_NAME_SIZE >=
constexpr const char* STANDARD_METADATA_NAME =
"android.hardware.graphics.common.StandardMetadataType";
constexpr const AIMapper_MetadataType kArmMetadataTypePlaneFds{
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::PLANE_FDS)};
constexpr const AIMapper_MetadataType kArmMetadataTypeFormatDataType{
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::FORMAT_DATA_TYPE)};
static bool isStandardMetadata(AIMapper_MetadataType metadataType) {
return strcmp(STANDARD_METADATA_NAME, metadataType.name) == 0;
}
static bool isArmMetadata(AIMapper_MetadataType metadataType) {
return strcmp(GRALLOC_ARM_METADATA_TYPE_NAME, metadataType.name) == 0;
}
class CrosGrallocMapperV5 final : public vendor::mapper::IMapperV5Impl {
private:
std::shared_ptr<cros_gralloc_driver> mDriver = cros_gralloc_driver::get_instance();
@ -119,6 +129,9 @@ class CrosGrallocMapperV5 final : public vendor::mapper::IMapperV5Impl {
void dumpBuffer(
const cros_gralloc_buffer* crosBuffer,
std::function<void(AIMapper_MetadataType, const std::vector<uint8_t>&)> callback);
int32_t getArmMetadata(buffer_handle_t _Nonnull buffer, int64_t armMetadataType,
void* _Nonnull outData, size_t outDataSize);
};
AIMapper_Error CrosGrallocMapperV5::importBuffer(
@ -268,14 +281,67 @@ AIMapper_Error CrosGrallocMapperV5::rereadLockedBuffer(buffer_handle_t _Nonnull
int32_t CrosGrallocMapperV5::getMetadata(buffer_handle_t _Nonnull buffer,
AIMapper_MetadataType metadataType, void* _Nonnull outData,
size_t outDataSize) {
// We don't have any vendor-specific metadata, so divert to getStandardMetadata after validating
// that this is a standard metadata request
if (isStandardMetadata(metadataType)) {
return getStandardMetadata(buffer, metadataType.value, outData, outDataSize);
}
if (isArmMetadata(metadataType)) {
return getArmMetadata(buffer, metadataType.value, outData, outDataSize);
}
return -AIMAPPER_ERROR_UNSUPPORTED;
}
int32_t CrosGrallocMapperV5::getArmMetadata(buffer_handle_t _Nonnull buffer,
int64_t armMetadataType, void* _Nonnull outData,
size_t outDataSize) {
cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(buffer);
if (!crosHandle) {
ALOGE("Failed to get. Invalid handle.");
return -AIMAPPER_ERROR_BAD_BUFFER;
}
int32_t retValue = -AIMAPPER_ERROR_UNSUPPORTED;
switch (armMetadataType) {
case ArmMetadataType::PLANE_FDS: {
mDriver->with_buffer(crosHandle, [&](cros_gralloc_buffer* crosBuffer) {
uint32_t num_planes = crosBuffer->get_num_planes();
if (outDataSize < sizeof(int64_t) * (1 + num_planes)) {
retValue = sizeof(int64_t) * (1 + num_planes);
} else {
int64_t plane_fds[DRV_MAX_PLANES + 1];
plane_fds[0] = num_planes;
for (auto plane = 0; plane < num_planes; plane++) {
plane_fds[1 + plane] = crosBuffer->get_plane_fd(plane);
}
memcpy(outData, plane_fds, sizeof(uint64_t) * (1 + num_planes));
retValue = -AIMAPPER_ERROR_NONE;
}
});
break;
}
case ArmMetadataType::FORMAT_DATA_TYPE: {
mDriver->with_buffer(crosHandle, [&](cros_gralloc_buffer* crosBuffer) {
uint32_t pf = crosBuffer->get_format();
int64_t fdt = static_cast<int64_t>(DataTypeFromDrmPixelFormat(pf));
if (outDataSize < sizeof(fdt)) {
retValue = sizeof(fdt);
} else {
memcpy(outData, &fdt, sizeof(fdt));
retValue = -AIMAPPER_ERROR_NONE;
}
});
break;
}
default:
return -AIMAPPER_ERROR_UNSUPPORTED;
}
return retValue;
}
int32_t CrosGrallocMapperV5::getStandardMetadata(buffer_handle_t _Nonnull bufferHandle,
int64_t standardType, void* _Nonnull outData,
size_t outDataSize) {
@ -355,7 +421,18 @@ int32_t CrosGrallocMapperV5::getStandardMetadata(const cros_gralloc_buffer* cros
return provide(hasProtectedContent);
}
if constexpr (metadataType == StandardMetadataType::COMPRESSION) {
return provide(android::gralloc4::Compression_None);
ExtendableType compression = android::gralloc4::Compression_None;
uint64_t modifier = crosBuffer->get_format_modifier();
if (fourcc_mod_is_vendor(modifier, ARM)) {
if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFBC) {
compression = Compression_AFBC;
} else if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFRC) {
compression = Compression_AFRC;
}
}
return provide(compression);
}
if constexpr (metadataType == StandardMetadataType::INTERLACED) {
return provide(android::gralloc4::Interlaced_None);
@ -528,7 +605,7 @@ constexpr AIMapper_MetadataTypeDescription describeStandard(StandardMetadataType
AIMapper_Error CrosGrallocMapperV5::listSupportedMetadataTypes(
const AIMapper_MetadataTypeDescription* _Nullable* _Nonnull outDescriptionList,
size_t* _Nonnull outNumberOfDescriptions) {
static constexpr std::array<AIMapper_MetadataTypeDescription, 22> sSupportedMetadaTypes{
static constexpr std::array<AIMapper_MetadataTypeDescription, 24> sSupportedMetadaTypes{
describeStandard(StandardMetadataType::BUFFER_ID, true, false),
describeStandard(StandardMetadataType::NAME, true, false),
describeStandard(StandardMetadataType::WIDTH, true, false),
@ -551,6 +628,8 @@ AIMapper_Error CrosGrallocMapperV5::listSupportedMetadataTypes(
describeStandard(StandardMetadataType::SMPTE2086, true, true),
describeStandard(StandardMetadataType::CTA861_3, true, true),
describeStandard(StandardMetadataType::STRIDE, true, false),
{kArmMetadataTypePlaneFds, "Vector of file descriptors of each plane", true, false, {0}},
{kArmMetadataTypeFormatDataType, "Format data type", true, false, {0}},
};
*outDescriptionList = sSupportedMetadaTypes.data();
*outNumberOfDescriptions = sSupportedMetadaTypes.size();

62
external/mediatek_drm.h vendored Normal file
View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2015 MediaTek Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef _UAPI_MEDIATEK_DRM_H
#define _UAPI_MEDIATEK_DRM_H
#include "drm.h"
/**
* User-desired buffer creation information structure.
*
* @size: user-desired memory allocation size.
* - this size value would be page-aligned internally.
* @flags: user request for setting memory type or cache attributes.
* @handle: returned a handle to created gem object.
* - this handle will be set by gem module of kernel side.
*/
struct drm_mtk_gem_create {
uint64_t size;
uint32_t flags;
uint32_t handle;
};
/**
* A structure for getting buffer offset.
*
* @handle: a pointer to gem object created.
* @pad: just padding to be 64-bit aligned.
* @offset: relatived offset value of the memory region allocated.
* - this value should be set by user.
*/
struct drm_mtk_gem_map_off {
uint32_t handle;
uint32_t pad;
uint64_t offset;
};
#define DRM_MTK_GEM_CREATE 0x00
#define DRM_MTK_GEM_MAP_OFFSET 0x01
#define DRM_MTK_GEM_CREATE_FLAG_RESTRICTED (1 << 0)
#define DRM_MTK_GEM_CREATE_FLAG_ALLOC_SINGLE_PAGES (1 << 1)
#define DRM_IOCTL_MTK_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + \
DRM_MTK_GEM_CREATE, struct drm_mtk_gem_create)
#define DRM_IOCTL_MTK_GEM_MAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + \
DRM_MTK_GEM_MAP_OFFSET, struct drm_mtk_gem_map_off)
#endif /* _UAPI_MEDIATEK_DRM_H */

View file

@ -54,6 +54,7 @@ const uint16_t adlp_ids[] = {
0x46A0, 0x46A1, 0x46A2, 0x46A3, 0x46A6, 0x46A8, 0x46AA,
0x462A, 0x4626, 0x4628, 0x46B0, 0x46B1, 0x46B2, 0x46B3,
0x46C0, 0x46C1, 0x46C2, 0x46C3, 0x46D0, 0x46D1, 0x46D2,
0x46D3, 0x46D4,
};
const uint16_t rplp_ids[] = { 0xA720, 0xA721, 0xA7A0, 0xA7A1, 0xA7A8, 0xA7A9, };

View file

@ -20,7 +20,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include <xf86drm.h>
#include <mediatek_drm.h>
#include "external/mediatek_drm.h"
// clang-format on
#include "drv_helpers.h"