static int read_afu_info(struct pci_dev *dev, struct ocxl_fn_config *fn, int offset, u32 *data) { u32 val; unsigned long timeout = jiffies + (HZ * OCXL_CFG_TIMEOUT); int pos = fn->dvsec_afu_info_pos; /* Protect 'data valid' bit */ if (EXTRACT_BIT(offset, 31)) { dev_err(&dev->dev, "Invalid offset in AFU info DVSEC\n"); return -EINVAL; } pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, offset); pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, &val); while (!EXTRACT_BIT(val, 31)) { if (time_after_eq(jiffies, timeout)) { dev_err(&dev->dev, "Timeout while reading AFU info DVSEC (offset=%d)\n", offset); return -EBUSY; } cpu_relax(); pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, &val); } pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_DATA, data); return 0; }
static void SensorSlave() { SensorRequest_t t; int status, byte; unsigned int i, j, index, parent; volatile uint32_t sensors[TRAIN_SENSOR_COUNT * TRAIN_MODULE_COUNT] = {0}; parent = MyParentTid(); debug("SensorSlave: Tid %d", MyTid()); t.type = SENSOR_RETURNED; t.sensor = (uint32_t)sensors; while (true) { pollSensors(); for (i = 0; i < TRAIN_MODULE_COUNT; ++i) { index = i * TRAIN_SENSOR_COUNT; byte = trgetchar(); for (j = 0; j < TRAIN_SENSOR_COUNT / 2; ++j) { sensors[index++] = EXTRACT_BIT(byte, (TRAIN_SENSOR_COUNT / 2) - j - 1) & 1; } byte = trgetchar(); for (; j < TRAIN_SENSOR_COUNT; ++j) { sensors[index++] = EXTRACT_BIT(byte, TRAIN_SENSOR_COUNT - j - 1) & 1; } } Send(parent, &t, sizeof(t), &status, sizeof(status)); } Exit(); }
static int read_dvsec_function(struct pci_dev *dev, struct ocxl_fn_config *fn) { int pos, afu_present; u32 val; pos = find_dvsec(dev, OCXL_DVSEC_FUNC_ID); if (!pos) { dev_err(&dev->dev, "Can't find function DVSEC\n"); return -ENODEV; } fn->dvsec_function_pos = pos; pci_read_config_dword(dev, pos + OCXL_DVSEC_FUNC_OFF_INDEX, &val); afu_present = EXTRACT_BIT(val, 31); if (!afu_present) { fn->max_afu_index = -1; dev_dbg(&dev->dev, "Function doesn't define any AFU\n"); goto out; } fn->max_afu_index = EXTRACT_BITS(val, 24, 29); out: dev_dbg(&dev->dev, "Function DVSEC:\n"); dev_dbg(&dev->dev, " Max AFU index = %d\n", fn->max_afu_index); return 0; }
/* Function: check_circuit() * Purpose: Check if a given input produces TRUE (a one) * * In args: id, the process id * z, the current combination * out: 1, if the the input TRUE in the circuit * 0, else */ int check_circuit (int id, int z) { int v[16]; /* Each element is a bit of z */ int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i); if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3]) && (!v[3] || !v[4]) && (v[4] || !v[5]) && (v[5] || !v[6]) && (v[5] || v[6]) && (v[6] || !v[15]) && (v[7] || !v[8]) && (!v[7] || !v[13]) && (v[8] || v[9]) && (v[8] || !v[9]) && (!v[9] || !v[10]) && (v[9] || v[11]) && (v[10] || v[11]) && (v[12] || v[13]) && (v[13] || !v[14]) && (v[14] || v[15])) { #ifndef DEBUG printf ("%d) %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n", id, v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9], v[10],v[11],v[12],v[13],v[14],v[15]); fflush (stdout); #endif return 1; } else return 0; }
int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, int pasid) { u32 val; unsigned long timeout; pci_read_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, &val); if (EXTRACT_BIT(val, 20)) { dev_err(&dev->dev, "Can't terminate PASID %#x, previous termination didn't complete\n", pasid); return -EBUSY; } val &= ~OCXL_DVSEC_PASID_MASK; val |= pasid & OCXL_DVSEC_PASID_MASK; val |= BIT(20); pci_write_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, val); timeout = jiffies + (HZ * OCXL_CFG_TIMEOUT); pci_read_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, &val); while (EXTRACT_BIT(val, 20)) { if (time_after_eq(jiffies, timeout)) { dev_err(&dev->dev, "Timeout while waiting for AFU to terminate PASID %#x\n", pasid); return -EBUSY; } cpu_relax(); pci_read_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, &val); } return 0; }
int check_circuit (int id, int z) { int v[16]; /* Each element is a bit of z */ int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i); if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3]) && (!v[3] || !v[4]) && (v[4] || !v[5]) && (v[5] || !v[6]) && (v[5] || v[6]) && (v[6] || !v[15]) && (v[7] || !v[8]) && (!v[7] || !v[13]) && (v[8] || v[9]) && (v[8] || !v[9]) && (!v[9] || !v[10]) && (v[9] || v[11]) && (v[10] || v[11]) && (v[12] || v[13]) && (v[13] || !v[14]) && (v[14] || v[15])) { return 1; } else { return 0; } }
int handleInterrupt() { /* * Figures out the event corresponding to the mask, * and wakes all events in its bucket. * Does not return anything. */ int *vic1base, *vic2base; uint32_t vic1, vic2; int result = 0; char *buf; int buflen; InterruptType_t type = NUM_INTERRUPTS; Task_t *task = NULL; // TODO: refactor code using these ptrs vic1base = (int*) VIC1_BASE; vic2base = (int*) VIC2_BASE; vic1 = vic1base[VICxIRQStatus]; vic2 = vic2base[VICxIRQStatus]; // Stop complaints about unused variable (void)u1flag; if (EXTRACT_BIT(vic2, TIMER_INTERRUPT)) { type = CLOCK_INTERRUPT; task = interruptTable[CLOCK_INTERRUPT].blockedTask; if (!task) { kerror("FATAL: missed clock tick"); return -1; } *((uint32_t*)TIMER_CLEAR) = 0; result = 1; } else if (EXTRACT_BIT(vic2, UART1_INTERRUPT)) { if (*u1int & RIS_MASK) { type = UART1_RCV_INTERRUPT; task = interruptTable[type].blockedTask; if (task) { result = *u1data & DATA_MASK; } else { // TODO: no waiting task, should send stop control bit sys_log_f("Uart1 rcv interrupt missed\n"); *u1ctlr &= ~(RIEN_MASK); } } else if (*u1int & TIS_MASK) { type = UART1_XMT_INTERRUPT; *u1ctlr &= ~(TIEN_MASK); task = interruptTable[type].blockedTask; if (!task) { sys_log_f("uart1 xmt interrupt missed\n"); } result = 1; } else if (*u1int & MIS_MASK) { type = UART1_MOD_INTERRUPT; task = interruptTable[type].blockedTask; result = 1; if (task) { *u1int = 0; } else { // TODO: no waiting task, mask intr sys_log_f("Uart1 MOD interrupt missed\n"); *u1ctlr &= ~(MSIEN_MASK); } } } else if (EXTRACT_BIT(vic2, UART2_INTERRUPT)) { if (*u2int & (RIS_MASK | RTIS_MASK)) { type = UART2_RCV_INTERRUPT; task = interruptTable[type].blockedTask; if (task) { buf = interruptTable[type].buf; buflen = interruptTable[type].buflen; result = 0; while (!(*(u2flag) & RXFE_MASK) && buflen --> 0) { buf[result++] = *u2data & DATA_MASK; } } else { // TODO: no waiting task -> input is faster than we are reading // should mask interrupt, send stop bit to sender sys_log_f("uart2 rcv interrupt missed\n"); *u2ctlr &= ~(RIEN_MASK); } } else if (*u2int & TIS_MASK) { type = UART2_XMT_INTERRUPT; // disable xmit interrupt *u2ctlr &= ~(TIEN_MASK); task = interruptTable[type].blockedTask; if (!task) { sys_log_f("uart2 xmt interrupt missed\n"); } result = 1; } } if (task) { addTask(task); setResult(task, result); clearEntry(type); } return 0; }