#include #include #include #include #include #include #include "vxbDrv.h" LOCAL VXB_DEV_ID pSampleDev; LOCAL STATUS sampleProbe ( VXB_DEV_ID pDev ) { /* * Probe logic really depends on the device. */ if (strcmp (vxbDevNameGet (pDev), "sample") == 0) return (OK); return (ERROR); } LOCAL STATUS sampleAttach ( VXB_DEV_ID pDev ) { DRV_CTRL * pDrvCtrl; VXB_RESOURCE_ADR * pAdr; /* Initialize driver-specific context. */ pDrvCtrl = malloc (sizeof(DRV_CTRL)); vxbDevSoftcSet (pDev, pDrvCtrl); /* Allocate the register bank resource */ pDrvCtrl->pBarRes = vxbResourceAlloc (pDev, VXB_RES_MEMORY, 0); pAdr = pDrvCtrl->pBarRes->pRes; pDrvCtrl->pRegBase = (char *)pAdr->virtual; /* Allocate the interrupt resource */ pDrvCtrl->pIntRes = vxbResourceAlloc (pDev, VXB_RES_IRQ, 0); /* Save a handle to the device */ pSampleDev = pDev; return (OK); } LOCAL STATUS sampleShutdown ( VXB_DEV_ID pDev ) { return (OK); } LOCAL STATUS sampleDetach ( VXB_DEV_ID pDev ) { DRV_CTRL * pDrvCtrl; pDrvCtrl = vxbDevSoftcGet (pDev); vxbDevSoftcSet (pDev, NULL); /* Release the register bank resource */ vxbResourceFree (pDev, pDrvCtrl->pBarRes); /* Release the register bank resource */ vxbResourceFree (pDev, pDrvCtrl->pIntRes); /* Release the context */ free (pDrvCtrl); return (OK); } /* Sample implementation of intConnect/intDisconnect for this device */ void myIntConnect ( VOIDFUNCPTR myIsrFunc, void * myIsrArg ) { DRV_CTRL * pDrvCtrl; pDrvCtrl = vxbDevSoftcGet (pSampleDev); vxbIntConnect (pSampleDev, pDrvCtrl->pIntRes, myIsrFunc, myIsrArg); vxbIntEnable (pSampleDev, pDrvCtrl->pIntRes); return; } void myIntDisconnect (void) { DRV_CTRL * pDrvCtrl; pDrvCtrl = vxbDevSoftcGet (pSampleDev); vxbIntDisable (pSampleDev, pDrvCtrl->pIntRes); vxbIntDisconnect (pSampleDev, pDrvCtrl->pIntRes); return; } LOCAL VXB_DRV_METHOD sampleMethods[] = { /* DEVICE API */ { VXB_DEVMETHOD_CALL(vxbDevProbe), sampleProbe }, { VXB_DEVMETHOD_CALL(vxbDevAttach), sampleAttach }, { VXB_DEVMETHOD_CALL(vxbDevShutdown), sampleShutdown }, { VXB_DEVMETHOD_CALL(vxbDevDetach), sampleDetach }, { 0, NULL } }; /* * Note: the class should match the parent bus type, * e.g. VXB_BUSID_PCI, VXB_BUSID_FDT, etc... */ VXB_DRV vxbSampleDrv = { { NULL } , "sample", /* Name */ "Sample VxBus driver", /* Description */ VXB_BUSID_NEXUS, /* Class */ 0, /* Flags */ 0, /* Reference count */ sampleMethods /* Method table */ }; VXB_DRV_DEF(vxbSampleDrv);