Exemplo n.º 1
0
static int initialize_device(struct usb_device *dev)
{
	libusb_device *newlib_dev = dev->dev;
	int num_configurations;
	size_t alloc_size;
	int r;
	int i;

	/* device descriptor is identical in both libs */
	r = libusb_get_device_descriptor(newlib_dev,
		(struct libusb_device_descriptor *) &dev->descriptor);
	if (r < 0) {
		usbi_err("error %d getting device descriptor", r);
		return compat_err(r);
	}

	num_configurations = dev->descriptor.bNumConfigurations;
	alloc_size = sizeof(struct usb_config_descriptor) * num_configurations;
	dev->config = malloc(alloc_size);
	if (!dev->config)
		return -ENOMEM;
	memset(dev->config, 0, alloc_size);

	/* even though structures are identical, we can't just use libusb-1.0's
	 * config descriptors because we have to store all configurations in
	 * a single flat memory area (libusb-1.0 provides separate allocations).
	 * we hand-copy libusb-1.0's descriptors into our own structures. */
	for (i = 0; i < num_configurations; i++) {
		struct libusb_config_descriptor *newlib_config;
		r = libusb_get_config_descriptor(newlib_dev, i, &newlib_config);
		if (r < 0) {
			clear_device(dev);
			free(dev->config);
			return compat_err(r);
		}
		r = copy_config_descriptor(dev->config + i, newlib_config);
		libusb_free_config_descriptor(newlib_config);
		if (r < 0) {
			clear_device(dev);
			free(dev->config);
			return r;
		}
	}

	/* libusb doesn't implement this and it doesn't seem that important. If
	 * someone asks for it, we can implement it in v1.1 or later. */
	dev->num_children = 0;
	dev->children = NULL;

	libusb_ref_device(newlib_dev);
	return 0;
}
Exemplo n.º 2
0
/* Print a statement for copying an array to or from the device,
 * or for initializing or clearing the device.
 * The statement identifier of a copying node is called
 * "to_device_<array name>" or "from_device_<array name>" and
 * its user pointer points to the gpu_array_info of the array
 * that needs to be copied.
 * The node for initializing the device is called "init_device".
 * The node for clearing the device is called "clear_device".
 *
 * Extract the array (if any) from the identifier and call
 * init_device, clear_device, copy_array_to_device or copy_array_from_device.
 */
static __isl_give isl_printer *print_device_node(__isl_take isl_printer *p,
	__isl_keep isl_ast_node *node, struct gpu_prog *prog)
{
	isl_ast_expr *expr, *arg;
	isl_id *id;
	const char *name;
	struct gpu_array_info *array;

	expr = isl_ast_node_user_get_expr(node);
	arg = isl_ast_expr_get_op_arg(expr, 0);
	id = isl_ast_expr_get_id(arg);
	name = isl_id_get_name(id);
	array = isl_id_get_user(id);
	isl_id_free(id);
	isl_ast_expr_free(arg);
	isl_ast_expr_free(expr);

	if (!name)
		return isl_printer_free(p);
	if (!strcmp(name, "init_device"))
		return init_device(p, prog);
	if (!strcmp(name, "clear_device"))
		return clear_device(p, prog);
	if (!array)
		return isl_printer_free(p);

	if (!prefixcmp(name, "to_device"))
		return copy_array_to_device(p, array);
	else
		return copy_array_from_device(p, array);
}
static void ilo_remove(struct pci_dev *pdev)
{
	int i, minor;
	struct ilo_hwinfo *ilo_hw = pci_get_drvdata(pdev);

	clear_device(ilo_hw);

	minor = MINOR(ilo_hw->cdev.dev);
	for (i = minor; i < minor + MAX_CCB; i++)
		device_destroy(ilo_class, MKDEV(ilo_major, i));

	cdev_del(&ilo_hw->cdev);
	ilo_disable_interrupts(ilo_hw);
	free_irq(pdev->irq, ilo_hw);
	ilo_unmap_device(pdev, ilo_hw);
	pci_release_regions(pdev);
	/*
	 * pci_disable_device(pdev) used to be here. But this PCI device has
	 * two functions with interrupt lines connected to a single pin. The
	 * other one is a USB host controller. So when we disable the PIN here
	 * e.g. by rmmod hpilo, the controller stops working. It is because
	 * the interrupt link is disabled in ACPI since it is not refcounted
	 * yet. See acpi_pci_link_free_irq called from acpi_pci_irq_disable.
	 */
	kfree(ilo_hw);
	ilo_hwdev[(minor / MAX_CCB)] = 0;
}
Exemplo n.º 4
0
static void ilo_remove(struct pci_dev *pdev)
{
	int i, minor;
	struct ilo_hwinfo *ilo_hw = pci_get_drvdata(pdev);

	clear_device(ilo_hw);

	minor = MINOR(ilo_hw->cdev.dev);
	for (i = minor; i < minor + MAX_CCB; i++)
		device_destroy(ilo_class, MKDEV(ilo_major, i));

	cdev_del(&ilo_hw->cdev);
	ilo_disable_interrupts(ilo_hw);
	free_irq(pdev->irq, ilo_hw);
	ilo_unmap_device(pdev, ilo_hw);
	pci_release_regions(pdev);
	pci_disable_device(pdev);
	kfree(ilo_hw);
	ilo_hwdev[(minor / MAX_CCB)] = 0;
}
Exemplo n.º 5
0
//
// Clean up the device then add it to the interrupt list and enable it.
//
void
ser_attach_intr(DEV_OMAP *dev) {
	uintptr_t	*port = dev->port;
	// interrupt sources except transmit and modem status interrupt
	unsigned	ier = OMAP_IER_RHR|OMAP_IER_LS;
	
	// According to the National bug sheet you must wait for the transmit
	// holding register to be empty.
	do {
	} while((read_omap(port[OMAP_UART_LSR]) & OMAP_LSR_TXRDY) == 0);

	clear_device(port);

	dev->iid = InterruptAttach(dev->intr, ser_intr, dev, 0, 0);

	// Enable modem status interrupt (default)
	if (!dev->no_msr_int) {
		ier |= OMAP_IER_MS;
	}
	// Enable interrupt sources.
	write_omap(port[OMAP_UART_IER], ier);
}
Exemplo n.º 6
0
PairGPUDeviceT::~PairGPUDevice() {
    clear_device();
}
static int __devinit ilo_probe(struct pci_dev *pdev,
			       const struct pci_device_id *ent)
{
	int devnum, minor, start, error;
	struct ilo_hwinfo *ilo_hw;

	/* find a free range for device files */
	for (devnum = 0; devnum < MAX_ILO_DEV; devnum++) {
		if (ilo_hwdev[devnum] == 0) {
			ilo_hwdev[devnum] = 1;
			break;
		}
	}

	if (devnum == MAX_ILO_DEV) {
		dev_err(&pdev->dev, "Error finding free device\n");
		return -ENODEV;
	}

	/* track global allocations for this device */
	error = -ENOMEM;
	ilo_hw = kzalloc(sizeof(*ilo_hw), GFP_KERNEL);
	if (!ilo_hw)
		goto out;

	ilo_hw->ilo_dev = pdev;
	spin_lock_init(&ilo_hw->alloc_lock);
	spin_lock_init(&ilo_hw->fifo_lock);
	spin_lock_init(&ilo_hw->open_lock);

	error = pci_enable_device(pdev);
	if (error)
		goto free;

	pci_set_master(pdev);

	error = pci_request_regions(pdev, ILO_NAME);
	if (error)
		goto disable;

	error = ilo_map_device(pdev, ilo_hw);
	if (error)
		goto free_regions;

	pci_set_drvdata(pdev, ilo_hw);
	clear_device(ilo_hw);

	error = request_irq(pdev->irq, ilo_isr, IRQF_SHARED, "hpilo", ilo_hw);
	if (error)
		goto unmap;

	ilo_enable_interrupts(ilo_hw);

	cdev_init(&ilo_hw->cdev, &ilo_fops);
	ilo_hw->cdev.owner = THIS_MODULE;
	start = devnum * MAX_CCB;
	error = cdev_add(&ilo_hw->cdev, MKDEV(ilo_major, start), MAX_CCB);
	if (error) {
		dev_err(&pdev->dev, "Could not add cdev\n");
		goto remove_isr;
	}

	for (minor = 0 ; minor < MAX_CCB; minor++) {
		struct device *dev;
		dev = device_create(ilo_class, &pdev->dev,
				    MKDEV(ilo_major, minor), NULL,
				    "hpilo!d%dccb%d", devnum, minor);
		if (IS_ERR(dev))
			dev_err(&pdev->dev, "Could not create files\n");
	}

	return 0;
remove_isr:
	ilo_disable_interrupts(ilo_hw);
	free_irq(pdev->irq, ilo_hw);
unmap:
	ilo_unmap_device(pdev, ilo_hw);
free_regions:
	pci_release_regions(pdev);
disable:
/*	pci_disable_device(pdev);  see comment in ilo_remove */
free:
	kfree(ilo_hw);
out:
	ilo_hwdev[devnum] = 0;
	return error;
}
Exemplo n.º 8
0
/* ----------------===============----------------------- */
int main(int argnum, char **argval) {

    HANDLE           PlxHandle[N_SURF+1] ;
    DEVICE_LOCATION  Device[N_SURF+1] ;
    PLX_INTR         PlxIntr, Plxstate ;
    RETURN_CODE      rc ;

    unsigned short  dataByte=0;//,d_out;
    unsigned short  evNo=0;
    unsigned short rawDataArray[N_SURF][N_CHN][N_SCA]; // Read only one chip per trigger. PM
    float calibDataArray[N_SURF][N_CHN][N_SCA]; 
    unsigned short data_scl[N_RF];
    unsigned short data_rfpw[N_RF];
    unsigned long numChipEvents[N_CHP];
    TURFIO_struct data_turf;
    int i, j, boardIndex, ftmo=0,tmo=0,doingEvent=0 ; 
    int numDevices, n_ev=0 ;
    float mean_dt=0;
    int testVal;
    char *outputDir ;
    int tmpGPIO;
    int selftrig=0;
    int value=0;

  
    printf(" Start dacSet program !!\n") ;


    if (verbose) printf("  size of buffer is %d bytes.\n", sizeof(dataByte)) ;

    // Initialize devices
    if ((numDevices = init_device(PlxHandle, Device)) < 0) {
	printf("Problem initializing devices\n");
	return 0 ;
    }
    for(i=0;i<4;i++) {  
	if (verbose)
	    printf("RJN: now, %.4x %.4x [%s - bus %.2x  slot %.2x]\n",
		   Device[i].DeviceId, Device[i].VendorId, Device[i].SerialNumber,
		   Device[i].BusNumber, Device[i].SlotNumber);
    }

    // Clear devices 
    clear_device(PlxHandle,numDevices);

    /* initialize interrupt structure. */
    memset(&PlxIntr, 0, sizeof(PLX_INTR)) ;
    memset(&Plxstate, 0, sizeof(PLX_INTR)) ;

    /* -----------
       despite of "Prog.Ref." manual description, IopToPciInt did not change 
       LINT select enable (level/edge trigger sw.) bits.   10-Nov-04
       ----------- */
    PlxIntr.IopToPciInt = 1 ;    /* LINT1 interrupt line */
    PlxIntr.IopToPciInt_2 = 1 ;  /* LINT2 interrupt line */
    PlxIntr.PciMainInt = 1 ;




    while ((doingEvent++ < n_ev) || (n_ev == 0)) { 
	
	
      setDAC(PlxHandle,numDevices,value);
      value++;


	if (selftrig){  /* --- send a trigger ---- */ 
	    printf(" try to trigger it locally.\n") ;
	    for(i=0;i<numDevices-1;++i)
		if (cntl_set_SURF(PlxHandle[i], LTrig) != ApiSuccess) 
		    printf("  failed to set LTrig flag on SURF %d.\n",i) ;
	}
	/* Wait for ready to read (Evt_F) */
	tmo=0;
	if(verbose) printf("Sitting here about to wait\n");
	/* RJN change PlxHandle[numDevices-2] to PlxHandle[0] */
	while (!((tmpGPIO=PlxRegisterRead(PlxHandle[0], PCI9030_GP_IO_CTRL, &rc)) & 0x800) &&
	       (selftrig?(++tmo<N_TMO):1)){
	    if(verbose>3) printf("SURF 1 GPIO: 0x%x %d\n",tmpGPIO,tmpGPIO);
	    if(selftrig) usleep(1000); /*RJN put it back in for selftrig */
	    usleep(1000); /*GV removed, RJN put it back in as it completely abuses the CPU*/
	}

	if (tmo == N_TMO){
	    printf(" Timed out (%d ms) while waiting for Evt_F flag in self trigger mode.\n", N_TMO) ;
	    continue;
	}

	if(verbose) printf("Triggered, event %d (by software counter).\n",doingEvent);

	//usleep (100) ;  /* I doubt Evt_f is issued in proper timing. SM */
    
	/* Loop over SURF boards and read out */
	for(boardIndex=0;boardIndex<numDevices-1;boardIndex++){
	    printf("What is boardIndex %d\n",boardIndex);
	    if(verbose)
		printf(" GPIO register contents SURF %d = %x\n",boardIndex,
		       PlxRegisterRead(PlxHandle[boardIndex], PCI9030_GP_IO_CTRL, &rc)) ; 
	    if(verbose)
		printf(" int reg contents SURF %d = %x\n",boardIndex,
		       PlxRegisterRead(PlxHandle[boardIndex], PCI9030_INT_CTRL_STAT, &rc)) ; 

	    // Readout event number
	    if (PlxBusIopRead(PlxHandle[boardIndex], IopSpace0, 0x0, TRUE, &dataByte, 2, BitSize16)
		!= ApiSuccess)
		printf("  failed to read event number on SURF %d\n", boardIndex) ;
	    if(verbose) printf("SURF %d, ID %d, event no %d\n",boardIndex,dataByte>>14,dataByte);
	    
	    if(boardIndex==0) evNo=dataByte;
	    if(cntl_set_SURF(PlxHandle[boardIndex],EvNoD)!=ApiSuccess)
		printf("Failed to set EvNoD on SURF %d\n",boardIndex);

	    // still too short!?!      usleep(1000000000); // wait a bit according to Jing

	    // Wait for Lab_F
	    ftmo=0;
	    if(verbose) printf("SURF %d, waiting for Lab_F\n",boardIndex);
	    testVal=PlxRegisterRead(PlxHandle[boardIndex], PCI9030_GP_IO_CTRL, &rc); 
	    while(!(testVal & 0x4000) &&
		  (++ftmo<N_FTMO)){
		/* 	  printf("testVal %x\n",testVal); */
		usleep(1); /* RJN/GV changed from usleep(1000) */
		testVal=PlxRegisterRead(PlxHandle[boardIndex], PCI9030_GP_IO_CTRL, &rc);
	    }
	
	    if (ftmo == N_FTMO){
		printf("No Lab_F flag for %d ms, bailing on the event\n",N_FTMO);
		continue;
	    }

	    if(cntl_set_SURF(PlxHandle[boardIndex],LabD)!=ApiSuccess)
		printf("Failed to set LabD on SURF %d\n",boardIndex);

	    // Read trigger scalars
	    for(i=0;i<N_RF;++i){
		if (PlxBusIopRead(PlxHandle[boardIndex], IopSpace0, 0x0, TRUE, &dataByte, 2, BitSize16)
		    != ApiSuccess)
		    printf("  failed to read IO. surf=%d, rf scl=%d\n", boardIndex, i) ;
		data_scl[i]=dataByte;
		if(verbose>2) 
		    printf("SURF %d, SCL %d: %d\n",boardIndex,i,dataByte);
	    }
      
	    if(cntl_set_SURF(PlxHandle[boardIndex],SclD)!=ApiSuccess)
		printf("Failed to set SclD on SURF %d\n",boardIndex);

	    // Read RF power 
	    for(i=0;i<N_RF;++i){
		if (PlxBusIopRead(PlxHandle[boardIndex], IopSpace0, 0x0, TRUE, &dataByte, 2, BitSize16)
		    != ApiSuccess)
		    printf("  failed to read IO. surf=%d, rf pw=%d\n", boardIndex, i) ;
		data_rfpw[i]=dataByte;
		if(verbose>2) 
		    printf("SURF %d, RF %d: %d\n",boardIndex,i,dataByte);
	    }
      
	    if(cntl_set_SURF(PlxHandle[boardIndex],RFpwD)!=ApiSuccess)
		printf("Failed to set RFpwD on SURF %d\n",boardIndex);



	}  /* this is closing for(numDevices) loop. */
	
	/* Readout TURFIO */
	boardIndex=numDevices-1;
	/* RJN Hack */
/*       boardIndex=1; */
      
	if(verbose) printf(" GPIO register contents TURFIO = %x\n",
			   PlxRegisterRead(PlxHandle[boardIndex], PCI9030_GP_IO_CTRL, &rc)) ; 
	if(verbose) printf(" int reg contents TURFIO = %x\n", 
			   PlxRegisterRead(PlxHandle[boardIndex], PCI9030_INT_CTRL_STAT, &rc)) ; 
	
	// Burn one TURFIO read
	if (PlxBusIopRead(PlxHandle[boardIndex], IopSpace0, 0x0, TRUE, &dataByte, 2, BitSize16)
	    != ApiSuccess)
	  printf("  failed to read TURF IO port. Burn read.\n");
	
	data_turf.interval=0;
	data_turf.time=10;
	data_turf.rawtrig=10;
	if(verbose) printf("TURF Handle number: %d\n",boardIndex);
	for (j=0 ; j<16 ; j++) { // Loop 16 times over return structure
	  for (i=0; i<16 ; i++) {
	    if (PlxBusIopRead(PlxHandle[boardIndex], IopSpace0, 0x0, TRUE, &dataByte, 2, BitSize16)
		!= ApiSuccess)
	      printf("  failed to read TURF IO port. loop %d, word %d.\n",j,i) ;
	    // Need to byteswap TURFIO words. This might get changed in hardware, so beware. PM 04/01/05
	    dataByte=byteswap_uh(dataByte);
	    if((verbose>2 && j==0) || verbose>3)
	      printf("TURFIO %d (%d): %hu\n",i,j,dataByte);
	    if(j==0){ //Interpret on the first pass only
	      switch(i){
	      case 0: data_turf.rawtrig=dataByte; break;
	      case 1: data_turf.L3Atrig=dataByte; break;
	      case 2: data_turf.pps1=dataByte; break;
	      case 3: data_turf.pps1+=dataByte*65536; break;
	      case 4: data_turf.time=dataByte; break;
	      case 5: data_turf.time+=dataByte*65536; break;
	      case 6: data_turf.interval=dataByte; break;
	      case 7: data_turf.interval+=dataByte*65536; break;
	      default: data_turf.rate[i/4-2][i%4]=dataByte; break;
	      }
	    }
	  }
	}
	if(verbose>2){
	  printf("raw: %hu\nL3A: %hu\n1PPS: %lu\ntime: %lu\nint: %lu\n",
		 data_turf.rawtrig,data_turf.L3Atrig,data_turf.pps1,data_turf.time,
		 data_turf.interval);
	  for(i=8;i<16;++i)
	    printf("Rate[%d][%d]=%d\n",i/4-2,i%4,data_turf.rate[i/4-2][i%4]);
	}
	
    
    if(verbose) printf("Done reading\n");
          mean_dt=mean_dt*(doingEvent-1)/doingEvent+(float)data_turf.interval/doingEvent;
      printf("Trig no: %hu, trig time: %lu, 1PPS: %lu, dt: %lu\n",data_turf.rawtrig,
	     data_turf.time,data_turf.pps1,data_turf.interval);
      printf("mean dt: %f\n",mean_dt);



	// Clear boards
	for(i=0;i<numDevices-1;++i)
	    if (cntl_set_SURF(PlxHandle[i], ClrEvt) != ApiSuccess)
		printf("  failed to send clear event pulse on SURF %d.\n",i) ;
    


    }  /* closing master while loop. */

    // Clean up
    for(i=0;i<numDevices;++i)  PlxPciDeviceClose(PlxHandle[i] );
  
    return 1 ;
}
Exemplo n.º 9
0
static void free_device(struct usb_device *dev)
{
	clear_device(dev);
	libusb_unref_device(dev->dev);
	free(dev);
}