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) { |
| 124 | ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug" |
| 125 | "event", __FUNCTION__); |
| 126 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE); |
| 127 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | case EXTERNAL_ONLINE: |
| 131 | { |
| 132 | /* Display already connected */ |
| 133 | if(ctx->dpyAttr[dpy].connected) { |
| 134 | ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event" |
| 135 | "for display: %d", __FUNCTION__, dpy); |
| 136 | break; |
| 137 | } |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 138 | |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 139 | if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) { |
| 140 | ctx->mDrawLock.lock(); |
| 141 | handle_online(ctx, dpy); |
| 142 | ctx->mDrawLock.unlock(); |
| 143 | |
| 144 | ctx->proc->invalidate(ctx->proc); |
| 145 | break; |
| 146 | } else { |
| 147 | ctx->mDrawLock.lock(); |
| 148 | //Force composition to give up resources like pipes and |
| 149 | //close fb. For example if assertive display is going on, |
| 150 | //fb2 could be open, thus connecting Layer Mixer#0 to |
| 151 | //WriteBack module. If HDMI attempts to open fb1, the driver |
| 152 | //will try to attach Layer Mixer#0 to HDMI INT, which will |
| 153 | //fail, since Layer Mixer#0 is still connected to WriteBack. |
| 154 | //This block will force composition to close fb2 in above |
| 155 | //example. |
| 156 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 157 | ctx->mDrawLock.unlock(); |
| 158 | |
| 159 | ctx->proc->invalidate(ctx->proc); |
| 160 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 161 | //2 cycles for slower content |
| 162 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 163 | * 2 / 1000); |
| 164 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 165 | if(isVDConnected(ctx)) { |
| 166 | // Do not initiate WFD teardown if WFD architecture is based |
| 167 | // on VDS mechanism. |
| 168 | // WFD Stack listens to HDMI intent and initiates virtual |
| 169 | // display teardown. |
| 170 | // ToDo: Currently non-WFD Virtual display clients do not |
| 171 | // involve HWC. If there is a change, we need to come up |
| 172 | // with mechanism of how to address non-WFD Virtual display |
| 173 | // clients + HDMI |
| 174 | ctx->mWfdSyncLock.lock(); |
| 175 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 176 | "%s: Waiting for wfd-teardown to be signalled", |
| 177 | __FUNCTION__); |
| 178 | ctx->mWfdSyncLock.wait(); |
| 179 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 180 | "%s: Teardown signalled. Completed waiting in" |
| 181 | "uevent thread", __FUNCTION__); |
| 182 | ctx->mWfdSyncLock.unlock(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 183 | } |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 184 | ctx->mHDMIDisplay->configure(); |
| 185 | ctx->mHDMIDisplay->activateDisplay(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 186 | |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 187 | ctx->mDrawLock.lock(); |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 188 | updateDisplayInfo(ctx, dpy); |
| 189 | initCompositionResources(ctx, dpy); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 190 | ctx->dpyAttr[dpy].isPause = false; |
| 191 | ctx->dpyAttr[dpy].connected = true; |
| 192 | ctx->dpyAttr[dpy].isConfiguring = true; |
Ramkumar Radhakrishnan | 5576dc1 | 2014-10-08 19:20:25 -0700 | [diff] [blame] | 193 | ctx->mDrawLock.unlock(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 194 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 195 | /* External display is HDMI */ |
| 196 | ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL ONLINE" |
| 197 | "hotplug event", __FUNCTION__); |
| 198 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_ONLINE); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 199 | break; |
| 200 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 201 | default: |
| 202 | { |
| 203 | ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state); |
| 204 | break; |
| 205 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 206 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void *uevent_loop(void *param) |
| 210 | { |
| 211 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 212 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 213 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 214 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 215 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 216 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
Sravan Kumar D.V.N | 04ce9ad | 2013-10-23 15:57:57 +0530 | [diff] [blame] | 217 | if(!uevent_init()) { |
| 218 | ALOGE("%s: failed to init uevent ",__FUNCTION__); |
| 219 | return NULL; |
| 220 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 221 | |
| 222 | while(1) { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 223 | len = uevent_next_event(udata, (int)sizeof(udata) - 2); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 224 | handle_uevent(ctx, udata, len); |
| 225 | } |
| 226 | |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | void init_uevent_thread(hwc_context_t* ctx) |
| 231 | { |
| 232 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 233 | int ret; |
| 234 | |
| 235 | ALOGI("Initializing UEVENT Thread"); |
| 236 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 237 | if (ret) { |
| 238 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 239 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 240 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | }; //namespace |