Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 159)
+++ trunk/src/os2ahci/Makefile	(revision 160)
@@ -30,7 +30,7 @@
 # Define default build version if not specified in environment
 BLD_MAJOR=1
-BLD_MINOR=27 # must be 2 digits
+BLD_MINOR=28 # must be 2 digits
 BLD_REV=0 # not used at this time
-FIXPACK=
+FIXPACK=Test Build
 
 !ifndef %WATCOM # if not defined in the environment
@@ -91,6 +91,6 @@
 AFLAGS = -q
 # In order to build the SMP safe version you must have the updated devhelp.h and define OS2AHCI_SMP.
-CFLAGS = -ei -6 -d0 -bt=os2 -ms -zu -wx -ecc -zp=1 -q -s -zgp -zfp -oi -DOS2AHCI_SMP
-CFLAGS_DEBUG = -ei -6 -d3 -hc -bt=os2 -ms -zu -ecc -zp=1 -q -s -zgp -zfp -od
+CFLAGS= -ei -6 -d0 -bt=os2 -ms -zu -wx -ecc -zp1 -q -s -zgp -zfp -oi -DOS2AHCI_SMP
+CFLAGS_DEBUG = -ei -6 -d3 -hc -bt=os2 -ms -zu -ecc -zp1 -q -s -zgp -zfp -od
 
 ###############################################################################
Index: trunk/src/os2ahci/README
===================================================================
--- trunk/src/os2ahci/README	(revision 159)
+++ trunk/src/os2ahci/README	(revision 160)
@@ -44,5 +44,5 @@
 The *binary* delivery of OS2AHCI.ADD as obtained from ecomstation.nl,
 or as part of packaged eComStation releases, is licensed to run with
-eComStation, only.
+eComStation only.
 
 The source code can be retrieved from http://svn.ecomstation.nl;
@@ -382,4 +382,9 @@
 ==========
 
+v.1.28 30-May-2013 - David Azarewicz
+  Reworked trap dump kernel exit
+  Removed unused IDC entry point.
+  Some work on suspend/resume routines.
+
 v.1.27 23-Apr-2013 - David Azarewicz
   Added LVM aware disk geometry reporting.
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 159)
+++ trunk/src/os2ahci/ahci.c	(revision 160)
@@ -162,47 +162,49 @@
 
   /* print AHCI register debug information */
+  #ifdef DEBUG
   if (debug) {
-    printf("AHCI global controller registers:\n");
+    aprintf("AHCI global controller registers:\n");
     for (i = 0; i <= HOST_CAP2 / sizeof(u32); i++) {
       u32 val = ai->bios_config[i];
-      printf(" %02x: %08lx", i, val);
+      aprintf(" %02x: %08lx", i, val);
 
       if (i == HOST_CAP) {
-        printf_nts(" -");
-        if (val & HOST_CAP_64)         printf_nts(" 64bit");
-        if (val & HOST_CAP_NCQ)        printf_nts(" ncq");
-        if (val & HOST_CAP_SNTF)       printf_nts(" sntf");
-        if (val & HOST_CAP_MPS)        printf_nts(" mps");
-        if (val & HOST_CAP_SSS)        printf_nts(" sss");
-        if (val & HOST_CAP_ALPM)       printf_nts(" alpm");
-        if (val & HOST_CAP_LED)        printf_nts(" led");
-        if (val & HOST_CAP_CLO)        printf_nts(" clo");
-        if (val & HOST_CAP_ONLY)       printf_nts(" ahci_only");
-        if (val & HOST_CAP_PMP)        printf_nts(" pmp");
-        if (val & HOST_CAP_FBS)        printf_nts(" fbs");
-        if (val & HOST_CAP_PIO_MULTI)  printf_nts(" pio_multi");
-        if (val & HOST_CAP_SSC)        printf_nts(" ssc");
-        if (val & HOST_CAP_PART)       printf_nts(" part");
-        if (val & HOST_CAP_CCC)        printf_nts(" ccc");
-        if (val & HOST_CAP_EMS)        printf_nts(" ems");
-        if (val & HOST_CAP_SXS)        printf_nts(" sxs");
-        printf_nts(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
-        printf_nts(" ports:%d",     (u16) (val & 0x1f) + 1);
+        ntprintf(" -");
+        if (val & HOST_CAP_64)         ntprintf(" 64bit");
+        if (val & HOST_CAP_NCQ)        ntprintf(" ncq");
+        if (val & HOST_CAP_SNTF)       ntprintf(" sntf");
+        if (val & HOST_CAP_MPS)        ntprintf(" mps");
+        if (val & HOST_CAP_SSS)        ntprintf(" sss");
+        if (val & HOST_CAP_ALPM)       ntprintf(" alpm");
+        if (val & HOST_CAP_LED)        ntprintf(" led");
+        if (val & HOST_CAP_CLO)        ntprintf(" clo");
+        if (val & HOST_CAP_ONLY)       ntprintf(" ahci_only");
+        if (val & HOST_CAP_PMP)        ntprintf(" pmp");
+        if (val & HOST_CAP_FBS)        ntprintf(" fbs");
+        if (val & HOST_CAP_PIO_MULTI)  ntprintf(" pio_multi");
+        if (val & HOST_CAP_SSC)        ntprintf(" ssc");
+        if (val & HOST_CAP_PART)       ntprintf(" part");
+        if (val & HOST_CAP_CCC)        ntprintf(" ccc");
+        if (val & HOST_CAP_EMS)        ntprintf(" ems");
+        if (val & HOST_CAP_SXS)        ntprintf(" sxs");
+        ntprintf(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
+        ntprintf(" ports:%d",     (u16) (val & 0x1f) + 1);
 
       } else if (i == HOST_CTL) {
-        printf_nts(" -");
-        if (val & HOST_AHCI_EN)        printf_nts(" ahci_enabled");
-        if (val & HOST_IRQ_EN)         printf_nts(" irq_enabled");
-        if (val & HOST_RESET)          printf_nts(" resetting");
+        ntprintf(" -");
+        if (val & HOST_AHCI_EN)        ntprintf(" ahci_enabled");
+        if (val & HOST_IRQ_EN)         ntprintf(" irq_enabled");
+        if (val & HOST_RESET)          ntprintf(" resetting");
 
       } else if (i == HOST_CAP2) {
-        printf_nts(" -");
-        if (val & HOST_CAP2_BOH)       printf_nts(" boh");
-        if (val & HOST_CAP2_NVMHCI)    printf_nts(" nvmhci");
-        if (val & HOST_CAP2_APST)      printf_nts(" apst");
+        ntprintf(" -");
+        if (val & HOST_CAP2_BOH)       ntprintf(" boh");
+        if (val & HOST_CAP2_NVMHCI)    ntprintf(" nvmhci");
+        if (val & HOST_CAP2_APST)      ntprintf(" apst");
       }
-      printf_nts("\n");
-    }
-  }
+      ntprintf("\n");
+    }
+  }
+  #endif
 
   /* Save working copies of CAP, CAP2 and port_map and remove broken feature
@@ -337,9 +339,4 @@
       }
     }
-
-    /* Wait some time to give the COMRESET a chance to complete (usually, at
-     * least hard disks complete the reset within a few milliseonds)
-     */
-    msleep(20);
   }
 
@@ -456,60 +453,4 @@
 }
 
-int ahci_reset_controller(AD_INFO *ai)
-{
-    u32 tmp;
-    TIMER Timer;
-
-    dprintf("controller reset starting on adapter %d\n", ad_no(ai));
-    /* we must be in AHCI mode, before using anything
-     * AHCI-specific, such as HOST_RESET.
-     */
-    ahci_enable_ahci(ai);
-
-    /* global controller reset */
-    tmp = readl(ai->mmio + HOST_CTL);
-    if ((tmp & HOST_RESET) == 0) {
-        writel(ai->mmio + HOST_CTL, tmp | HOST_RESET);
-        readl(ai->mmio + HOST_CTL); /* flush */
-    }
-
-    /*
-     * to perform host reset, OS should set HOST_RESET
-     * and poll until this bit is read to be "0".
-     * reset must complete within 1 second, or
-     * the hardware should be considered fried.
-     */
-    timer_init(&Timer, 1000);
-    while (((tmp = readl(ai->mmio + HOST_CTL)) & HOST_RESET) != 0) {
-      if (timer_check_and_block(&Timer)) {
-        dprintf("controller reset failed (0x%lx)\n", tmp);
-        return(-1);
-      }
-    }
-
-    /* turn on AHCI mode */
-    ahci_enable_ahci(ai);
-
-    /* Some registers might be cleared on reset.  Restore
-     * initial values.
-     */
-    ahci_restore_initial_config(ai);
-
-    if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
-      u32 tmp16 = 0;
-
-      ddprintf("ahci_reset_controller: intel detected\n");
-      /* configure PCS */
-      pci_read_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16);
-      if ((tmp16 & ai->port_map) != ai->port_map) {
-        ddprintf("ahci_reset_controller: updating PCS %x/%x\n", (u16)tmp16, ai->port_map);
-        tmp16 |= ai->port_map;
-        pci_write_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16);
-      }
-    }
-
-    return 0;
-}
-
 /******************************************************************************
  * Scan all ports for connected devices and fill in the corresponding device
@@ -547,6 +488,4 @@
     ahci_save_bios_config(ai);
   }
-
-  ahci_reset_controller(ai);
 
   if (ahci_enable_ahci(ai)) {
@@ -723,17 +662,17 @@
   dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
   if (debug > 1) {
-    printf(" PORT_CMD       = 0x%lx\n", readl(port_mmio + PORT_CMD));
-    printf("ahci_reset_port: command engine status:\n");
-    printf(" PORT_SCR_ACT   = 0x%lx\n", readl(port_mmio + PORT_SCR_ACT));
-    printf(" PORT_CMD_ISSUE = 0x%lx\n", readl(port_mmio + PORT_CMD_ISSUE));
-    printf("link/device status:\n");
-    printf(" PORT_SCR_STAT  = 0x%lx\n", readl(port_mmio + PORT_SCR_STAT));
-    printf(" PORT_SCR_CTL   = 0x%lx\n", readl(port_mmio + PORT_SCR_CTL));
-    printf(" PORT_SCR_ERR   = 0x%lx\n", readl(port_mmio + PORT_SCR_ERR));
-    printf(" PORT_TFDATA    = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
-    printf("interrupt status:\n");
-    printf(" PORT_IRQ_STAT  = 0x%lx\n", readl(port_mmio + PORT_IRQ_STAT));
-    printf(" PORT_IRQ_MASK  = 0x%lx\n", readl(port_mmio + PORT_IRQ_MASK));
-    printf(" HOST_IRQ_STAT  = 0x%lx\n", readl(ai->mmio + HOST_IRQ_STAT));
+    aprintf(" PORT_CMD       = 0x%lx\n", readl(port_mmio + PORT_CMD));
+    aprintf("ahci_reset_port: command engine status:\n");
+    aprintf(" PORT_SCR_ACT   = 0x%lx\n", readl(port_mmio + PORT_SCR_ACT));
+    aprintf(" PORT_CMD_ISSUE = 0x%lx\n", readl(port_mmio + PORT_CMD_ISSUE));
+    aprintf("link/device status:\n");
+    aprintf(" PORT_SCR_STAT  = 0x%lx\n", readl(port_mmio + PORT_SCR_STAT));
+    aprintf(" PORT_SCR_CTL   = 0x%lx\n", readl(port_mmio + PORT_SCR_CTL));
+    aprintf(" PORT_SCR_ERR   = 0x%lx\n", readl(port_mmio + PORT_SCR_ERR));
+    aprintf(" PORT_TFDATA    = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
+    aprintf("interrupt status:\n");
+    aprintf(" PORT_IRQ_STAT  = 0x%lx\n", readl(port_mmio + PORT_IRQ_STAT));
+    aprintf(" PORT_IRQ_MASK  = 0x%lx\n", readl(port_mmio + PORT_IRQ_MASK));
+    aprintf(" HOST_IRQ_STAT  = 0x%lx\n", readl(ai->mmio + HOST_IRQ_STAT));
   }
 
@@ -1565,7 +1504,8 @@
    */
   if (irq_stat & PORT_IRQ_UNK_FIS) {
+    #ifdef DEBUG
     u32 _far *unk = (u32 _far *) (port_dma_base(ai, p)->rx_fis + RX_FIS_UNK);
-    dprintf("warning: unknown FIS %08lx %08lx %08lx %08lx\n",
-            unk[0], unk[1], unk[2], unk[3]);
+    dprintf("warning: unknown FIS %08lx %08lx %08lx %08lx\n", unk[0], unk[1], unk[2], unk[3]);
+    #endif
     reset_port = 1;
   }
@@ -1688,7 +1628,9 @@
 void ahci_execute_ata(IORBH _far *iorb)
 {
+  #ifdef DEBUG
   int a = iorb_unit_adapter(iorb);
   int p = iorb_unit_port(iorb);
   int d = iorb_unit_device(iorb);
+  #endif
 
   dphex(((IORB_ADAPTER_PASSTHRU _far *) iorb)->pControllerCmd,
Index: trunk/src/os2ahci/apm.c
===================================================================
--- trunk/src/os2ahci/apm.c	(revision 159)
+++ trunk/src/os2ahci/apm.c	(revision 160)
@@ -77,5 +77,5 @@
     if (evt->ulParm2 >> 16 != APM_PWRSTATEREADY) {
       /* we're suspending */
-      apm_suspend();
+      suspend();
     }
     break;
@@ -84,5 +84,5 @@
   case APM_CRITRESUMEEVENT:
     /* we're resuming */
-    apm_resume();
+    resume();
     break;
 
@@ -96,8 +96,8 @@
 
 /******************************************************************************
- * APM suspend handler. In a nutshell, it'll turn of interrupts and flush all
+ * Suspend handler. In a nutshell, it'll turn off interrupts and flush all
  * write caches.
  */
-void apm_suspend(void)
+void suspend(void)
 {
   int a;
@@ -107,5 +107,5 @@
 
   if (suspended) return;
-  dprintf("apm_suspend()\n");
+  dprintf("suspend()\n");
 
   /* restart all ports with interrupts disabled */
@@ -132,4 +132,10 @@
       }
     }
+
+    /* AHCI spec rev1.1 section 8.3.3:
+     * Software must disable interrupts prior to requesting a transition of the HBA to D3 state.
+     */
+    writel(ai->mmio + HOST_CTL, readl(ai->mmio + HOST_CTL) & ~HOST_IRQ_EN);
+    readl(ai->mmio + HOST_CTL); /* flush */
   }
 
@@ -137,24 +143,29 @@
   init_complete = 0;
 
+#if 0
   /* restore BIOS configuration for each adapter and release the adapter */
   for (a = 0; a < ad_info_cnt; a++) {
     ahci_restore_bios_config(ad_infos + a);
-    unlock_adapter(ad_infos + a);
-  }
+  }
+#endif
+
+  /* TODO: put the device into the D3 state */
 
   suspended = 1;
-  dprintf("apm_suspend() finished\n");
-}
-
-/******************************************************************************
- * APM resume handler. All ports are restarted with interrupts enabled using
+  dprintf("suspend() finished\n");
+}
+
+/******************************************************************************
+ * Resume handler. All ports are restarted with interrupts enabled using
  * the same function as the IOCM_COMPLETE_INIT handler does.
  */
-void apm_resume(void)
+void resume(void)
 {
   int a;
 
   if (!suspended) return;
-  dprintf("apm_resume()\n");
+  dprintf("resume()\n");
+
+  /* TODO: put the device into the D0 state */
 
   for (a = 0; a < ad_info_cnt; a++) {
@@ -165,5 +176,4 @@
      * done to get the adapter and its ports up and running.
      */
-    lock_adapter(ai);
     ahci_complete_init(ai);
   }
@@ -178,4 +188,76 @@
 
   suspended = 0;
-  dprintf("apm_resume() finished\n");
-}
+  dprintf("resume() finished\n");
+}
+
+/******************************************************************************
+ * This is the kernel exit handler for panics and traps.
+ * Assume the system is trashed and do the absolute minimum necessary
+ * to put the adapters into a state so that the BIOS can operate the
+ * adapters. We never need to recover from this as the system will be rebooted.
+ */
+void shutdown_driver(void)
+{
+  int a;
+  int p;
+  u16 i;
+  u32 tmp;
+  //int d;
+
+  dprintf("shutdown_driver() enter\n");
+
+  for (a = 0; a < ad_info_cnt; a++) {
+    AD_INFO *ai = ad_infos + a;
+
+    /* Try to be nice. Wait 50ms for adapter to go not busy.
+     * If it doesn't go not busy in that time, too bad. Stop it anyway.
+     */
+    for (i=0; i<50000 && ai->busy; i++) udelay(1000);
+
+    for (p = 0; p <= ai->port_max; p++) {
+      u8 _far *port_mmio = port_base(ai, p);
+
+      /* Wait up to 50ms for port to go not busy. Again stop it
+       * anyway if it doesn't go not busy in that time.
+       */
+      for (i=0; i<50000 && ahci_port_busy(ai, p); i++) udelay(1000);
+
+      /* stop port */
+      writel(port_mmio + PORT_IRQ_MASK, 0); /* disable port interrupts */
+      writel(port_mmio + PORT_CMD, readl(port_mmio + PORT_CMD) & ~PORT_CMD_FIS_RX); /* disable FIS reception */
+      while (readl(port_mmio + PORT_CMD) & PORT_CMD_FIS_ON); /* wait for it to stop */
+      writel(port_mmio + PORT_CMD, readl(port_mmio + PORT_CMD) & ~PORT_CMD_START); /* set port to idle */
+      while (readl(port_mmio + PORT_CMD) & PORT_CMD_LIST_ON); /* wait for it to stop */
+
+      /* clear any pending port IRQs */
+      tmp = readl(port_mmio + PORT_IRQ_STAT);
+      if (tmp) writel(port_mmio + PORT_IRQ_STAT, tmp);
+      writel(ai->mmio + HOST_IRQ_STAT, 1UL << p);
+
+      /* reset PxSACT register (tagged command queues, not reset by COMRESET) */
+      writel(port_mmio + PORT_SCR_ACT, 0);
+      readl(port_mmio + PORT_SCR_ACT);  /* flush */
+
+      #if 0
+      ahci_start_port(ai, p, 0);
+
+      /* flush cache on all attached devices */
+      for (d = 0; d <= ai->ports[p].dev_max; d++) {
+        if (ai->ports[p].devs[d].present) {
+	  ahci_flush_cache(ai, p, d);
+	}
+      }
+      #endif
+    }
+  }
+
+  init_complete = 0;
+
+  /* restore BIOS configuration for each adapter */
+  for (a = 0; a < ad_info_cnt; a++) {
+    ahci_restore_bios_config(ad_infos + a);
+  }
+
+  dprintf("shutdown_driver() finished\n");
+}
+
Index: trunk/src/os2ahci/ata.c
===================================================================
--- trunk/src/os2ahci/ata.c	(revision 159)
+++ trunk/src/os2ahci/ata.c	(revision 160)
@@ -277,5 +277,5 @@
 
   if (debug >= 2) {
-    printf("ATA command for %d.%d.%d, slot %d:\n", ad_no(ai), p, d, slot);
+    aprintf("ATA command for %d.%d.%d, slot %d:\n", ad_no(ai), p, d, slot);
     phex(cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), "cmd_hdr:   ");
     phex(&ata_cmd, sizeof(ata_cmd), "ata_cmd:   ");
@@ -480,7 +480,4 @@
 {
   GEOMETRY _far *geometry = ((IORB_GEOMETRY _far *) iorb)->pGeometry;
-  AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
-  int p = iorb_unit_port(iorb);
-  int d = iorb_unit_device(iorb);
   ULONG sector;
 
@@ -488,5 +485,10 @@
 
   if (use_lvm_info) {
+    #ifdef DEBUG
+    AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
+    int p = iorb_unit_port(iorb);
+    int d = iorb_unit_device(iorb);
     ddprintf("is_lvm_geometry (%d.%d.%d)\n", ad_no(ai), p, d);
+    #endif
 
     /* First check the sector reported by the hardware */
Index: trunk/src/os2ahci/init.asm
===================================================================
--- trunk/src/os2ahci/init.asm	(revision 159)
+++ trunk/src/os2ahci/init.asm	(revision 160)
@@ -109,5 +109,5 @@
                 EXTRN   _reset_ctxhook : NEAR     ; C reset context hook
                 EXTRN   _engine_ctxhook : NEAR    ; C engine context hook
-                EXTRN   _apm_suspend : NEAR       ; C routine for INT13 IO enable
+                EXTRN   _shutdown_driver : NEAR   ; C routine for INT13 IO enable
 _TEXT           ENDS
 
@@ -134,4 +134,5 @@
 TGROUP          GROUP   _TEXT, CODE, LIBCODE, RMCode, _z_text
 
+        .386
 
 ; ----------------------------------------------------------------------------
@@ -181,5 +182,4 @@
 ;  Kernel exit routine to enable INT13 I/O (called before a trap dump occurrs)
 _asm_krnl_exit  PROC    FAR
-
                 PUSH    ES
                 PUSH    DS
@@ -189,5 +189,5 @@
 
                 ;  call C routine
-                CALL    _apm_suspend
+                CALL    _shutdown_driver
 
                 POP     DS
@@ -469,6 +469,4 @@
 __I4D           endp
 
-                .286
-
 _TEXT           ENDS
 
Index: trunk/src/os2ahci/libc.c
===================================================================
--- trunk/src/os2ahci/libc.c	(revision 159)
+++ trunk/src/os2ahci/libc.c	(revision 160)
@@ -405,5 +405,5 @@
   if (debug) {
     /* print the same message to COM1/trace as well */
-    printf("%s", buf);
+    aprintf("%s", buf);
   }
 
@@ -436,21 +436,21 @@
   /* print hex block */
   while (len > 0) {
-    printf_nts("%Fp ", buf);
+    ntprintf("%Fp ", buf);
 
     /* print hex block */
     for (i = 0; i < 16; i++) {
       if (i < len) {
-        printf_nts("%c%02x", ((i == 8) ? '-' : ' '), buf[i]);
+        ntprintf("%c%02x", ((i == 8) ? '-' : ' '), buf[i]);
       } else {
-        printf_nts("   ");
+        ntprintf("   ");
       }
     }
 
     /* print ASCII block */
-    printf_nts("   ");
+    ntprintf("   ");
     for (i = 0; i < ((len > 16) ? 16 : len); i++) {
-      printf_nts("%c", (buf[i] >= 32 && buf[i] < 128) ? buf[i] : '.');
-    }
-    printf_nts("\n");
+      ntprintf("%c", (buf[i] >= 32 && buf[i] < 128) ? buf[i] : '.');
+    }
+    ntprintf("\n");
 
     buf += 16;
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 159)
+++ trunk/src/os2ahci/os2ahci.c	(revision 160)
@@ -408,6 +408,6 @@
   }
 
-  printf_nts("BldLevel: %s\n", BldLevel);
-  printf_nts("CmdLine: %Fs\n", cmd_line);
+  ntprintf("BldLevel: %s\n", BldLevel);
+  ntprintf("CmdLine: %Fs\n", cmd_line);
 
   /* scan PCI bus for supported devices */
@@ -489,27 +489,4 @@
     break;
 
-  case OS2AHCI_IDC_CATEGORY:
-    switch (ioctl->Function) {
-
-    case OS2AHCI_IDC_BIOSMODE:
-      /* reconfigure adapters in BIOS/int13 mode; needed for generating
-       * trap dumps on some machines. This was intended to be called by ACPI.PSD,
-       * but that is never done. This is obslete. The kernel exit accomplishes
-       * this instead.
-       *
-       * To enter BIOS mode, we flush all write caches, turn off interrupts
-       * and restore the BIOS configuration. This is exactly what
-       * apm_suspend() does.
-       */
-      apm_suspend();
-      return(STDON);
-
-    case OS2AHCI_IDC_BEEP:
-      /* IOCTL for IDC testing - just beep */
-      DevHelp_Beep(2000, 100);
-      return(STDON);
-    }
-    break;
-
   case DSKSP_CAT_GENERIC:
     return(ioctl_gen_dsk(ioctl));
@@ -552,5 +529,5 @@
   }
 
-  apm_suspend();
+  suspend();
   return(STDON);
 }
@@ -564,6 +541,6 @@
   dprintf("sr_drv(%d) called\n", func);
 
-  if (func) apm_resume();
-  else apm_suspend();
+  if (func) resume();
+  else suspend();
 
   return(STDON);
@@ -765,4 +742,5 @@
    * IORB.
    */
+  while (suspended) DevHelp_ProcBlock((ULONG)&send_iorb, 1, WAIT_IS_INTERRUPTABLE);
   add_workspace(iorb)->processing = 1;
   spin_unlock(drv_lock);
@@ -1263,5 +1241,5 @@
 
     if (debug > min_debug) {
-      printf("IORB %Fp queued (cmd = %d/%d, queue = %Fp [%s], timeout = %ld)\n",
+      aprintf("IORB %Fp queued (cmd = %d/%d, queue = %Fp [%s], timeout = %ld)\n",
              iorb, iorb->CommandCode, iorb->CommandModifier, queue, queue_type,
              iorb->Timeout);
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 159)
+++ trunk/src/os2ahci/os2ahci.h	(revision 160)
@@ -34,4 +34,5 @@
  */
 
+#define DEBUG
 #define INCL_NOPMAPI
 #define INCL_DOSINFOSEG
@@ -104,4 +105,5 @@
 
 /* debug output macros */
+#ifdef DEBUG
 #define dprintf   if (debug > 0) printf
 #define dphex     if (debug > 0) phex
@@ -110,4 +112,16 @@
 #define dddprintf if (debug > 2) printf
 #define dddphex   if (debug > 2) phex
+#define ntprintf printf_nts
+#define aprintf printf
+#else
+#define dprintf(a,...)
+#define dphex(a,b,c,...)
+#define ddprintf(a,...)
+#define ddphex(a,b,c,...)
+#define dddprintf(a,...)
+#define dddphex(a,b,c,...)
+#define ntprintf(a,...)
+#define aprintf(a,...)
+#endif
 
 /* verbosity console print macros
@@ -561,6 +575,6 @@
 /* apm.c */
 extern void        apm_init           (void);
-extern void        apm_suspend        (void);
-extern void        apm_resume         (void);
+extern void        suspend        (void);
+extern void        resume         (void);
 
 /* ioctl.c */
Index: trunk/src/os2ahci/trace.c
===================================================================
--- trunk/src/os2ahci/trace.c	(revision 159)
+++ trunk/src/os2ahci/trace.c	(revision 160)
@@ -235,5 +235,5 @@
     AD_INFO *ai = ad_infos + a;
 
-    printf_nts("Adapter %d: %d:%d:%d irq=%d addr=0x%lx\n", a,
+    ntprintf("Adapter %d: %d:%d:%d irq=%d addr=0x%lx\n", a,
       ai->bus, ai->dev_func>>3, ai->dev_func&7,
       ai->irq, ai->mmio_phys);
@@ -242,9 +242,9 @@
       P_INFO *pi = &ai->ports[p];
 
-      printf_nts("  Port %d:\n", p);
+      ntprintf("  Port %d:\n", p);
 
       for (d = 0; d <= pi->dev_max; d++) {
         if (!pi->devs[d].present) continue;
-        printf_nts("    Drive %d: atapi=%d, removable=%d\n", d, pi->devs[d].atapi, pi->devs[d].removable);
+        ntprintf("    Drive %d: atapi=%d, removable=%d\n", d, pi->devs[d].atapi, pi->devs[d].removable);
       }
     }
