gfx/hid/irs/nv/vi: changes related to sysmodule users, see details:

- Removed hard dependency on applet
- Allow appletGetAppletResourceUserId to fail (using default zero in that case)
- nvInitialize uses nvdrv:s for AppletType_None
- gfx now uses weak global __nx_gfx_vi_service_type for the ViServiceType passed to viInitialize
This commit is contained in:
fincs 2018-11-10 16:34:51 +01:00 committed by fincs
parent 3a31df429e
commit ae77cbea97
5 changed files with 12 additions and 29 deletions

View File

@ -12,6 +12,8 @@
#include "display/gfx.h" #include "display/gfx.h"
#include "nvidia/map.h" #include "nvidia/map.h"
__attribute__((weak)) ViServiceType __nx_gfx_vi_service_type = ViServiceType_Default;
static bool g_gfxInitialized = 0; static bool g_gfxInitialized = 0;
static ViDisplay g_gfxDisplay; static ViDisplay g_gfxDisplay;
static Event g_gfxDisplayVsyncEvent; static Event g_gfxDisplayVsyncEvent;
@ -231,7 +233,7 @@ Result gfxInitDefault(void) {
return rc; return rc;
} }
rc = viInitialize(ViServiceType_Default); rc = viInitialize(__nx_gfx_vi_service_type);
if (R_SUCCEEDED(rc)) rc = viOpenDefaultDisplay(&g_gfxDisplay); if (R_SUCCEEDED(rc)) rc = viOpenDefaultDisplay(&g_gfxDisplay);

View File

@ -61,17 +61,12 @@ Result hidInitialize(void)
if (serviceIsActive(&g_hidSrv)) if (serviceIsActive(&g_hidSrv))
return 0; return 0;
if (R_FAILED(appletInitialize()))
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
Result rc; Result rc;
Handle sharedmem_handle; Handle sharedmem_handle;
u64 AppletResourceUserId;
rc = appletGetAppletResourceUserId(&AppletResourceUserId);
// If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero
if (R_FAILED(rc)) u64 AppletResourceUserId = 0;
AppletResourceUserId = 0; appletGetAppletResourceUserId(&AppletResourceUserId);
rc = smGetService(&g_hidSrv, "hid"); rc = smGetService(&g_hidSrv, "hid");
if (R_FAILED(rc)) if (R_FAILED(rc))
@ -124,8 +119,6 @@ void hidExit(void)
serviceClose(&g_hidIAppletResource); serviceClose(&g_hidIAppletResource);
serviceClose(&g_hidSrv); serviceClose(&g_hidSrv);
shmemClose(&g_hidSharedmem); shmemClose(&g_hidSharedmem);
appletExit();
} }
} }

View File

@ -32,19 +32,15 @@ Result irsInitialize(void)
if (serviceIsActive(&g_irsSrv)) if (serviceIsActive(&g_irsSrv))
return 0; return 0;
if (R_FAILED(appletInitialize()))
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
Result rc; Result rc;
Handle sharedmem_handle; Handle sharedmem_handle;
u64 AppletResourceUserId=0;
g_irsSensorActivated = 0; g_irsSensorActivated = 0;
memset(g_irsCameras, 0, sizeof(g_irsCameras)); memset(g_irsCameras, 0, sizeof(g_irsCameras));
rc = appletGetAppletResourceUserId(&AppletResourceUserId); // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero
if (R_FAILED(rc)) u64 AppletResourceUserId=0;
return rc; appletGetAppletResourceUserId(&AppletResourceUserId);
rc = smGetService(&g_irsSrv, "irs"); rc = smGetService(&g_irsSrv, "irs");
if (R_FAILED(rc)) if (R_FAILED(rc))
@ -83,7 +79,6 @@ void irsExit(void)
serviceClose(&g_irsSrv); serviceClose(&g_irsSrv);
shmemClose(&g_irsSharedmem); shmemClose(&g_irsSharedmem);
appletExit();
} }
} }

View File

@ -28,15 +28,14 @@ Result nvInitialize(void)
if (serviceIsActive(&g_nvSrv)) if (serviceIsActive(&g_nvSrv))
return 0; return 0;
if (R_FAILED(appletInitialize())) {
atomicDecrement64(&g_refCnt);
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
}
Result rc = 0; Result rc = 0;
u64 AppletResourceUserId = 0; u64 AppletResourceUserId = 0;
switch (appletGetAppletType()) { switch (appletGetAppletType()) {
case AppletType_None:
rc = smGetService(&g_nvSrv, "nvdrv:s");
break;
case AppletType_Default: case AppletType_Default:
case AppletType_Application: case AppletType_Application:
case AppletType_SystemApplication: case AppletType_SystemApplication:
@ -91,7 +90,6 @@ void nvExit(void)
serviceClose(&g_nvSrvClone); serviceClose(&g_nvSrvClone);
serviceClose(&g_nvSrv); serviceClose(&g_nvSrv);
tmemClose(&g_nvTransfermem); tmemClose(&g_nvTransfermem);
appletExit();
} }
} }

View File

@ -26,9 +26,6 @@ Result viInitialize(ViServiceType service_type)
if (serviceIsActive(&g_viIApplicationDisplayService)) if (serviceIsActive(&g_viIApplicationDisplayService))
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
if (R_FAILED(appletInitialize()))
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
Service root_srv; Service root_srv;
Result rc = 0; Result rc = 0;
@ -88,8 +85,6 @@ void viExit(void)
serviceClose(&g_viIHOSBinderDriverRelay); serviceClose(&g_viIHOSBinderDriverRelay);
serviceClose(&g_viIApplicationDisplayService); serviceClose(&g_viIApplicationDisplayService);
g_viServiceType = ViServiceType_Default; g_viServiceType = ViServiceType_Default;
appletExit();
} }
Service* viGetSession_IApplicationDisplayService(void) Service* viGetSession_IApplicationDisplayService(void)