Skip to content

Commit 271a494

Browse files
committed
Add hdcp hwc support
1. Add hdcp drm property 2. Add hdcp2.2 support in hwc/libhwcservice 3. Delete libhwcservice hardcode for servie connect 4. Fix type0/type1 switch issue 5. Add libhwcservice for media hdcp api Test-done: Android hdcp daemon test Tracked-On: OAM- Signed-off-by: Jialin <lin.a.jia@intel.com> Signed-off-by: Li, HaihongX <haihongx.li@intel.com>
1 parent d526817 commit 271a494

36 files changed

Lines changed: 4333 additions & 4 deletions

Android.bp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ cc_defaults {
4949
"libsync",
5050
"libui",
5151
"libutils",
52+
"libbinder",
53+
"libhwcservice",
54+
"libutilscallstack",
5255
],
5356

5457
include_dirs: ["vendor/intel/external/drm-hwcomposer"],
@@ -68,6 +71,10 @@ cc_defaults {
6871
"-DHWC2_USE_CPP11",
6972
"-std=c++17",
7073
"-DUSE_IMAPPER4_METADATA_API",
74+
"-Wno-unused-parameter",
75+
"-Wno-unused-private-field",
76+
"-Wno-unused-function",
77+
"-frtti",
7178
],
7279

7380
product_variables: {
@@ -111,6 +118,8 @@ filegroup {
111118
"hwc2_device/HwcDisplayConfigs.cpp",
112119
"hwc2_device/HwcLayer.cpp",
113120
"hwc2_device/hwc2_device.cpp",
121+
"hwc2_device/hwcservice.cpp",
122+
"hwc2_device/callstack.cpp",
114123
],
115124
}
116125

drm/DrmAtomicStateManager.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,84 @@ auto DrmAtomicStateManager::SetColorBrightnessContrast(void) ->int{
675675

676676
return 0;
677677
}
678+
679+
void DrmAtomicStateManager::SetHDCPState(HWCContentProtection state,
680+
HWCContentType content_type) {
681+
uint64_t value = 3;
682+
uint64_t type = 3;
683+
int ret =0;
684+
685+
auto *connector = pipe_->connector->Get();
686+
687+
if (!connector->IsConnected())
688+
return;
689+
690+
desired_protection_support_ = state;
691+
ALOGD("SetHDCPState desired_protection_support_ %d\n",desired_protection_support_);
692+
ALOGD("SetHDCPState current_protection_support_ %d\n",current_protection_support_);
693+
694+
if (desired_protection_support_ == current_protection_support_)
695+
return;
696+
697+
if (pipe_->connector->Get()->GetHdcpTypeProperty().id() <= 0) {
698+
ALOGE("Cannot set HDCP state as Type property is not supported \n");
699+
return;
700+
}
701+
702+
std::tie(ret, type) = pipe_->connector->Get()->GetHdcpTypeProperty().value();
703+
ALOGD("Get Content type %lu \n", type);
704+
ALOGD("Get Content content_type %u \n", content_type);
705+
706+
if ((content_type < 2) && (content_type_ != content_type)) {
707+
content_type_ = content_type;
708+
709+
ALOGD("Set Content type %u \n", content_type);
710+
drmModeConnectorSetProperty(pipe_->device->GetFd(),
711+
pipe_->connector->Get()->GetId(),
712+
pipe_->connector->Get()->GetHdcpTypeProperty().id(),
713+
content_type);
714+
715+
}
716+
717+
if (pipe_->connector->Get()->GetHdcpProperty().id() <= 0) {
718+
ALOGE("Cannot set HDCP state as Connector property is not supported \n");
719+
return;
720+
}
721+
722+
std::tie(ret, value) = pipe_->connector->Get()->GetHdcpProperty().value();
723+
ALOGD("Get Content Protection value %lu \n", value);
724+
725+
if (value < 3) {
726+
switch (value) {
727+
case 0:
728+
//current_protection_support_ = HWCContentProtection::kUnDesired;
729+
current_protection_support_ = hwcomposer::HWCContentProtection::kUnDesired;
730+
ALOGD("%s GetHDCPConnectorProperty value 0", __FUNCTION__);
731+
break;
732+
case 1:
733+
//current_protection_support_ = HWCContentProtection::kDesired;
734+
current_protection_support_ = hwcomposer::HWCContentProtection::kDesired;
735+
ALOGD("%s GetHDCPConnectorProperty value 1", __FUNCTION__);
736+
break;
737+
default:
738+
ALOGE("%s GetHDCPConnectorProperty default", __FUNCTION__);
739+
break;
740+
}
741+
}
742+
743+
if (desired_protection_support_ == HWCContentProtection::kUnSupported) {
744+
desired_protection_support_ = current_protection_support_;
745+
}
746+
747+
current_protection_support_ = desired_protection_support_;
748+
if (current_protection_support_ == kDesired) {
749+
value = 1;
750+
}
751+
752+
ALOGD("Set Content Protection %lu \n", value);
753+
drmModeConnectorSetProperty(pipe_->device->GetFd(),
754+
pipe_->connector->Get()->GetId(),
755+
pipe_->connector->Get()->GetHdcpProperty().id(),
756+
value);
757+
}
678758
} // namespace android

drm/DrmAtomicStateManager.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class DrmAtomicStateManager {
111111
uint32_t brightness_c) ->int;
112112
auto ApplyPendingLUT(struct drm_color_lut *lut, uint64_t lut_size) -> int;
113113

114+
void SetHDCPState(HWCContentProtection state,
115+
HWCContentType content_type);
114116
private:
115117
auto CommitFrame(AtomicCommitArgs &args) -> int;
116118

@@ -156,6 +158,12 @@ class DrmAtomicStateManager {
156158
int frames_staged_{};
157159
int frames_tracked_{};
158160
bool hdr_mdata_set_ = false;
161+
162+
hwcomposer::HWCContentProtection current_protection_support_ =
163+
hwcomposer::HWCContentProtection::kUnSupported;
164+
hwcomposer::HWCContentProtection desired_protection_support_ =
165+
hwcomposer::HWCContentProtection::kUnSupported;
166+
hwcomposer::HWCContentType content_type_ = hwcomposer::kCONTENT_TYPE0;
159167
};
160168

161169
} // namespace android

drm/DrmConnector.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ auto DrmConnector::CreateInstance(DrmDevice &dev, uint32_t connector_id,
7373
auto c = std::unique_ptr<DrmConnector>(
7474
new DrmConnector(std::move(conn), &dev, index));
7575

76+
if (!GetConnectorProperty(dev, *c, "Content Protection", &c->hdcp_id_property_)) {
77+
ALOGE("%s GetHDCPConnectorProperty check failed!", __FUNCTION__);
78+
return {};
79+
}
80+
81+
if (!GetConnectorProperty(dev, *c, "HDCP Content Type", &c->hdcp_type_property_)) {
82+
ALOGE("%s GetHDCPTypeProperty check failed!", __FUNCTION__);
83+
return {};
84+
}
85+
7686
if (!GetConnectorProperty(dev, *c, "DPMS", &c->dpms_property_) ||
7787
!GetConnectorProperty(dev, *c, "CRTC_ID", &c->crtc_id_property_) ||
7888
(dev.IsHdrSupportedDevice() && !GetConnectorProperty(dev, *c, "HDR_OUTPUT_METADATA", &c->hdr_op_metadata_prop_))) {
@@ -601,4 +611,31 @@ void DrmConnector::PrepareHdrMetadata(hdr_md *layer_hdr_metadata,
601611
const DrmProperty &DrmConnector::link_status_property() const {
602612
return link_status_property_;
603613
}
614+
#if 0
615+
void DrmConnector::SetHDCPState(HWCContentProtection state,
616+
HWCContentType content_type) {
617+
desired_protection_support_ = state;
618+
content_type_ = content_type;
619+
if (desired_protection_support_ == current_protection_support_)
620+
return;
621+
622+
if (hdcp_id_prop_ <= 0) {
623+
ETRACE("Cannot set HDCP state as Connector property is not supported \n");
624+
return;
625+
}
626+
627+
if (!(connection_state_ & kConnected)) {
628+
return;
629+
}
630+
631+
current_protection_support_ = desired_protection_support_;
632+
uint32_t value = 0;
633+
if (current_protection_support_ == kDesired) {
634+
value = 1;
635+
}
636+
637+
drmModeConnectorSetProperty(gpu_fd_, connector_, hdcp_id_prop_, value);
638+
ITRACE("Ignored Content type. \n");
639+
}
640+
#endif
604641
} // namespace android

drm/DrmConnector.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "DrmUnique.h"
3232
#include "utils/hdr_metadata_defs.h"
3333
#include "utils/cta_hdr_defs.h"
34+
#include "utils/hwcdefs.h"
3435

3536
namespace android {
3637

@@ -114,6 +115,13 @@ class DrmConnector : public PipelineBindable<DrmConnector> {
114115
return hdr_metadata_;
115116
}
116117

118+
auto &GetHdcpProperty() const {
119+
return hdcp_id_property_;
120+
}
121+
122+
auto &GetHdcpTypeProperty() const {
123+
return hdcp_type_property_;
124+
}
117125

118126
auto IsConnected() const {
119127
return connector_->connection == DRM_MODE_CONNECTED;
@@ -144,7 +152,8 @@ class DrmConnector : public PipelineBindable<DrmConnector> {
144152

145153
void PrepareHdrMetadata(hdr_md *layer_hdr_metadata,
146154
struct hdr_output_metadata *final_hdr_metadata);
147-
155+
void SetHDCPState(hwcomposer::HWCContentProtection state,
156+
hwcomposer::HWCContentType content_type);
148157
const DrmProperty &link_status_property() const;
149158
private:
150159
DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
@@ -167,6 +176,8 @@ class DrmConnector : public PipelineBindable<DrmConnector> {
167176
DrmProperty writeback_fb_id_;
168177
DrmProperty writeback_out_fence_;
169178
DrmProperty link_status_property_;
179+
DrmProperty hdcp_id_property_;
180+
DrmProperty hdcp_type_property_;
170181

171182
uint32_t preferred_mode_id_{};
172183
//hdr_output_metadata property

drm/DrmDevice.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,60 @@ bool DrmDevice::IsHdrSupportedDevice() {
276276

277277
return is_hdr_supported_;
278278
}
279+
#if 0
280+
void DrmDevice::EnableHDCPSessionForDisplay(
281+
uint32_t connector, HWCContentType content_type) {
282+
GetPipe().atomic_state_manager->SetHDCPState(HWCContentProtection::kDesired,
283+
content_type);
284+
#if 0
285+
size_t size = displays_.size();
286+
for (size_t i = 0; i < size; i++) {
287+
if (displays_.at(i)->GetConnectorID() == connector) {
288+
displays_.at(i)->SetHDCPState(HWCContentProtection::kDesired,
289+
content_type);
290+
}
291+
}
292+
#endif
293+
}
294+
295+
void DrmDevice::EnableHDCPSessionForAllDisplays(
296+
HWCContentType content_type) {
297+
GetPipe().atomic_state_manager->SetHDCPState(HWCContentProtection::kDesired,
298+
content_type);
299+
#if 0
300+
size_t size = displays_.size();
301+
for (size_t i = 0; i < size; i++) {
302+
displays_.at(i)->SetHDCPState(HWCContentProtection::kDesired, content_type);
303+
}
304+
#endif
305+
}
279306

307+
void DrmDevice::DisableHDCPSessionForDisplay(uint32_t connector) {
308+
GetPipe().atomic_state_manager->SetHDCPState(HWCContentProtection::kDesired,
309+
content_type);
310+
#if 0
311+
size_t size = displays_.size();
312+
for (size_t i = 0; i < size; i++) {
313+
if (displays_.at(i)->GetConnectorID() == connector) {
314+
displays_.at(i)->SetHDCPState(HWCContentProtection::kUnDesired,
315+
HWCContentType::kInvalid);
316+
}
317+
}
318+
#endif
319+
}
320+
321+
void DrmDevice::DisableHDCPSessionForAllDisplays() {
322+
GetPipe().atomic_state_manager->SetHDCPState(HWCContentProtection::kDesired,
323+
content_type);
324+
#if 0
325+
size_t size = displays_.size();
326+
for (size_t i = 0; i < size; i++) {
327+
displays_.at(i)->SetHDCPState(HWCContentProtection::kUnDesired,
328+
HWCContentType::kInvalid);
329+
}
330+
#endif
331+
}
332+
#endif
280333
auto DrmDevice::IsKMSDev(const char *path) -> bool {
281334
auto fd = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
282335
if (!fd) {

drm/DrmDevice.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "DrmEncoder.h"
2727
#include "DrmFbImporter.h"
2828
#include "utils/UniqueFd.h"
29+
#include "utils/hwcdefs.h"
2930

3031
#define DRM_FORMAT_NV12_Y_TILED_INTEL fourcc_code('9', '9', '9', '6')
3132
namespace android {
@@ -104,7 +105,31 @@ class DrmDevice {
104105
void ResetModeId();
105106
int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
106107
DrmProperty *property) const;
107-
108+
#if 0
109+
// Enables the usage of HDCP for all planes supporting this feature
110+
// on display. Some displays can support latest HDCP specification and also
111+
// have ability to fallback to older specifications i.e. HDCP 2.2 and 1.4
112+
// in case latest speicification cannot be supported for some reason.
113+
// Content type is defined by content_type.
114+
void EnableHDCPSessionForDisplay(uint32_t connector,
115+
hwcomposer::HWCContentType content_type);
116+
117+
// Enables the usage of HDCP for all planes supporting this feature
118+
// on all connected displays. Some displays can support latest HDCP
119+
// specification and also have ability to fallback to older
120+
// specifications i.e. HDCP 2.2 and 1.4 in case latest speicification
121+
// cannot be supported for some reason. Content type is defined by
122+
// content_type.
123+
void EnableHDCPSessionForAllDisplays(hwcomposer::HWCContentType content_type);
124+
125+
// The control disables the usage of HDCP for all planes supporting this
126+
// feature on display.
127+
void DisableHDCPSessionForDisplay(uint32_t connector);
128+
129+
// The control disables the usage of HDCP for all planes supporting this
130+
// feature on all connected displays.
131+
void DisableHDCPSessionForAllDisplays();
132+
#endif
108133
private:
109134
explicit DrmDevice(ResourceManager *res_man);
110135
auto Init(const char *path) -> int;

drm/ResourceManager.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <ctime>
2424
#include <sstream>
25+
#include <binder/IPCThreadState.h>
26+
#include <binder/ProcessState.h>
2527

2628
#include "bufferinfo/BufferInfoGetter.h"
2729
#include "drm/DrmAtomicStateManager.h"
@@ -150,10 +152,22 @@ void ResourceManager::Init() {
150152
});
151153

152154
UpdateFrontendDisplays();
153-
155+
pt_ = std::thread(&ResourceManager::HwcServiceThread, this);
154156
initialized_ = true;
155157
}
156158

159+
void ResourceManager::HwcServiceThread() {
160+
this->hwcService_.Start((DrmHwcTwo*)frontend_interface_);
161+
sp<ProcessState> proc(ProcessState::self());
162+
if (!proc.get())
163+
{
164+
ALOGE("Error: Fail to new ProcessState.");
165+
return ;
166+
}
167+
proc->startThreadPool();
168+
IPCThreadState::self()->joinThreadPool();
169+
}
170+
157171
void ResourceManager::DeInit() {
158172
if (!initialized_) {
159173
ALOGE("Not initialized");

drm/ResourceManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "DrmDisplayPipeline.h"
2424
#include "DrmFbImporter.h"
2525
#include "UEventListener.h"
26-
26+
#include "hwc2_device/hwcservice.h"
2727
namespace android {
2828
class HwcDisplay;
2929
class PipelineToFrontendBindingInterface {
@@ -63,6 +63,7 @@ class ResourceManager {
6363
auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
6464
void UpdateFrontendDisplays();
6565
void DetachAllFrontendDisplays();
66+
void HwcServiceThread();
6667

6768
std::vector<std::unique_ptr<DrmDevice>> drms_;
6869

@@ -78,6 +79,8 @@ class ResourceManager {
7879
PipelineToFrontendBindingInterface *const frontend_interface_;
7980

8081
bool initialized_{};
82+
android::HwcService hwcService_;
83+
std::thread pt_;
8184
};
8285
} // namespace android
8386

0 commit comments

Comments
 (0)