/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
/* Handling of doorbell interrupt and related clean up */
#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>
#include "ehci.h"
#include "ehci_regs.h"

#include "ehci_core.h"

static IOSError
LOCK_DB(ehci_hcd *hcd)
{
    return IOS_ERROR_OK;
}

static IOSError
UNLOCK_DB(ehci_hcd *hcd)
{ 
    return IOS_ERROR_OK;
}

IOSError
enqueueDBCleanup(ehci_hcd *hcd, void *buf)
{
  IOSError rv = IOS_ERROR_OK;
  ehci_dbClean *list;
  ehci_dbClean *el = allocDBClean();
  if (NULL == el) {
      EHCI_ERR("%s: failed to allocate dbclean buffer\n", __FUNCTION__);
      rv = IOS_ERROR_MAX;
      goto done;
  }
  el->buf = buf;
  LOCK_DB(hcd);
  {
      list = hcd->db.hd;
      hcd->db.hd = el;
      el->nxt = list;
      EHCI_DBG("%s: enqueued: buf: %p el: %p\n", __FUNCTION__, buf, el);
  }
  UNLOCK_DB(hcd);

done:
  return rv;
}

IOSError
handleDBIntr(ehci_hcd *hcd)
{
    IOSError rv = IOS_ERROR_OK;
    LOCK_DB(hcd);
    {
       ehci_dbClean *curr;
       ehci_dbClean *tmp;
       curr = hcd->db.hd;
       while (curr != NULL) {
           tmp = curr;
           curr = curr->nxt;
           EHCI_DBG("%s: freeing buf: %p , el: %p\n", 
                   __FUNCTION__, tmp->buf, tmp);
           IOS_Free(__ehcdHeapId, tmp->buf);
           IOS_Free(__ehcdHeapId, tmp);
       }
       hcd->db.hd = NULL;
    }
    UNLOCK_DB(hcd);
    return rv;
}
