[kernel][interrupt] Replace AutoLock variants with Guard in PC interrupt path

AutoLock variants are deprecated in favor of lockdep Guard and this change allows for an
existing violation of the SpinLock in pc/interrupts.cpp and the Mutex in the p2ra library
to be detected by the runtime dependency analysis.

Test: No functional changes. Built and ran kernel unit tests. Observed expected dependency
violation when built with enable_lock_dep=true

ZX-4095 #comment
ZX-3442 #comment

Change-Id: I0163db9990810d4cdd99ea6ce3142740ca4d4eda
diff --git a/zircon/kernel/lib/pow2_range_allocator/include/lib/pow2_range_allocator.h b/zircon/kernel/lib/pow2_range_allocator/include/lib/pow2_range_allocator.h
index 6d02d84..a003831 100644
--- a/zircon/kernel/lib/pow2_range_allocator/include/lib/pow2_range_allocator.h
+++ b/zircon/kernel/lib/pow2_range_allocator/include/lib/pow2_range_allocator.h
@@ -30,7 +30,7 @@
  */
 
 typedef struct p2ra_state {
-    Mutex             lock;
+    DECLARE_MUTEX(p2ra_state) lock;
     struct list_node  ranges;
     struct list_node  unused_blocks;
     struct list_node  allocated_blocks;
diff --git a/zircon/kernel/lib/pow2_range_allocator/pow2_range_allocator.cpp b/zircon/kernel/lib/pow2_range_allocator/pow2_range_allocator.cpp
index 9ba28dd..d59f809 100644
--- a/zircon/kernel/lib/pow2_range_allocator/pow2_range_allocator.cpp
+++ b/zircon/kernel/lib/pow2_range_allocator/pow2_range_allocator.cpp
@@ -10,7 +10,7 @@
 #include <assert.h>
 #include <debug.h>
 #include <fbl/auto_call.h>
-#include <fbl/auto_lock.h>
+#include <kernel/lockdep.h>
 #include <pow2.h>
 #include <stdlib.h>
 #include <string.h>
@@ -193,7 +193,7 @@
     });
 
     /* Enter the lock and check for overlap with pre-existing ranges */
-    fbl::AutoLock guard(&state->lock);
+    Guard<Mutex> guard{&state->lock};
 
     p2ra_range_t* range;
     list_for_every_entry (&state->ranges, range, p2ra_range_t, node) {
@@ -301,7 +301,7 @@
     /* Lock state during allocation */
     p2ra_block_t* block = NULL;
 
-    fbl::AutoLock guard(&state->lock);
+    Guard<Mutex> guard{&state->lock};
 
     /* Find the smallest sized chunk which can hold the allocation and is
      * compatible with the requested addressing capabilities */
@@ -362,7 +362,7 @@
 
     uint bucket = log2_uint_floor(size);
 
-    fbl::AutoLock guard(&state->lock);
+    Guard<Mutex> guard{&state->lock};
 
     /* In a debug build, find the specific block being returned in the list of
      * allocated blocks and use it as the bookkeeping for returning to the free
diff --git a/zircon/kernel/platform/pc/interrupts.cpp b/zircon/kernel/platform/pc/interrupts.cpp
index 1888e6d..92fcbea 100644
--- a/zircon/kernel/platform/pc/interrupts.cpp
+++ b/zircon/kernel/platform/pc/interrupts.cpp
@@ -15,7 +15,7 @@
 #include <dev/interrupt.h>
 #include <err.h>
 #include <fbl/algorithm.h>
-#include <kernel/auto_lock.h>
+#include <kernel/lockdep.h>
 #include <kernel/spinlock.h>
 #include <kernel/thread.h>
 #include <lib/acpi_tables.h>
@@ -35,12 +35,12 @@
 #include <trace.h>
 
 struct int_handler_struct {
-    SpinLock lock;
+    DECLARE_SPINLOCK(int_handler_struct) lock;
     int_handler handler;
     void* arg;
 };
 
-static SpinLock lock;
+DECLARE_SINGLETON_SPINLOCK(InterruptLock);
 static struct int_handler_struct int_handler_table[X86_INT_COUNT];
 static p2ra_state_t x86_irq_vector_allocator;
 
@@ -125,13 +125,13 @@
 LK_INIT_HOOK(apic, &platform_init_apic, LK_INIT_LEVEL_VM + 2)
 
 zx_status_t mask_interrupt(unsigned int vector) {
-    AutoSpinLock guard(&lock);
+    Guard<SpinLock, IrqSave> guard{InterruptLock::Get()};
     apic_io_mask_irq(vector, IO_APIC_IRQ_MASK);
     return ZX_OK;
 }
 
 zx_status_t unmask_interrupt(unsigned int vector) {
-    AutoSpinLock guard(&lock);
+    Guard<SpinLock, IrqSave> guard{InterruptLock::Get()};
     apic_io_mask_irq(vector, IO_APIC_IRQ_UNMASK);
     return ZX_OK;
 }
@@ -139,7 +139,7 @@
 zx_status_t configure_interrupt(unsigned int vector,
                                 enum interrupt_trigger_mode tm,
                                 enum interrupt_polarity pol) {
-    AutoSpinLock guard(&lock);
+    Guard<SpinLock, IrqSave> guard{InterruptLock::Get()};
     apic_io_configure_irq(
         vector,
         tm,
@@ -155,7 +155,7 @@
 zx_status_t get_interrupt_config(unsigned int vector,
                                  enum interrupt_trigger_mode* tm,
                                  enum interrupt_polarity* pol) {
-    AutoSpinLock guard(&lock);
+    Guard<SpinLock, IrqSave> guard{InterruptLock::Get()};
     return apic_io_fetch_irq_config(vector, tm, pol);
 }
 
@@ -169,7 +169,7 @@
     struct int_handler_struct* handler = &int_handler_table[x86_vector];
 
     {
-        AutoSpinLockNoIrqSave guard(&handler->lock);
+        Guard<SpinLock, NoIrqSave> guard{&handler->lock};
         if (handler->handler) {
             handler->handler(handler->arg);
         }
@@ -184,7 +184,7 @@
         return ZX_ERR_INVALID_ARGS;
     }
 
-    AutoSpinLock guard(&lock);
+    Guard<SpinLock, IrqSave> guard{InterruptLock::Get()};
     zx_status_t result = ZX_OK;
 
     /* Fetch the x86 vector currently configured for this global irq.  Force
@@ -228,7 +228,7 @@
 
     {
         // No need to irq_save; we already did that when we grabbed the outer lock.
-        AutoSpinLockNoIrqSave handler_guard(&int_handler_table[x86_vector].lock);
+        Guard<SpinLock, NoIrqSave> handler_guard{&int_handler_table[x86_vector].lock};
 
         if (handler && int_handler_table[x86_vector].handler) {
             p2ra_free_range(&x86_irq_vector_allocator, x86_vector, 1);
@@ -355,7 +355,7 @@
     DEBUG_ASSERT((x86_vector >= X86_INT_PLATFORM_BASE) &&
                  (x86_vector <= X86_INT_PLATFORM_MAX));
 
-    AutoSpinLock guard(&int_handler_table[x86_vector].lock);
+    Guard<SpinLock, IrqSave> guard{&int_handler_table[x86_vector].lock};
     int_handler_table[x86_vector].handler = handler;
     int_handler_table[x86_vector].arg = handler ? ctx : NULL;
 }