#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/kmem.h>
#include <vm/seg_kmem.h>
#include <sys/async.h>
#include <sys/spl.h>
#include <sys/sunddi.h>
#include <sys/ddi_impldefs.h>
#include <sys/pci/pci_obj.h>
#include <sys/x_call.h>
void
sc_create(pci_t *pci_p)
{
dev_info_t *dip = pci_p->pci_dip;
sc_t *sc_p;
uint64_t paddr;
#ifdef lint
dip = dip;
#endif
if (!pci_stream_buf_exists)
return;
sc_p = (sc_t *)kmem_zalloc(sizeof (sc_t), KM_SLEEP);
pci_p->pci_sc_p = sc_p;
sc_p->sc_pci_p = pci_p;
pci_sc_setup(sc_p);
sc_p->sc_sync_reg_pa = va_to_pa((char *)sc_p->sc_sync_reg);
DEBUG3(DBG_ATTACH, dip, "sc_create: ctrl=%x, invl=%x, sync=%x\n",
sc_p->sc_ctrl_reg, sc_p->sc_invl_reg,
sc_p->sc_sync_reg);
DEBUG2(DBG_ATTACH, dip, "sc_create: ctx_invl=%x ctx_match=%x\n",
sc_p->sc_ctx_invl_reg, sc_p->sc_ctx_match_reg);
DEBUG3(DBG_ATTACH, dip,
"sc_create: data_diag=%x, tag_diag=%x, ltag_diag=%x\n",
sc_p->sc_data_diag_acc, sc_p->sc_tag_diag_acc,
sc_p->sc_ltag_diag_acc);
sc_p->sc_sync_flag_base =
vmem_xalloc(static_alloc_arena, PCI_SYNC_FLAG_SIZE,
PCI_SYNC_FLAG_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
sc_p->sc_sync_flag_vaddr = (uint64_t *)sc_p->sc_sync_flag_base;
paddr = (uint64_t)hat_getpfnum(kas.a_hat,
(caddr_t)sc_p->sc_sync_flag_vaddr);
paddr <<= MMU_PAGESHIFT;
paddr += (uint64_t)
((uintptr_t)sc_p->sc_sync_flag_vaddr & ~MMU_PAGEMASK);
sc_p->sc_sync_flag_pa = paddr;
DEBUG2(DBG_ATTACH, dip, "sc_create: sync buffer - vaddr=%x paddr=%x\n",
sc_p->sc_sync_flag_vaddr, sc_p->sc_sync_flag_pa);
mutex_init(&sc_p->sc_sync_mutex, NULL, MUTEX_DRIVER,
(void *)ipltospl(XCALL_PIL));
sc_configure(sc_p);
}
void
sc_destroy(pci_t *pci_p)
{
sc_t *sc_p;
if (!pci_stream_buf_exists)
return;
sc_p = pci_p->pci_sc_p;
DEBUG0(DBG_DETACH, pci_p->pci_dip, "sc_destroy:\n");
vmem_xfree(static_alloc_arena, sc_p->sc_sync_flag_base,
PCI_SYNC_FLAG_SIZE);
kmem_free(sc_p, sizeof (sc_t));
pci_p->pci_sc_p = NULL;
}
void
sc_configure(sc_t *sc_p)
{
int i, instance;
uint64_t l;
dev_info_t *dip;
if (!sc_p)
return;
dip = sc_p->sc_pci_p->pci_dip;
DEBUG0(DBG_ATTACH, dip, "sc_configure:\n");
*sc_p->sc_ctrl_reg |= COMMON_SC_CTRL_DIAG_ENABLE;
for (i = 0; i < PCI_SBUF_ENTRIES; i++) {
sc_p->sc_tag_diag_acc[i] = 0x0ull;
sc_p->sc_ltag_diag_acc[i] = 0x0ull;
}
l = 0;
instance = ddi_get_instance(dip);
if (pci_stream_buf_enable & (1 << instance))
l |= COMMON_SC_CTRL_ENABLE;
if (pci_rerun_disable & (1 << instance))
l |= COMMON_SC_CTRL_RR__DISABLE;
if (pci_lock_sbuf & (1 << instance))
l |= COMMON_SC_CTRL_LRU_LE;
l |= pci_sc_configure(sc_p->sc_pci_p);
DEBUG1(DBG_ATTACH, dip,
"sc_configure: writing %x to sc csr\n", l);
*sc_p->sc_ctrl_reg = l;
}