Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 1 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 4 | * Copyright (C) 2012-14, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 5 | * |
| 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 Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 21 | #define UEVENT_DEBUG 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <hardware_legacy/uevent.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <sys/resource.h> |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 25 | #include <sys/prctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include "hwc_utils.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 29 | #include "hwc_fbupdate.h" |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 30 | #include "hwc_mdpcomp.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 31 | #include "hwc_copybit.h" |
| 32 | #include "comptype.h" |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 33 | #include "hdmi.h" |
Tatenda Chipeperekwa | 8f1b9d7 | 2014-02-11 16:20:50 -0800 | [diff] [blame] | 34 | #include "hwc_virtual.h" |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 35 | #include "mdp_version.h" |
Amara Venkata Mastan Manoj Kumar | 5cbac94 | 2013-08-13 19:00:14 -0700 | [diff] [blame] | 36 | using namespace overlay; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 37 | namespace qhwc { |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 38 | #define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/" |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 39 | #define HWC_UEVENT_THREAD_NAME "hwcUeventThread" |
| 40 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 41 | /* Parse uevent data for devices which we are interested */ |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 42 | static int getConnectedDisplay(hwc_context_t* ctx, const char* strUdata) |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 43 | { |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 44 | 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 Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 56 | static 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 Banerjee | d896598 | 2013-11-08 17:27:33 -0800 | [diff] [blame] | 63 | ALOGI("%s: got change event in fb0 with PANEL_ALIVE=0", |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 64 | __FUNCTION__); |
| 65 | ctx->mPanelResetStatus = true; |
| 66 | return true; |
| 67 | } |
| 68 | iter_str += strlen(iter_str)+1; |
| 69 | } |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 74 | /* Parse uevent data for action requested for the display */ |
| 75 | static 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 88 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 89 | { |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 90 | bool bpanelReset = getPanelResetStatus(ctx, udata, len); |
| 91 | if (bpanelReset) { |
radhakrishna | 5d24c25 | 2013-12-19 18:03:56 +0530 | [diff] [blame] | 92 | ctx->proc->invalidate(ctx->proc); |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 96 | int dpy = getConnectedDisplay(ctx, udata); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 97 | if(dpy < 0) { |
| 98 | ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 99 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 100 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 101 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 102 | int switch_state = getConnectedState(udata, len); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 103 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 104 | ALOGE_IF(UEVENT_DEBUG,"%s: uevent received: %s switch state: %d", |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 105 | __FUNCTION__,udata, switch_state); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 106 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 107 | 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 Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 114 | break; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 115 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 116 | |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 117 | ctx->mDrawLock.lock(); |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 118 | handle_offline(ctx, dpy); |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 119 | ctx->mDrawLock.unlock(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 120 | |
| 121 | /* We need to send hotplug to SF only when we are disconnecting |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 122 | * HDMI as an external display. */ |
| 123 | if(dpy == HWC_DISPLAY_EXTERNAL) { |
Saurabh Shah | 15455aa | 2015-01-28 13:54:48 -0800 | [diff] [blame] | 124 | ALOGI("%s: Sending EXTERNAL OFFLINE event", __FUNCTION__); |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 125 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE); |
| 126 | } |
Saurabh Shah | b85284b | 2015-01-27 10:54:52 -0800 | [diff] [blame] | 127 | |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 128 | // Report Hotplug via CEC HAL |
| 129 | ctx->mQService->onHdmiHotplug((int)ctx->dpyAttr[dpy].connected); |
| 130 | |
Saurabh Shah | b85284b | 2015-01-27 10:54:52 -0800 | [diff] [blame] | 131 | //On 8994, 8992 due to hardware limitations, we disable bwc |
| 132 | //when HDMI intf is active |
| 133 | if((qdutils::MDPVersion::getInstance().is8994() or |
Saurabh Shah | 23a9520 | 2015-03-03 10:50:27 -0800 | [diff] [blame] | 134 | qdutils::MDPVersion::getInstance().is8992()) and |
Saurabh Shah | b85284b | 2015-01-27 10:54:52 -0800 | [diff] [blame] | 135 | qdutils::MDPVersion::getInstance().supportsBWC()) { |
| 136 | Locker::Autolock _l(ctx->mDrawLock); |
| 137 | ctx->mBWCEnabled = true; |
| 138 | } |
| 139 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 140 | 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 Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 150 | |
Saurabh Shah | b85284b | 2015-01-27 10:54:52 -0800 | [diff] [blame] | 151 | //On 8994, 8992 due to hardware limitations, we disable bwc |
| 152 | //when HDMI intf is active |
| 153 | if((qdutils::MDPVersion::getInstance().is8994() or |
Saurabh Shah | 23a9520 | 2015-03-03 10:50:27 -0800 | [diff] [blame] | 154 | qdutils::MDPVersion::getInstance().is8992()) and |
Saurabh Shah | b85284b | 2015-01-27 10:54:52 -0800 | [diff] [blame] | 155 | qdutils::MDPVersion::getInstance().supportsBWC()) { |
| 156 | Locker::Autolock _l(ctx->mDrawLock); |
| 157 | ctx->mBWCEnabled = false; |
| 158 | } |
| 159 | |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 160 | if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) { |
| 161 | ctx->mDrawLock.lock(); |
| 162 | handle_online(ctx, dpy); |
| 163 | ctx->mDrawLock.unlock(); |
Naseer Ahmed | 251c030 | 2014-10-10 12:53:13 -0400 | [diff] [blame] | 164 | ctx->mQService->onHdmiHotplug(ctx->dpyAttr[dpy].connected); |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 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 Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 182 | //2 cycles for slower content |
| 183 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 184 | * 2 / 1000); |
| 185 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 186 | 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.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 204 | } |
Arun Kumar K.R | 205df77 | 2015-02-20 18:45:58 -0800 | [diff] [blame] | 205 | // If FB open fails ignore this hotplug event |
| 206 | int error = ctx->mHDMIDisplay->configure(); |
| 207 | if (error < 0) { |
| 208 | ALOGE("%s: Open Framebuffer for dpy = %d", __FUNCTION__, dpy); |
| 209 | ctx->mDrawLock.lock(); |
| 210 | ctx->dpyAttr[dpy].isConfiguring = false; |
| 211 | ctx->mDrawLock.unlock(); |
| 212 | break; |
| 213 | } |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 214 | ctx->mHDMIDisplay->activateDisplay(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 215 | |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 216 | ctx->mDrawLock.lock(); |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 217 | updateDisplayInfo(ctx, dpy); |
| 218 | initCompositionResources(ctx, dpy); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 219 | ctx->dpyAttr[dpy].isPause = false; |
| 220 | ctx->dpyAttr[dpy].connected = true; |
| 221 | ctx->dpyAttr[dpy].isConfiguring = true; |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 222 | ctx->mDrawLock.unlock(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 223 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 224 | /* External display is HDMI */ |
Saurabh Shah | 15455aa | 2015-01-28 13:54:48 -0800 | [diff] [blame] | 225 | ALOGI("%s: Sending EXTERNAL ONLINE event", __FUNCTION__); |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 226 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_ONLINE); |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 227 | ctx->mQService->onHdmiHotplug(ctx->dpyAttr[dpy].connected); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 228 | break; |
| 229 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 230 | default: |
| 231 | { |
Saurabh Shah | 15455aa | 2015-01-28 13:54:48 -0800 | [diff] [blame] | 232 | ALOGE("%s: Invalid state to switch:%d", __FUNCTION__, switch_state); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 233 | break; |
| 234 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 235 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static void *uevent_loop(void *param) |
| 239 | { |
| 240 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 241 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 242 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 243 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 244 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 245 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
Sravan Kumar D.V.N | 04ce9ad | 2013-10-23 15:57:57 +0530 | [diff] [blame] | 246 | if(!uevent_init()) { |
| 247 | ALOGE("%s: failed to init uevent ",__FUNCTION__); |
| 248 | return NULL; |
| 249 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 250 | |
| 251 | while(1) { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 252 | len = uevent_next_event(udata, (int)sizeof(udata) - 2); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 253 | handle_uevent(ctx, udata, len); |
| 254 | } |
| 255 | |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | void init_uevent_thread(hwc_context_t* ctx) |
| 260 | { |
| 261 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 262 | int ret; |
| 263 | |
| 264 | ALOGI("Initializing UEVENT Thread"); |
| 265 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 266 | if (ret) { |
| 267 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 268 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 269 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | }; //namespace |