public int sceKernelCreateEventFlag( int name, int attr, int bits, int opt ) { KEvent ev = new KEvent( _kernel, _kernel.ReadString( ( uint )name ), ( KEventAttributes )attr, ( uint )bits ); _kernel.AddHandle( ev ); // options unused Debug.Assert( opt == 0 ); return ( int )ev.UID; }
private KernelResult CreateEvent(out int wEventHandle, out int rEventHandle) { KEvent Event = new KEvent(_system); KernelResult result = _process.HandleTable.GenerateHandle(Event.WritableEvent, out wEventHandle); if (result == KernelResult.Success) { result = _process.HandleTable.GenerateHandle(Event.ReadableEvent, out rEventHandle); if (result != KernelResult.Success) { _process.HandleTable.CloseHandle(wEventHandle); } } else { rEventHandle = 0; } return(result); }
public ISelfController(Horizon System) { m_Commands = new Dictionary <int, ServiceProcessRequest>() { { 0, Exit }, { 1, LockExit }, { 2, UnlockExit }, { 9, GetLibraryAppletLaunchableEvent }, { 10, SetScreenShotPermission }, { 11, SetOperationModeChangedNotification }, { 12, SetPerformanceModeChangedNotification }, { 13, SetFocusHandlingMode }, { 14, SetRestartMessageEnabled }, { 16, SetOutOfFocusSuspendingEnabled }, { 19, SetScreenShotImageOrientation }, { 50, SetHandlesRequestToDisplay }, { 62, SetIdleTimeDetectionExtension }, { 63, GetIdleTimeDetectionExtension } }; LaunchableEvent = new KEvent(System); }
public ResultCode QuerySystemEvent(out KEvent systemEvent) { ResultCode resultCode = (ResultCode)_impl.QuerySystemEvent(out IWritableEvent outEvent); if (resultCode == ResultCode.Success) { if (outEvent is AudioKernelEvent) { systemEvent = ((AudioKernelEvent)outEvent).Event; } else { throw new NotImplementedException(); } } else { systemEvent = null; } return(resultCode); }
public IAudioDevice(Horizon System) { m_Commands = new Dictionary <int, ServiceProcessRequest>() { { 0, ListAudioDeviceName }, { 1, SetAudioDeviceOutputVolume }, { 3, GetActiveAudioDeviceName }, { 4, QueryAudioDeviceSystemEvent }, { 5, GetActiveChannelCount }, { 6, ListAudioDeviceNameAuto }, { 7, SetAudioDeviceOutputVolumeAuto }, { 8, GetAudioDeviceOutputVolumeAuto }, { 10, GetActiveAudioDeviceNameAuto }, { 11, QueryAudioDeviceInputEvent }, { 12, QueryAudioDeviceOutputEvent } }; SystemEvent = new KEvent(System); //TODO: We shouldn't be signaling this here. SystemEvent.Signal(); }
public Horizon(Switch Device) { this.Device = Device; Scheduler = new KProcessScheduler(Device.Log); Processes = new ConcurrentDictionary <int, Process>(); State = new SystemStateMgr(); if (!Device.Memory.Allocator.TryAllocate(HidSize, out long HidPA) || !Device.Memory.Allocator.TryAllocate(FontSize, out long FontPA)) { throw new InvalidOperationException(); } HidSharedMem = new KSharedMemory(HidPA, HidSize); FontSharedMem = new KSharedMemory(FontPA, FontSize); Font = new SharedFontManager(Device, FontSharedMem.PA); VsyncEvent = new KEvent(); }
[Command(26)] // 5.0.0+ // AcquireBleServiceDiscoveryEvent() -> (byte<1>, handle<copy>) public ResultCode AcquireBleServiceDiscoveryEvent(ServiceCtx context) { KernelResult result = KernelResult.Success; if (_bleServiceDiscoveryEventHandle == 0) { _bleServiceDiscoveryEvent = new KEvent(context.Device.System.KernelContext); result = context.Process.HandleTable.GenerateHandle(_bleServiceDiscoveryEvent.ReadableEvent, out _bleServiceDiscoveryEventHandle); if (result != KernelResult.Success) { // NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not. Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!"); } } context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleServiceDiscoveryEventHandle); context.ResponseData.Write(result == KernelResult.Success ? 1 : 0); return(ResultCode.Success); }
public Horizon(Switch Device) { this.Device = Device; Processes = new ConcurrentDictionary <int, Process>(); State = new SystemStateMgr(); CriticalSectionLock = new KRecursiveLock(this); Scheduler = new KScheduler(this); TimeManager = new KTimeManager(); AddressArbiter = new KAddressArbiter(this); Synchronization = new KSynchronization(this); Withholders = new LinkedList <KThread>(); Scheduler.StartAutoPreemptionThread(); if (!Device.Memory.Allocator.TryAllocate(HidSize, out long HidPA) || !Device.Memory.Allocator.TryAllocate(FontSize, out long FontPA)) { throw new InvalidOperationException(); } HidSharedMem = new KSharedMemory(HidPA, HidSize); FontSharedMem = new KSharedMemory(FontPA, FontSize); Font = new SharedFontManager(Device, FontSharedMem.PA); VsyncEvent = new KEvent(this); LoadKeySet(); }
// SDK location: /user/pspthreadman.h:719 // SDK declaration: int sceKernelReferEventFlagStatus(SceUID event, SceKernelEventFlagInfo *status); public int sceKernelReferEventFlagStatus(int evid, int status) { // SceSize size // char name [32] // SceUInt attr // SceUInt initPattern // SceUInt currentPattern // int numWaitThreads KEvent ev = _kernel.GetHandle <KEvent>(evid); if (ev == null) { return(-1); } unsafe { byte *p = ( byte * )_memorySystem.Translate(( uint )status); int size = *(( int * )p); if (size == 52) { _kernel.WriteString(( uint )(status + 4), ev.Name); *(( uint * )(p + 36)) = ( uint )ev.Attributes; *(( uint * )(p + 40)) = ev.InitialValue; *(( uint * )(p + 44)) = ev.Value; *(( int * )(p + 48)) = ev.WaitingThreads.Count; return(0); } else { Log.WriteLine(Verbosity.Critical, Feature.Bios, "sceKernelReferEventFlagStatus: app passed in SceKernelEventFlagInfo of size {0}; expected size 52", size); return(-1); } } }
// SDK location: /user/pspthreadman.h:688 // SDK declaration: int sceKernelWaitEventFlag(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout); public int sceKernelWaitEventFlag(int evid, int bits, int wait, int outBits, int timeout) { KEvent ev = _kernel.GetHandle <KEvent>(evid); if (ev == null) { return(-1); } // TODO: event timeouts Debug.Assert(timeout == 0); // We may already be set if (ev.Matches(( uint )bits, ( KWaitType )wait) == true) { if (outBits != 0) { unsafe { uint *poutBits = ( uint * )_memorySystem.Translate(( uint )outBits); * poutBits = ev.Value; } } ev.Clear((uint)bits, (KWaitType)wait); return(0); } else { // No match - wait us KThread thread = _kernel.ActiveThread; Debug.Assert(thread != null); thread.Wait(ev, ( KWaitType )wait, ( uint )bits, ( uint )outBits, ( uint )timeout, false); return(0); } }
public IAudioRenderer( Horizon System, AMemory Memory, IAalOutput AudioOut, AudioRendererParameter Params) { m_Commands = new Dictionary <int, ServiceProcessRequest>() { { 0, GetSampleRate }, { 1, GetSampleCount }, { 2, GetMixBufferCount }, { 3, GetState }, { 4, RequestUpdateAudioRenderer }, { 5, StartAudioRenderer }, { 6, StopAudioRenderer }, { 7, QuerySystemEvent } }; UpdateEvent = new KEvent(System); this.Memory = Memory; this.AudioOut = AudioOut; this.Params = Params; Track = AudioOut.OpenTrack( AudioConsts.HostSampleRate, AudioConsts.HostChannelsCount, AudioCallback); MemoryPools = CreateArray <MemoryPoolContext>(Params.EffectCount + Params.VoiceCount * 4); Voices = CreateArray <VoiceContext>(Params.VoiceCount); InitializeAudioOut(); PlayState = PlayState.Stopped; }
public IAudioRenderer( Horizon system, MemoryManager memory, IAalOutput audioOut, AudioRendererParameter Params) { _commands = new Dictionary <int, ServiceProcessRequest> { { 0, GetSampleRate }, { 1, GetSampleCount }, { 2, GetMixBufferCount }, { 3, GetState }, { 4, RequestUpdateAudioRenderer }, { 5, StartAudioRenderer }, { 6, StopAudioRenderer }, { 7, QuerySystemEvent } }; _updateEvent = new KEvent(system); _memory = memory; _audioOut = audioOut; _params = Params; _track = audioOut.OpenTrack( AudioConsts.HostSampleRate, AudioConsts.HostChannelsCount, AudioCallback); _memoryPools = CreateArray <MemoryPoolContext>(Params.EffectCount + Params.VoiceCount * 4); _voices = CreateArray <VoiceContext>(Params.VoiceCount); InitializeAudioOut(); _playState = PlayState.Stopped; }
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId) { // TODO: accurately represent and implement those events. KEvent targetEvent = null; switch (eventId) { case 0x1: targetEvent = _smExceptionBptIntReportEvent; break; case 0x2: targetEvent = _smExceptionBptPauseReportEvent; break; case 0x3: targetEvent = _errorNotifierEvent; break; } if (targetEvent != null) { if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != KernelResult.Success) { throw new InvalidOperationException("Out of handles!"); } } else { eventHandle = 0; return(NvInternalResult.InvalidInput); } return(NvInternalResult.Success); }
private long OpenAudioOutImpl(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize) { string DeviceName = AMemoryHelper.ReadAsciiString( Context.Memory, SendPosition, SendSize); if (DeviceName == string.Empty) { DeviceName = DefaultAudioOutput; } if (DeviceName != DefaultAudioOutput) { Logger.PrintWarning(LogClass.Audio, "Invalid device name!"); return(MakeError(ErrorModule.Audio, AudErr.DeviceNotFound)); } byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0"); if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize) { Context.Memory.WriteBytes(ReceivePosition, DeviceNameBuffer); } else { Logger.PrintError(LogClass.ServiceAudio, $"Output buffer size {ReceiveSize} too small!"); } int SampleRate = Context.RequestData.ReadInt32(); int Channels = Context.RequestData.ReadInt32(); if (SampleRate == 0) { SampleRate = DefaultSampleRate; } if (SampleRate != DefaultSampleRate) { Logger.PrintWarning(LogClass.Audio, "Invalid sample rate!"); return(MakeError(ErrorModule.Audio, AudErr.UnsupportedSampleRate)); } Channels = (ushort)Channels; if (Channels == 0) { Channels = DefaultChannelsCount; } KEvent ReleaseEvent = new KEvent(Context.Device.System); ReleaseCallback Callback = () => { ReleaseEvent.ReadableEvent.Signal(); }; IAalOutput AudioOut = Context.Device.AudioOut; int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback); MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track)); Context.ResponseData.Write(SampleRate); Context.ResponseData.Write(Channels); Context.ResponseData.Write((int)SampleFormat.PcmInt16); Context.ResponseData.Write((int)PlaybackState.Stopped); return(0); }
public IApplicationFunctions(Horizon system) { _gpuErrorDetectedSystemEvent = new KEvent(system.KernelContext); _friendInvitationStorageChannelEvent = new KEvent(system.KernelContext); _notificationStorageChannelEvent = new KEvent(system.KernelContext); }
public INvDrvServices(ServiceCtx context) { _event = new KEvent(context.Device.System); }
public ICommonStateGetter(Horizon system) { _displayResolutionChangeEvent = new KEvent(system); }
public ISelfController(Horizon system) { _libraryAppletLaunchableEvent = new KEvent(system.KernelContext); }
public IAddOnContentManager(ServiceCtx context) { _addOnContentListChangedEvent = new KEvent(context.Device.System.KernelContext); }
public Horizon(Switch device, ContentManager contentManager) { ControlData = new BlitStruct <ApplicationControlProperty>(1); Device = device; State = new SystemStateMgr(); ResourceLimit = new KResourceLimit(this); KernelInit.InitializeResourceLimit(ResourceLimit); MemoryRegions = KernelInit.GetMemoryRegions(); LargeMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize * 2); SmallMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize); UserSlabHeapPages = new KSlabHeap( UserSlabHeapBase, UserSlabHeapItemSize, UserSlabHeapSize); CriticalSection = new KCriticalSection(this); Scheduler = new KScheduler(this); TimeManager = new KTimeManager(); Synchronization = new KSynchronization(this); ContextIdManager = new KContextIdManager(); _kipId = InitialKipId; _processId = InitialProcessId; Scheduler.StartAutoPreemptionThread(); KernelInitialized = true; ThreadCounter = new CountdownEvent(1); Processes = new SortedDictionary <long, KProcess>(); AutoObjectNames = new ConcurrentDictionary <string, KAutoObject>(); // Note: This is not really correct, but with HLE of services, the only memory // region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = MemoryRegions[(int)MemoryRegion.NvServices]; ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; ulong iirsPa = region.Address + HidSize + FontSize; ulong timePa = region.Address + HidSize + FontSize + IirsSize; HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase); KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); KPageList iirsPageList = new KPageList(); KPageList timePageList = new KPageList(); hidPageList.AddRange(hidPa, HidSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); iirsPageList.AddRange(iirsPa, IirsSize / KMemoryManager.PageSize); timePageList.AddRange(timePa, TimeSize / KMemoryManager.PageSize); HidSharedMem = new KSharedMemory(this, hidPageList, 0, 0, MemoryPermission.Read); FontSharedMem = new KSharedMemory(this, fontPageList, 0, 0, MemoryPermission.Read); IirsSharedMem = new KSharedMemory(this, iirsPageList, 0, 0, MemoryPermission.Read); KSharedMemory timeSharedMemory = new KSharedMemory(this, timePageList, 0, 0, MemoryPermission.Read); TimeServiceManager.Instance.Initialize(device, this, timeSharedMemory, (long)(timePa - DramMemoryMap.DramBase), TimeSize); AppletState = new AppletStateMgr(this); AppletState.SetFocus(true); Font = new SharedFontManager(device, (long)(fontPa - DramMemoryMap.DramBase)); IUserInterface.InitializePort(this); VsyncEvent = new KEvent(this); ContentManager = contentManager; // TODO: use set:sys (and get external clock source id from settings) // TODO: use "time!standard_steady_clock_rtc_update_interval_minutes" and implement a worker thread to be accurate. UInt128 clockSourceId = new UInt128(Guid.NewGuid().ToByteArray()); IRtcManager.GetExternalRtcValue(out ulong rtcValue); // We assume the rtc is system time. TimeSpanType systemTime = TimeSpanType.FromSeconds((long)rtcValue); // First init the standard steady clock TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, TimeSpanType.Zero, TimeSpanType.Zero, false); TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds()); if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes)) { TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); TimeServiceManager.Instance.SetupStandardNetworkSystemClock(new SystemClockContext(), standardNetworkClockSufficientAccuracy); } TimeServiceManager.Instance.SetupStandardUserSystemClock(null, false, SteadyClockTimePoint.GetRandom()); // FIXME: TimeZone shoud be init here but it's actually done in ContentManager TimeServiceManager.Instance.SetupEphemeralNetworkSystemClock(); }
public ILibraryAppletAccessor(Horizon system) { _stateChangedEvent = new KEvent(system); }
public Horizon(Switch device) { Device = device; State = new SystemStateMgr(); ResourceLimit = new KResourceLimit(this); KernelInit.InitializeResourceLimit(ResourceLimit); MemoryRegions = KernelInit.GetMemoryRegions(); LargeMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize * 2); SmallMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize); UserSlabHeapPages = new KSlabHeap( UserSlabHeapBase, UserSlabHeapItemSize, UserSlabHeapSize); CriticalSection = new KCriticalSection(this); Scheduler = new KScheduler(this); TimeManager = new KTimeManager(); Synchronization = new KSynchronization(this); ContextIdManager = new KContextIdManager(); _kipId = InitialKipId; _processId = InitialProcessId; Scheduler.StartAutoPreemptionThread(); KernelInitialized = true; ThreadCounter = new CountdownEvent(1); Processes = new SortedDictionary <long, KProcess>(); AutoObjectNames = new ConcurrentDictionary <string, KAutoObject>(); //Note: This is not really correct, but with HLE of services, the only memory //region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = MemoryRegions[(int)MemoryRegion.NvServices]; ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase); KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); hidPageList.AddRange(hidPa, HidSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); HidSharedMem = new KSharedMemory(hidPageList, 0, 0, MemoryPermission.Read); FontSharedMem = new KSharedMemory(fontPageList, 0, 0, MemoryPermission.Read); AppletState = new AppletStateMgr(this); AppletState.SetFocus(true); Font = new SharedFontManager(device, (long)(fontPa - DramMemoryMap.DramBase)); VsyncEvent = new KEvent(this); LoadKeySet(); ContentManager = new ContentManager(device); }
public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) { _errorEvent = new KEvent(context.Device.System.KernelContext); _unknownEvent = new KEvent(context.Device.System.KernelContext); }
public IPsmSession(Horizon system) { _stateChangeEvent = new KEvent(system); _stateChangeEventHandle = -1; }
public IAudioOut(IAalOutput audioOut, KEvent releaseEvent, int track) { _audioOut = audioOut; _releaseEvent = releaseEvent; _track = track; }
private ResultCode OpenAudioOutImpl(ServiceCtx context, long sendPosition, long sendSize, long receivePosition, long receiveSize) { string deviceName = MemoryHelper.ReadAsciiString( context.Memory, sendPosition, sendSize); if (deviceName == string.Empty) { deviceName = DefaultAudioOutput; } if (deviceName != DefaultAudioOutput) { Logger.PrintWarning(LogClass.Audio, "Invalid device name!"); return(ResultCode.DeviceNotFound); } byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(deviceName + "\0"); if ((ulong)deviceNameBuffer.Length <= (ulong)receiveSize) { context.Memory.Write((ulong)receivePosition, deviceNameBuffer); } else { Logger.PrintError(LogClass.ServiceAudio, $"Output buffer size {receiveSize} too small!"); } int sampleRate = context.RequestData.ReadInt32(); int channels = context.RequestData.ReadInt32(); if (sampleRate == 0) { sampleRate = DefaultSampleRate; } if (sampleRate != DefaultSampleRate) { Logger.PrintWarning(LogClass.Audio, "Invalid sample rate!"); return(ResultCode.UnsupportedSampleRate); } channels = (ushort)channels; if (channels == 0) { channels = DefaultChannelsCount; } KEvent releaseEvent = new KEvent(context.Device.System.KernelContext); ReleaseCallback callback = () => { releaseEvent.ReadableEvent.Signal(); }; IAalOutput audioOut = context.Device.AudioOut; int track = audioOut.OpenTrack(sampleRate, channels, callback); MakeObject(context, new IAudioOut(audioOut, releaseEvent, track)); context.ResponseData.Write(sampleRate); context.ResponseData.Write(channels); context.ResponseData.Write((int)SampleFormat.PcmInt16); context.ResponseData.Write((int)PlaybackState.Stopped); return(ResultCode.Success); }
public AppletStateMgr() { Messages = new ConcurrentQueue <MessageInfo>(); MessageEvent = new KEvent(); }
public AppletStateMgr(Horizon system) { _messages = new ConcurrentQueue <MessageInfo>(); MessageEvent = new KEvent(system); }
public Horizon(Switch device) { KernelContext = new KernelContext( device, device.Memory, device.Configuration.MemoryConfiguration.ToKernelMemorySize(), device.Configuration.MemoryConfiguration.ToKernelMemoryArrange()); Device = device; State = new SystemStateMgr(); PerformanceState = new PerformanceState(); NfpDevices = new List <NfpDevice>(); // Note: This is not really correct, but with HLE of services, the only memory // region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = KernelContext.MemoryManager.MemoryRegions[(int)MemoryRegion.NvServices]; ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; ulong iirsPa = region.Address + HidSize + FontSize; ulong timePa = region.Address + HidSize + FontSize + IirsSize; ulong appletCaptureBufferPa = region.Address + HidSize + FontSize + IirsSize + TimeSize; KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); KPageList iirsPageList = new KPageList(); KPageList timePageList = new KPageList(); KPageList appletCaptureBufferPageList = new KPageList(); hidPageList.AddRange(hidPa, HidSize / KPageTableBase.PageSize); fontPageList.AddRange(fontPa, FontSize / KPageTableBase.PageSize); iirsPageList.AddRange(iirsPa, IirsSize / KPageTableBase.PageSize); timePageList.AddRange(timePa, TimeSize / KPageTableBase.PageSize); appletCaptureBufferPageList.AddRange(appletCaptureBufferPa, AppletCaptureBufferSize / KPageTableBase.PageSize); var hidStorage = new SharedMemoryStorage(KernelContext, hidPageList); var fontStorage = new SharedMemoryStorage(KernelContext, fontPageList); var iirsStorage = new SharedMemoryStorage(KernelContext, iirsPageList); var timeStorage = new SharedMemoryStorage(KernelContext, timePageList); var appletCaptureBufferStorage = new SharedMemoryStorage(KernelContext, appletCaptureBufferPageList); HidStorage = hidStorage; HidSharedMem = new KSharedMemory(KernelContext, hidStorage, 0, 0, KMemoryPermission.Read); FontSharedMem = new KSharedMemory(KernelContext, fontStorage, 0, 0, KMemoryPermission.Read); IirsSharedMem = new KSharedMemory(KernelContext, iirsStorage, 0, 0, KMemoryPermission.Read); KSharedMemory timeSharedMemory = new KSharedMemory(KernelContext, timeStorage, 0, 0, KMemoryPermission.Read); TimeServiceManager.Instance.Initialize(device, this, timeSharedMemory, timeStorage, TimeSize); AppletCaptureBufferTransfer = new KTransferMemory(KernelContext, appletCaptureBufferStorage); AppletState = new AppletStateMgr(this); AppletState.SetFocus(true); Font = new SharedFontManager(device, fontStorage); VsyncEvent = new KEvent(KernelContext); DisplayResolutionChangeEvent = new KEvent(KernelContext); AccountManager = device.Configuration.AccountManager; ContentManager = device.Configuration.ContentManager; CaptureManager = new CaptureManager(device); // TODO: use set:sys (and get external clock source id from settings) // TODO: use "time!standard_steady_clock_rtc_update_interval_minutes" and implement a worker thread to be accurate. UInt128 clockSourceId = new UInt128(Guid.NewGuid().ToByteArray()); IRtcManager.GetExternalRtcValue(out ulong rtcValue); // We assume the rtc is system time. TimeSpanType systemTime = TimeSpanType.FromSeconds((long)rtcValue); // Configure and setup internal offset TimeSpanType internalOffset = TimeSpanType.FromSeconds(device.Configuration.SystemTimeOffset); TimeSpanType systemTimeOffset = new TimeSpanType(systemTime.NanoSeconds + internalOffset.NanoSeconds); if (systemTime.IsDaylightSavingTime() && !systemTimeOffset.IsDaylightSavingTime()) { internalOffset = internalOffset.AddSeconds(3600L); } else if (!systemTime.IsDaylightSavingTime() && systemTimeOffset.IsDaylightSavingTime()) { internalOffset = internalOffset.AddSeconds(-3600L); } internalOffset = new TimeSpanType(-internalOffset.NanoSeconds); // First init the standard steady clock TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, internalOffset, TimeSpanType.Zero, false); TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds()); if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes)) { TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); // The network system clock needs a valid system clock, as such we setup this system clock using the local system clock. TimeServiceManager.Instance.StandardLocalSystemClock.GetClockContext(null, out SystemClockContext localSytemClockContext); TimeServiceManager.Instance.SetupStandardNetworkSystemClock(localSytemClockContext, standardNetworkClockSufficientAccuracy); } TimeServiceManager.Instance.SetupStandardUserSystemClock(null, false, SteadyClockTimePoint.GetRandom()); // FIXME: TimeZone shoud be init here but it's actually done in ContentManager TimeServiceManager.Instance.SetupEphemeralNetworkSystemClock(); DatabaseImpl.Instance.InitializeDatabase(device); HostSyncpoint = new NvHostSyncpt(device); SurfaceFlinger = new SurfaceFlinger(device); InitLibHacHorizon(); InitializeAudioRenderer(); }
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, memory, owner) { _smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle); _smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle); _errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle); }
public Horizon(Switch device, ContentManager contentManager) { ControlData = new BlitStruct <ApplicationControlProperty>(1); KernelContext = new KernelContext(device, device.Memory); Device = device; State = new SystemStateMgr(); // Note: This is not really correct, but with HLE of services, the only memory // region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = KernelContext.MemoryRegions[(int)MemoryRegion.NvServices]; ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; ulong iirsPa = region.Address + HidSize + FontSize; ulong timePa = region.Address + HidSize + FontSize + IirsSize; HidBaseAddress = hidPa - DramMemoryMap.DramBase; KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); KPageList iirsPageList = new KPageList(); KPageList timePageList = new KPageList(); hidPageList.AddRange(hidPa, HidSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); iirsPageList.AddRange(iirsPa, IirsSize / KMemoryManager.PageSize); timePageList.AddRange(timePa, TimeSize / KMemoryManager.PageSize); HidSharedMem = new KSharedMemory(KernelContext, hidPageList, 0, 0, MemoryPermission.Read); FontSharedMem = new KSharedMemory(KernelContext, fontPageList, 0, 0, MemoryPermission.Read); IirsSharedMem = new KSharedMemory(KernelContext, iirsPageList, 0, 0, MemoryPermission.Read); KSharedMemory timeSharedMemory = new KSharedMemory(KernelContext, timePageList, 0, 0, MemoryPermission.Read); TimeServiceManager.Instance.Initialize(device, this, timeSharedMemory, timePa - DramMemoryMap.DramBase, TimeSize); AppletState = new AppletStateMgr(this); AppletState.SetFocus(true); Font = new SharedFontManager(device, fontPa - DramMemoryMap.DramBase); IUserInterface.InitializePort(this); VsyncEvent = new KEvent(KernelContext); DisplayResolutionChangeEvent = new KEvent(KernelContext); ContentManager = contentManager; // TODO: use set:sys (and get external clock source id from settings) // TODO: use "time!standard_steady_clock_rtc_update_interval_minutes" and implement a worker thread to be accurate. UInt128 clockSourceId = new UInt128(Guid.NewGuid().ToByteArray()); IRtcManager.GetExternalRtcValue(out ulong rtcValue); // We assume the rtc is system time. TimeSpanType systemTime = TimeSpanType.FromSeconds((long)rtcValue); // Configure and setup internal offset TimeSpanType internalOffset = TimeSpanType.FromSeconds(ConfigurationState.Instance.System.SystemTimeOffset); TimeSpanType systemTimeOffset = new TimeSpanType(systemTime.NanoSeconds + internalOffset.NanoSeconds); if (systemTime.IsDaylightSavingTime() && !systemTimeOffset.IsDaylightSavingTime()) { internalOffset = internalOffset.AddSeconds(3600L); } else if (!systemTime.IsDaylightSavingTime() && systemTimeOffset.IsDaylightSavingTime()) { internalOffset = internalOffset.AddSeconds(-3600L); } internalOffset = new TimeSpanType(-internalOffset.NanoSeconds); // First init the standard steady clock TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, internalOffset, TimeSpanType.Zero, false); TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds()); if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes)) { TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); TimeServiceManager.Instance.SetupStandardNetworkSystemClock(new SystemClockContext(), standardNetworkClockSufficientAccuracy); } TimeServiceManager.Instance.SetupStandardUserSystemClock(null, false, SteadyClockTimePoint.GetRandom()); // FIXME: TimeZone shoud be init here but it's actually done in ContentManager TimeServiceManager.Instance.SetupEphemeralNetworkSystemClock(); DatabaseImpl.Instance.InitializeDatabase(device); HostSyncpoint = new NvHostSyncpt(device); SurfaceFlinger = new SurfaceFlinger(device); ConfigurationState.Instance.System.EnableDockedMode.Event += OnDockedModeChange; InitLibHacHorizon(); }