blob: c26a6ce6942d618bfc22ab62623d59814703ef2f [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 Chipeperekwa12f41c92014-09-17 12:55:01 -070033#include "hdmi.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070034#include "virtual.h"
Tatenda Chipeperekwa0d706842014-02-11 16:20:50 -080035#include "hwc_virtual.h"
Saurabh Shah67a38c32013-06-10 16:23:15 -070036#include "mdp_version.h"
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -070037using namespace overlay;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070038namespace qhwc {
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -080039#define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/"
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070040#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
41
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070042/* Parse uevent data for devices which we are interested */
43static int getConnectedDisplay(const char* strUdata)
44{
45 if(strcasestr("change@/devices/virtual/switch/hdmi", strUdata))
46 return HWC_DISPLAY_EXTERNAL;
47 if(strcasestr("change@/devices/virtual/switch/wfd", strUdata))
48 return HWC_DISPLAY_VIRTUAL;
49 return -1;
50}
51
Veera Sankaran0dadfb32013-07-22 16:07:48 -070052static bool getPanelResetStatus(hwc_context_t* ctx, const char* strUdata, int len)
53{
54 const char* iter_str = strUdata;
55 if (strcasestr("change@/devices/virtual/graphics/fb0", strUdata)) {
56 while(((iter_str - strUdata) <= len) && (*iter_str)) {
57 char* pstr = strstr(iter_str, "PANEL_ALIVE=0");
58 if (pstr != NULL) {
Arpita Banerjeed8965982013-11-08 17:27:33 -080059 ALOGI("%s: got change event in fb0 with PANEL_ALIVE=0",
Veera Sankaran0dadfb32013-07-22 16:07:48 -070060 __FUNCTION__);
61 ctx->mPanelResetStatus = true;
62 return true;
63 }
64 iter_str += strlen(iter_str)+1;
65 }
66 }
67 return false;
68}
69
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070070/* Parse uevent data for action requested for the display */
71static int getConnectedState(const char* strUdata, int len)
72{
73 const char* iter_str = strUdata;
74 while(((iter_str - strUdata) <= len) && (*iter_str)) {
75 char* pstr = strstr(iter_str, "SWITCH_STATE=");
76 if (pstr != NULL) {
77 return (atoi(pstr + strlen("SWITCH_STATE=")));
78 }
79 iter_str += strlen(iter_str)+1;
80 }
81 return -1;
82}
83
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080084void handle_pause(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwa0d706842014-02-11 16:20:50 -080085 if(ctx->mHWCVirtual) {
86 ctx->mHWCVirtual->pause(ctx, dpy);
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080087 }
88 return;
89}
90
91void handle_resume(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwa0d706842014-02-11 16:20:50 -080092 if(ctx->mHWCVirtual) {
93 ctx->mHWCVirtual->resume(ctx, dpy);
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080094 }
95 return;
96}
97
Naseer Ahmed72cf9762012-07-21 12:17:13 -070098static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
99{
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700100 bool bpanelReset = getPanelResetStatus(ctx, udata, len);
101 if (bpanelReset) {
radhakrishna5d24c252013-12-19 18:03:56 +0530102 ctx->proc->invalidate(ctx->proc);
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700103 return;
104 }
105
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700106 int dpy = getConnectedDisplay(udata);
107 if(dpy < 0) {
108 ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700109 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700110 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800111
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700112 int switch_state = getConnectedState(udata, len);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800113
Raj kamal9af062e2014-04-01 16:52:19 +0530114 ALOGE_IF(UEVENT_DEBUG,"%s: uevent received: %s switch state: %d",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700115 __FUNCTION__,udata, switch_state);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800116
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700117 switch(switch_state) {
118 case EXTERNAL_OFFLINE:
119 {
120 /* Display not connected */
121 if(!ctx->dpyAttr[dpy].connected){
122 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event"
123 "for display: %d", __FUNCTION__, dpy);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800124 break;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800125 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700126
Ramkumar Radhakrishnan5c3e6b92014-10-08 19:20:25 -0700127 ctx->mDrawLock.lock();
Tatenda Chipeperekwaaa832122014-09-16 18:09:18 -0700128 destroyCompositionResources(ctx, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700129 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwa12f41c92014-09-17 12:55:01 -0700130 ctx->mHDMIDisplay->teardown();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700131 } else {
132 ctx->mVirtualDisplay->teardown();
133 }
Tatenda Chipeperekwaaa832122014-09-16 18:09:18 -0700134 resetDisplayInfo(ctx, dpy);
Ramkumar Radhakrishnan5c3e6b92014-10-08 19:20:25 -0700135 ctx->mDrawLock.unlock();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700136
137 /* We need to send hotplug to SF only when we are disconnecting
138 * (1) HDMI OR (2) proprietary WFD session */
139 if(dpy == HWC_DISPLAY_EXTERNAL ||
140 ctx->mVirtualonExtActive) {
141 ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug"
142 "event", __FUNCTION__);
143 ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL,
144 EXTERNAL_OFFLINE);
Manoj Kumar AVM7afbcf92013-10-18 09:07:41 -0700145 ctx->mVirtualonExtActive = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700146 }
147 break;
148 }
149 case EXTERNAL_ONLINE:
150 {
151 /* Display already connected */
152 if(ctx->dpyAttr[dpy].connected) {
153 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event"
154 "for display: %d", __FUNCTION__, dpy);
155 break;
156 }
Ramkumar Radhakrishnan5c3e6b92014-10-08 19:20:25 -0700157 ctx->mDrawLock.lock();
158 //Force composition to give up resources like pipes and
159 //close fb. For example if assertive display is going on,
160 //fb2 could be open, thus connecting Layer Mixer#0 to
161 //WriteBack module. If HDMI attempts to open fb1, the driver
162 //will try to attach Layer Mixer#0 to HDMI INT, which will
163 //fail, since Layer Mixer#0 is still connected to WriteBack.
164 //This block will force composition to close fb2 in above
165 //example.
166 ctx->dpyAttr[dpy].isConfiguring = true;
167 ctx->mDrawLock.unlock();
168
169 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700170 //2 cycles for slower content
171 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
172 * 2 / 1000);
173
174 if(dpy == HWC_DISPLAY_EXTERNAL) {
175 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected) {
176 ALOGD_IF(UEVENT_DEBUG,"Received HDMI connection request"
177 "when WFD is active");
178 {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700179 Locker::Autolock _l(ctx->mDrawLock);
Tatenda Chipeperekwaaa832122014-09-16 18:09:18 -0700180 destroyCompositionResources(ctx, HWC_DISPLAY_VIRTUAL);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700181 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
182 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
183 }
184
185 ctx->mVirtualDisplay->teardown();
186
187 /* Need to send hotplug only when connected WFD in
188 * proprietary path */
189 if(ctx->mVirtualonExtActive) {
190 ALOGE_IF(UEVENT_DEBUG,"%s: Sending EXTERNAL OFFLINE"
191 "hotplug event", __FUNCTION__);
192 ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL,
193 EXTERNAL_OFFLINE);
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -0800194 {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700195 Locker::Autolock _l(ctx->mDrawLock);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700196 ctx->mVirtualonExtActive = false;
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -0800197 }
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -0800198 }
Raj kamal9af062e2014-04-01 16:52:19 +0530199
Nirmal Abraham5f0e4482014-08-13 10:58:45 +0530200 ctx->mWfdSyncLock.lock();
Raj kamal9af062e2014-04-01 16:52:19 +0530201 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
202 "%s: Waiting for wfd-teardown to be signalled",
203 __FUNCTION__);
204 ctx->mWfdSyncLock.wait();
205 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
206 "%s: Teardown signalled",__FUNCTION__);
Nirmal Abraham5f0e4482014-08-13 10:58:45 +0530207 ctx->mWfdSyncLock.unlock();
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -0800208 }
Tatenda Chipeperekwa12f41c92014-09-17 12:55:01 -0700209 ctx->mHDMIDisplay->configure();
210 ctx->mHDMIDisplay->activateDisplay();
Tatenda Chipeperekwaaa832122014-09-16 18:09:18 -0700211 ctx->mDrawLock.lock();
212 updateDisplayInfo(ctx, dpy);
213 ctx->mDrawLock.unlock();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700214 } else {
Saurabh Shah188e4332013-07-18 10:33:22 -0700215 {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700216 Locker::Autolock _l(ctx->mDrawLock);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700217 /* TRUE only when we are on proprietary WFD session */
218 ctx->mVirtualonExtActive = true;
219 char property[PROPERTY_VALUE_MAX];
220 if((property_get("persist.sys.wfd.virtual",
221 property, NULL) > 0) &&
222 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
223 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
224 // This means we are on Google's WFD session
225 ctx->mVirtualonExtActive = false;
226 }
Saurabh Shah188e4332013-07-18 10:33:22 -0700227 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700228 ctx->mVirtualDisplay->configure();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800229 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700230
Ramkumar Radhakrishnan5c3e6b92014-10-08 19:20:25 -0700231 ctx->mDrawLock.lock();
Tatenda Chipeperekwaaa832122014-09-16 18:09:18 -0700232 initCompositionResources(ctx, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700233 ctx->dpyAttr[dpy].isPause = false;
234 ctx->dpyAttr[dpy].connected = true;
235 ctx->dpyAttr[dpy].isConfiguring = true;
Ramkumar Radhakrishnan5c3e6b92014-10-08 19:20:25 -0700236 ctx->mDrawLock.unlock();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700237
Raj Kamal2464cce2013-09-06 16:20:12 +0530238 if(dpy == HWC_DISPLAY_EXTERNAL ||
239 ctx->mVirtualonExtActive) {
240 /* External display is HDMI or non-hybrid WFD solution */
241 ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL_OFFLINE ONLINE"
242 "hotplug event", __FUNCTION__);
243 ctx->proc->hotplug(ctx->proc,HWC_DISPLAY_EXTERNAL,
244 EXTERNAL_ONLINE);
245 } else {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700246 /* We wont be getting unblank for VIRTUAL DISPLAY and its
247 * always guaranteed from WFD stack that CONNECT uevent for
248 * VIRTUAL DISPLAY will be triggered before creating
249 * surface for the same. */
250 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800251 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700252 break;
253 }
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700254 case EXTERNAL_PAUSE:
255 { // pause case
256 ALOGD("%s Received Pause event",__FUNCTION__);
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800257 handle_pause(ctx, dpy);
258 break;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800259 }
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700260 case EXTERNAL_RESUME:
261 { // resume case
262 ALOGD("%s Received resume event",__FUNCTION__);
263 //Treat Resume as Online event
264 //Since external didnt have any pipes, force primary to give up
265 //its pipes; we don't allow inter-mixer pipe transfers.
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800266 handle_resume(ctx, dpy);
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700267 break;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700268 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700269 default:
270 {
271 ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state);
272 break;
273 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700274 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700275}
276
277static void *uevent_loop(void *param)
278{
279 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400280 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700281 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700282 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400283 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700284 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
Sravan Kumar D.V.N04ce9ad2013-10-23 15:57:57 +0530285 if(!uevent_init()) {
286 ALOGE("%s: failed to init uevent ",__FUNCTION__);
287 return NULL;
288 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700289
290 while(1) {
291 len = uevent_next_event(udata, sizeof(udata) - 2);
292 handle_uevent(ctx, udata, len);
293 }
294
295 return NULL;
296}
297
298void init_uevent_thread(hwc_context_t* ctx)
299{
300 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700301 int ret;
302
303 ALOGI("Initializing UEVENT Thread");
304 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
305 if (ret) {
306 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
307 HWC_UEVENT_THREAD_NAME, strerror(ret));
308 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700309}
310
311}; //namespace