blob: 65e041b573b90431b58643709672937c8a9899d0 [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 */
42static int getConnectedDisplay(const char* strUdata)
43{
44 if(strcasestr("change@/devices/virtual/switch/hdmi", strUdata))
45 return HWC_DISPLAY_EXTERNAL;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070046 return -1;
47}
48
Veera Sankaran0dadfb32013-07-22 16:07:48 -070049static bool getPanelResetStatus(hwc_context_t* ctx, const char* strUdata, int len)
50{
51 const char* iter_str = strUdata;
52 if (strcasestr("change@/devices/virtual/graphics/fb0", strUdata)) {
53 while(((iter_str - strUdata) <= len) && (*iter_str)) {
54 char* pstr = strstr(iter_str, "PANEL_ALIVE=0");
55 if (pstr != NULL) {
Arpita Banerjeed8965982013-11-08 17:27:33 -080056 ALOGI("%s: got change event in fb0 with PANEL_ALIVE=0",
Veera Sankaran0dadfb32013-07-22 16:07:48 -070057 __FUNCTION__);
58 ctx->mPanelResetStatus = true;
59 return true;
60 }
61 iter_str += strlen(iter_str)+1;
62 }
63 }
64 return false;
65}
66
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070067/* Parse uevent data for action requested for the display */
68static int getConnectedState(const char* strUdata, int len)
69{
70 const char* iter_str = strUdata;
71 while(((iter_str - strUdata) <= len) && (*iter_str)) {
72 char* pstr = strstr(iter_str, "SWITCH_STATE=");
73 if (pstr != NULL) {
74 return (atoi(pstr + strlen("SWITCH_STATE=")));
75 }
76 iter_str += strlen(iter_str)+1;
77 }
78 return -1;
79}
80
Naseer Ahmed72cf9762012-07-21 12:17:13 -070081static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
82{
Veera Sankaran0dadfb32013-07-22 16:07:48 -070083 bool bpanelReset = getPanelResetStatus(ctx, udata, len);
84 if (bpanelReset) {
radhakrishna5d24c252013-12-19 18:03:56 +053085 ctx->proc->invalidate(ctx->proc);
Veera Sankaran0dadfb32013-07-22 16:07:48 -070086 return;
87 }
88
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070089 int dpy = getConnectedDisplay(udata);
90 if(dpy < 0) {
91 ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070092 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070093 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080094
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070095 int switch_state = getConnectedState(udata, len);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080096
Raj kamal59fea562014-04-01 16:52:19 +053097 ALOGE_IF(UEVENT_DEBUG,"%s: uevent received: %s switch state: %d",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070098 __FUNCTION__,udata, switch_state);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080099
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700100 switch(switch_state) {
101 case EXTERNAL_OFFLINE:
102 {
103 /* Display not connected */
104 if(!ctx->dpyAttr[dpy].connected){
105 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event"
106 "for display: %d", __FUNCTION__, dpy);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800107 break;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800108 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700109
Saurabh Shahb39f8152013-08-22 10:21:44 -0700110 Locker::Autolock _l(ctx->mDrawLock);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700111 destroyCompositionResources(ctx, dpy);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700112 ctx->mHDMIDisplay->teardown();
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700113 resetDisplayInfo(ctx, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700114
115 /* We need to send hotplug to SF only when we are disconnecting
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700116 * HDMI */
117 ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug"
118 "event", __FUNCTION__);
119 ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700120 break;
121 }
122 case EXTERNAL_ONLINE:
123 {
124 /* Display already connected */
125 if(ctx->dpyAttr[dpy].connected) {
126 ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event"
127 "for display: %d", __FUNCTION__, dpy);
128 break;
129 }
130 {
131 //Force composition to give up resources like pipes and
132 //close fb. For example if assertive display is going on,
133 //fb2 could be open, thus connecting Layer Mixer#0 to
134 //WriteBack module. If HDMI attempts to open fb1, the driver
135 //will try to attach Layer Mixer#0 to HDMI INT, which will
136 //fail, since Layer Mixer#0 is still connected to WriteBack.
137 //This block will force composition to close fb2 in above
138 //example.
Saurabh Shahb39f8152013-08-22 10:21:44 -0700139 Locker::Autolock _l(ctx->mDrawLock);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700140 ctx->dpyAttr[dpy].isConfiguring = true;
141 ctx->proc->invalidate(ctx->proc);
142 }
143 //2 cycles for slower content
144 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
145 * 2 / 1000);
146
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700147 if(isVDConnected(ctx)) {
148 // Do not initiate WFD teardown if WFD architecture is based
149 // on VDS mechanism.
150 // WFD Stack listens to HDMI intent and initiates virtual
151 // display teardown.
152 // ToDo: Currently non-WFD Virtual display clients do not
153 // involve HWC. If there is a change, we need to come up
154 // with mechanism of how to address non-WFD Virtual display
155 // clients + HDMI
156 ctx->mWfdSyncLock.lock();
157 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
158 "%s: Waiting for wfd-teardown to be signalled",
159 __FUNCTION__);
160 ctx->mWfdSyncLock.wait();
161 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
162 "%s: Teardown signalled. Completed waiting in"
163 "uevent thread", __FUNCTION__);
164 ctx->mWfdSyncLock.unlock();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800165 }
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700166 ctx->mHDMIDisplay->configure();
167 ctx->mHDMIDisplay->activateDisplay();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700168
Saurabh Shahb39f8152013-08-22 10:21:44 -0700169 Locker::Autolock _l(ctx->mDrawLock);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700170 updateDisplayInfo(ctx, dpy);
171 initCompositionResources(ctx, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700172 ctx->dpyAttr[dpy].isPause = false;
173 ctx->dpyAttr[dpy].connected = true;
174 ctx->dpyAttr[dpy].isConfiguring = true;
175
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700176 /* External display is HDMI */
177 ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL ONLINE"
178 "hotplug event", __FUNCTION__);
179 ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_ONLINE);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700180 break;
181 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700182 default:
183 {
184 ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state);
185 break;
186 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700187 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700188}
189
190static void *uevent_loop(void *param)
191{
192 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400193 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700194 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700195 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400196 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700197 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
Sravan Kumar D.V.N04ce9ad2013-10-23 15:57:57 +0530198 if(!uevent_init()) {
199 ALOGE("%s: failed to init uevent ",__FUNCTION__);
200 return NULL;
201 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700202
203 while(1) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530204 len = uevent_next_event(udata, (int)sizeof(udata) - 2);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205 handle_uevent(ctx, udata, len);
206 }
207
208 return NULL;
209}
210
211void init_uevent_thread(hwc_context_t* ctx)
212{
213 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700214 int ret;
215
216 ALOGI("Initializing UEVENT Thread");
217 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
218 if (ret) {
219 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
220 HWC_UEVENT_THREAD_NAME, strerror(ret));
221 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700222}
223
224}; //namespace