1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <ddk/protocol/intelgpucore.h>
8 #include <fbl/macros.h>
9 #include <threads.h>
10 #include <zircon/types.h>
11 #include <lib/zx/handle.h>
12 
13 #include "registers-pipe.h"
14 
15 namespace i915 {
16 
17 class Controller;
18 
19 class Interrupts {
20 public:
21     Interrupts();
22     ~Interrupts();
23 
24     zx_status_t Init(Controller* controller);
25     void FinishInit();
26     void Resume();
27     void Destroy();
28 
29     void EnablePipeVsync(registers::Pipe pipe, bool enable);
30     zx_status_t SetInterruptCallback(const zx_intel_gpu_core_interrupt_t* callback,
31                                      uint32_t interrupt_mask);
32 
33     int IrqLoop();
34 private:
35     void EnableHotplugInterrupts();
36     void HandlePipeInterrupt(registers::Pipe pipe, zx_time_t timestamp);
37 
38     Controller* controller_; // Assume that controller callbacks are threadsafe
39 
40     zx::handle irq_;
41     thrd_t irq_thread_;
42 
43     zx_intel_gpu_core_interrupt_t interrupt_cb_ __TA_GUARDED(lock_);
44     uint32_t interrupt_mask_ __TA_GUARDED(lock_) = 0;
45 
46     mtx_t lock_;
47 
48     DISALLOW_COPY_ASSIGN_AND_MOVE(Interrupts);
49 };
50 
51 } // namespace i915
52