static int cmp_devs(const void *ap, const void *bp) { const struct dev *a = ap, *b = bp; uint64_t cmp_a = get_pci_addr(a->pci_dev); uint64_t cmp_b = get_pci_addr(b->pci_dev); if (cmp_a < cmp_b) { return -1; } else if (cmp_a > cmp_b) { return 1; } else { return 0; } }
static struct dev * get_controller(void) { unsigned int domain; unsigned int bus; unsigned int devid; unsigned int function; uint64_t pci_addr; char address[64]; char *p; int ch; struct dev *iter; const struct spdk_nvme_ctrlr_data *cdata; memset(address, 0, sizeof(address)); foreach_dev(iter) { display_controller(iter, CONTROLLER_DISPLAY_SIMPLISTIC); } printf("Please Input PCI Address(domain:bus:dev.func): \n"); while ((ch = getchar()) != '\n' && ch != EOF); p = fgets(address, 64, stdin); if (p == NULL) { return NULL; } while (isspace(*p)) { p++; } if (sscanf(p, "%x:%x:%x.%x", &domain, &bus, &devid, &function) == 4) { /* Matched a full address - all variables are initialized */ } else if (sscanf(p, "%x:%x:%x", &domain, &bus, &devid) == 3) { function = 0; } else if (sscanf(p, "%x:%x.%x", &bus, &devid, &function) == 3) { domain = 0; } else if (sscanf(p, "%x:%x", &bus, &devid) == 2) { domain = 0; function = 0; } else { return NULL; } pci_addr = (uint64_t)domain << 24; pci_addr |= (uint64_t)bus << 16; pci_addr |= (uint64_t)devid << 8; pci_addr |= (uint64_t)function; foreach_dev(iter) { if (pci_addr == get_pci_addr(iter->pci_dev)) { cdata = spdk_nvme_ctrlr_get_data(iter->ctrlr); iter->cdata = cdata; return iter; } } return NULL; }
static void mdlStart(SimStruct *S) { #ifndef MATLAB_MEX_FILE unsigned int base_adc, base_status, base_pci; unsigned int addr_mat[5]; int_T num_channels = ssGetOutputPortWidth(S,0); get_pci_addr(PCI_VENDOR_ID_CBOARDS,0x0F,addr_mat); base_pci = addr_mat[0]; base_status = addr_mat[1]; base_adc = addr_mat[2]; outw(((num_channels-1)<<4) | 0x0400,base_status+0x02); outw(0x0000,base_adc+0x02); cal_ad(base_pci,base_status); ssSetIWorkValue(S,BASE_ADDR_I_IND,(int_T) base_adc); ssSetIWorkValue(S,BASE_ADDR_I_IND+1,(int_T) base_status); #endif }
static void mdlStart(SimStruct *S) { #ifndef MATLAB_MEX_FILE unsigned int base_dio, base_status, base_pci; int_T control, port; unsigned int addr_mat[5]; port=(int_T) mxGetPr(PORT_ARG)[PORT_IND]; get_pci_addr(PCI_VENDOR_ID_CBOARDS,0x0F,addr_mat); base_pci = addr_mat[0]; base_status = addr_mat[1]; base_dio = addr_mat[3]; control=inb(base_dio+0x07); port=(int_T) mxGetPr(PORT_ARG)[PORT_IND]; switch(port){ case 1: dio_control |=0x10; control=0x80 | dio_control; outb(control, base_dio+0x07); ssSetIWorkValue(S,OUTPORT_I_IND,0x04); break; case 2: dio_control |=0x02; control=0x80 | dio_control; outb(control, base_dio+0x07); ssSetIWorkValue(S,OUTPORT_I_IND,0x05); break; } ssSetIWorkValue(S,BASE_ADDR_I_IND,(int_T) base_dio); #endif }