blob: e282b533151c55b9611e048f34c0243bdcc7817b [file] [log] [blame]
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -08001
Naseer Ahmed72cf9762012-07-21 12:17:13 -07002/*
3 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -08004 * Copyright (C) 2012-14, The Linux Foundation. All rights reserved.
Naseer Ahmed72cf9762012-07-21 12:17:13 -07005 *
6 * Not a Contribution, Apache license notifications and license are
7 * retained for attribution purposes only.
8
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
Saurabh Shah649cda62012-09-16 16:05:58 -070021#define UEVENT_DEBUG 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <hardware_legacy/uevent.h>
23#include <utils/Log.h>
24#include <sys/resource.h>
Naseer Ahmedff4f0252012-10-01 13:03:01 -040025#include <sys/prctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include <string.h>
27#include <stdlib.h>
28#include "hwc_utils.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080029#include "hwc_fbupdate.h"
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080030#include "hwc_mdpcomp.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080031#include "hwc_copybit.h"
32#include "comptype.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070033#include "hdmi.h"
Tatenda Chipeperekwa8f1b9d72014-02-11 16:20:50 -080034#include "hwc_virtual.h"
Saurabh Shah67a38c32013-06-10 16:23:15 -070035#include "mdp_version.h"
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -070036using namespace overlay;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070037namespace qhwc {
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -080038#define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/"
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070039#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
40
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070041/* Parse uevent data for devices which we are interested */
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -070042static int getConnectedDisplay(hwc_context_t* ctx, const char* strUdata)
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070043{
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -070044 int ret = -1;
45 // Switch node for HDMI as PRIMARY/EXTERNAL
46 if(strcasestr("change@/devices/virtual/switch/hdmi", strUdata)) {
47 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
48 ret = HWC_DISPLAY_PRIMARY;
49 } else {
50 ret = HWC_DISPLAY_EXTERNAL;
51 }
52 }
53 return ret;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070054}
55
Veera Sankaran0dadfb32013-07-22 16:07:48 -070056static bool getPanelResetStatus(hwc_context_t* ctx, const char* strUdata, int len)
57{
58 const char* iter_str = strUdata;
59 if (strcasestr("change@/devices/virtual/graphics/fb0", strUdata)) {
60 while(((iter_str - strUdata) <= len) && (*iter_str)) {
61 char* pstr = strstr(iter_str, "PANEL_ALIVE=0");
62 if (pstr != NULL) {
Arpita Banerjeed8965982013-11-08 17:27:33 -080063 ALOGI("%s: got change event in fb0 with PANEL_ALIVE=0",
Veera Sankaran0dadfb32013-07-22 16:07:48 -070064 __FUNCTION__);
65 ctx->mPanelResetStatus = true;
66 return true;
67 }
68 iter_str += strlen(iter_str)+1;
69 }
70 }
71 return false;
72}
73
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070074/* Parse uevent data for action requested for the display */
75static int getConnectedState(const char* strUdata, int len)
76{
77 const char* iter_str = strUdata;
78 while(((iter_str - strUdata) <= len) && (*iter_str)) {
79 char* pstr = strstr(iter_str, "SWITCH_STATE=");
80 if (pstr != NULL) {
81 return (atoi(pstr + strlen("SWITCH_STATE=")));
82 }
83 iter_str += strlen(iter_str)+1;
84 }
85 return -1;
86}
87
Naseer Ahmed72cf9762012-07-21 12:17:13 -070088static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
89{
Veera Sankaran0dadfb32013-07-22 16:07:48 -070090 bool bpanelReset = getPanelResetStatus(ctx, udata, len);
91 if (bpanelReset) {
radhakrishna5d24c252013-12-19 18:03:56 +053092 ctx->proc->invalidate(ctx->proc);
Veera Sankaran0dadfb32013-07-22 16:07:48 -070093 return;
94 }
95
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -070096 int dpy = getConnectedDisplay(ctx, udata);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070097 if(dpy < 0) {
98 ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070099 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700100 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800101
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700102 int switch_state = getConnectedState(udata, len);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800103
Raj kamal59fea562014-04-01 16:52:19 +0530104 ALOGE_IF(UEVENT_DEBUG,"%s: uevent received: %s switch state: %d",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700105 __FUNCTION__,udata, switch_state);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800106
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700107 switch(switch_state) {
108 case EXTERNAL_OFFLINE:
109 {
110 /* Display not connected */
111 if(!ctx->dpyAttr[dpy].connected){
112 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event"
113 "for display: %d", __FUNCTION__, dpy);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800114 break;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800115 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700116
Ramkumar Radhakrishnan5576dc12014-10-08 19:20:25 -0700117 ctx->mDrawLock.lock();
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700118 handle_offline(ctx, dpy);
Ramkumar Radhakrishnan5576dc12014-10-08 19:20:25 -0700119 ctx->mDrawLock.unlock();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700120
121 /* We need to send hotplug to SF only when we are disconnecting
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700122 * HDMI as an external display. */
123 if(dpy == HWC_DISPLAY_EXTERNAL) {
Saurabh Shah15455aa2015-01-28 13:54:48 -0800124 ALOGI("%s: Sending EXTERNAL OFFLINE event", __FUNCTION__);
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700125 ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE);
126 }
Saurabh Shahb85284b2015-01-27 10:54:52 -0800127
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400128 // Report Hotplug via CEC HAL
129 ctx->mQService->onHdmiHotplug((int)ctx->dpyAttr[dpy].connected);
130
Saurabh Shahb85284b2015-01-27 10:54:52 -0800131 //On 8994, 8992 due to hardware limitations, we disable bwc
132 //when HDMI intf is active
133 if((qdutils::MDPVersion::getInstance().is8994() or
134 qdutils::MDPVersion::getInstance().is8092()) and
135 qdutils::MDPVersion::getInstance().supportsBWC()) {
136 Locker::Autolock _l(ctx->mDrawLock);
137 ctx->mBWCEnabled = true;
138 }
139
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700140 break;
141 }
142 case EXTERNAL_ONLINE:
143 {
144 /* Display already connected */
145 if(ctx->dpyAttr[dpy].connected) {
146 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event"
147 "for display: %d", __FUNCTION__, dpy);
148 break;
149 }
Ramkumar Radhakrishnan5576dc12014-10-08 19:20:25 -0700150
Saurabh Shahb85284b2015-01-27 10:54:52 -0800151 //On 8994, 8992 due to hardware limitations, we disable bwc
152 //when HDMI intf is active
153 if((qdutils::MDPVersion::getInstance().is8994() or
154 qdutils::MDPVersion::getInstance().is8092()) and
155 qdutils::MDPVersion::getInstance().supportsBWC()) {
156 Locker::Autolock _l(ctx->mDrawLock);
157 ctx->mBWCEnabled = false;
158 }
159
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700160 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
161 ctx->mDrawLock.lock();
162 handle_online(ctx, dpy);
163 ctx->mDrawLock.unlock();
164
165 ctx->proc->invalidate(ctx->proc);
166 break;
167 } else {
168 ctx->mDrawLock.lock();
169 //Force composition to give up resources like pipes and
170 //close fb. For example if assertive display is going on,
171 //fb2 could be open, thus connecting Layer Mixer#0 to
172 //WriteBack module. If HDMI attempts to open fb1, the driver
173 //will try to attach Layer Mixer#0 to HDMI INT, which will
174 //fail, since Layer Mixer#0 is still connected to WriteBack.
175 //This block will force composition to close fb2 in above
176 //example.
177 ctx->dpyAttr[dpy].isConfiguring = true;
178 ctx->mDrawLock.unlock();
179
180 ctx->proc->invalidate(ctx->proc);
181 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700182 //2 cycles for slower content
183 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
184 * 2 / 1000);
185
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700186 if(isVDConnected(ctx)) {
187 // Do not initiate WFD teardown if WFD architecture is based
188 // on VDS mechanism.
189 // WFD Stack listens to HDMI intent and initiates virtual
190 // display teardown.
191 // ToDo: Currently non-WFD Virtual display clients do not
192 // involve HWC. If there is a change, we need to come up
193 // with mechanism of how to address non-WFD Virtual display
194 // clients + HDMI
195 ctx->mWfdSyncLock.lock();
196 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
197 "%s: Waiting for wfd-teardown to be signalled",
198 __FUNCTION__);
199 ctx->mWfdSyncLock.wait();
200 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
201 "%s: Teardown signalled. Completed waiting in"
202 "uevent thread", __FUNCTION__);
203 ctx->mWfdSyncLock.unlock();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800204 }
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700205 ctx->mHDMIDisplay->configure();
206 ctx->mHDMIDisplay->activateDisplay();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700207
Ramkumar Radhakrishnan5576dc12014-10-08 19:20:25 -0700208 ctx->mDrawLock.lock();
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700209 updateDisplayInfo(ctx, dpy);
210 initCompositionResources(ctx, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700211 ctx->dpyAttr[dpy].isPause = false;
212 ctx->dpyAttr[dpy].connected = true;
213 ctx->dpyAttr[dpy].isConfiguring = true;
Ramkumar Radhakrishnan5576dc12014-10-08 19:20:25 -0700214 ctx->mDrawLock.unlock();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700215
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700216 /* External display is HDMI */
Saurabh Shah15455aa2015-01-28 13:54:48 -0800217 ALOGI("%s: Sending EXTERNAL ONLINE event", __FUNCTION__);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700218 ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_ONLINE);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400219 ctx->mQService->onHdmiHotplug(ctx->dpyAttr[dpy].connected);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700220 break;
221 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700222 default:
223 {
Saurabh Shah15455aa2015-01-28 13:54:48 -0800224 ALOGE("%s: Invalid state to switch:%d", __FUNCTION__, switch_state);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700225 break;
226 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700227 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700228}
229
230static void *uevent_loop(void *param)
231{
232 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400233 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700235 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400236 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700237 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
Sravan Kumar D.V.N04ce9ad2013-10-23 15:57:57 +0530238 if(!uevent_init()) {
239 ALOGE("%s: failed to init uevent ",__FUNCTION__);
240 return NULL;
241 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700242
243 while(1) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530244 len = uevent_next_event(udata, (int)sizeof(udata) - 2);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700245 handle_uevent(ctx, udata, len);
246 }
247
248 return NULL;
249}
250
251void init_uevent_thread(hwc_context_t* ctx)
252{
253 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700254 int ret;
255
256 ALOGI("Initializing UEVENT Thread");
257 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
258 if (ret) {
259 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
260 HWC_UEVENT_THREAD_NAME, strerror(ret));
261 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700262}
263
264}; //namespace