Example #1
0
int run_test(ssize_t f, char c) {
  int exit = 0;
  switch(c) {
    case 'q':
    case 'Q':
      exit = 1;
      break;
    case 'i':
    case 'I':
      printf ("Vendor id = 0x%x, Device id = 0x%x\n", 
              get_vendor_id(f), get_device_id(f));
      print_pid();
      break;
    case 'h':
    case 'H':
      print_help();
      break;
    case '1':
      test_auto_discovery_read(f);
      break;
    case '2':
      test_global_mem_write (f);
      break;
    case '3':
      test_dma_writes(f);
      break;
    default:
      printf("Invalid selection (%c).\n", c);
      exit = 1;
      break;
  }
  return exit;
}
Example #2
0
static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
{
	int res;
	unsigned short vid, pid;
	char transport[32];

	buf[0] = '\0';

	res = get_string_property_utf8(
		device, CFSTR(kIOHIDTransportKey),
		transport, sizeof(transport));
	
	if (!res)
		return -1;

	vid = get_vendor_id(device);
	pid = get_product_id(device);

	res = snprintf(buf, len, "%s_%04hx_%04hx_%p",
	                   transport, vid, pid, device);
	
	
	buf[len-1] = '\0';
	return res+1;
}
Example #3
0
void blass()
        {
            char vendorID[ 13 ];
            memset( vendorID, 0, 13 );
            get_vendor_id( vendorID );
            std::cout << "Vendor ID: " << vendorID << std::endl;
        }
Example #4
0
File: pci.c Project: eparodi/NEOS
void
print_all_devices(){
  int i,j,size;
  uint16_t vendorID;
  uint16_t deviceID;
  uint16_t hType;
  uint32_t data;
  char aux[30];
  for ( i = 0 ; i <= 0xFF ; i++ ){
    for ( j = 0 ; j <= 0xFF ; j++ ){ // j+= 0x08
      vendorID = get_vendor_id(i, j);
      if (vendorID != 0xFFFF){
        size = parse_int(aux,i,10);
        aux[size] = 0;
        print_string("Bus:",0xffffff);
        print_string(aux,0xffffff);
        print_string(",",0xffffff);
        size = parse_int(aux,j>>3,10);
        aux[size] = 0;
        print_string("Device:",0xffffff);
        print_string(aux,0xffffff);
        print_string(",",0xffffff);
        size = parse_int(aux,j&0x7,10);
        aux[size] = 0;
        print_string("Function:",0xffffff);
        print_string(aux,0xffffff);
        print_string(":",0xffffff);
        size = parse_int(aux,vendorID,16);
        aux[size] = 0;
        print_string(" VendorID: 0x",0xffffff);
        print_string(aux,0xffffff);
        deviceID = get_devide_id(i, j);
        size = parse_int(aux,deviceID,16);
        aux[size] = 0;
        print_string(", DeviceID: 0x",0xffffff);
        print_string(aux,0xffffff);
        hType = get_header_type(i,j);
        size = parse_int(aux,hType,16);
        aux[size] = 0;
        print_string(", HeaderType: 0x",0xffffff);
        print_string(aux,0xffffff);
        data = _pci_read_reg(i,j,0x04);
        size = parse_int(aux,data,16);
        aux[size] = 0;
        print_string(", DATA: 0x",0xffffff);
        print_string(aux,0xffffff);
        print_string("\n",0xffffff);
      }
    }
  }
Example #5
0
int main()
{
    std::cout << maxofthree(  1, -4, -7 ) << std::endl;
    std::cout << maxofthree(  2, -6,  1 ) << std::endl;
    std::cout << maxofthree(  2,  3,  1 ) << std::endl;
    std::cout << maxofthree( -2,  4,  3 ) << std::endl;
    std::cout << maxofthree(  2, -6,  5 ) << std::endl;
    std::cout << maxofthree(  2,  4,  6 ) << std::endl;
    
    char vendorID[ 20 ];
    memset( vendorID, 0, 20 );
    get_vendor_id( vendorID );
    std::cout << "Vendor ID: " << vendorID << std::endl;
    
    return 0;
}
Example #6
0
static void scan_device(uint8_t bus, uint8_t dev)
{
    for (uint8_t func = 0; func < 8; ++func) {
        uint16_t vendor_id = get_vendor_id(bus, dev, func);

        if (vendor_id != 0xFFFF) {
            uint32_t device_id = get_device_id(bus, dev, func);
            uint32_t class_code = get_class_code(bus, dev, func);
            uint32_t subclass_code = get_subclass_code(bus, dev, func);

            printk("Bus: %d, Device: %d, Function %d\n", bus, dev, func);
            printk("  -> Vendor ID: %x, Device ID: %x, Class: %x, Subclass: %x\n", vendor_id, device_id, class_code, subclass_code);
            //printk("  -> Vednor: %s\n", get_vendor_name(vendor_id));
            //printk("  -> Device: %s\n", get_device_name(vendor_id, device_id));
        }
    }
}
Example #7
0
int main(void)
{
	IOHIDManagerRef mgr;
	int i;

	mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
	IOHIDManagerSetDeviceMatching(mgr, NULL);
	IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone);

	CFSetRef device_set = IOHIDManagerCopyDevices(mgr);
    if (device_set==NULL) {
        return 0;
    }

	CFIndex num_devices = CFSetGetCount(device_set);
	IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
	CFSetGetValues(device_set, (const void **) device_array);

	for (i = 0; i < num_devices; i++) {
		IOHIDDeviceRef dev = device_array[i];
		printf("Device: %p\n", dev);
		printf("  %04hx %04hx\n", get_vendor_id(dev), get_product_id(dev));

		wchar_t serial[256], buf[256];
		char cbuf[256];
		get_serial_number(dev, serial, 256);


		printf("  Serial: %ls\n", serial);
		printf("  Loc: %ld\n", get_location_id(dev));
		get_transport(dev, buf, 256);
		printf("  Trans: %ls\n", buf);
		make_path(dev, cbuf, 256);
		printf("  Path: %s\n", cbuf);

	}

	return 0;
}
Example #8
0
int main() {
  ssize_t f = open ("/dev/de4", O_RDWR);
  if (f == -1) {
    printf ("Couldn't open the device. Did you load the driver?\n");
    return 0;
  } else {
    printf ("Opened the device: file handle #%zu!\n", f);
  }

  printf ("Vendor id = 0x%x, Device id = 0x%x\n", 
          get_vendor_id(f), get_device_id(f));
    
  print_pid();
  
  test_global_mem_write(f);
  
  int i;
  /* Change upper limit to a larger number (e.g. 1000) for stress testing */
  for (i = 0; i < 1; i++) {
    printf ("-- %d --\n", i);
     
   test_auto_discovery_read (f);
   test_small_writes (f);
   test_global_mem(f);
   // test_large_read_write (f);
   // test_reprogram(f);
   test_dma_writes(f);
   // test_cvp(f);
  }

  test_global_mem_write(f);
 
  printf ("Done testing!\n");
  
  close (f);
  return 0;
}
Example #9
0
int pci_device_scan(uint16_t vendor_id, uint16_t device_id, struct pci_dev *ref)
{
    /* TODO cache bus entries */
    uint8_t bus = 0;
    for (uint8_t dev = 0; dev < 32; ++dev) {
        for (uint8_t func = 0; func < 8; ++func) {
            uint16_t _vendor_id = get_vendor_id(bus, dev, func);
            if (_vendor_id != 0xFFFF) {
                uint16_t _device_id = get_device_id(bus, dev, func);
                if (_vendor_id == vendor_id && _device_id == device_id) {
                    if (ref) {
                        ref->bus = bus;
                        ref->dev = dev;
                        ref->func = func;
                    }

                    return 0;
                }
            }
        }
    }

    return -1;
}
Example #10
0
struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
	struct hid_device_info *root = NULL; // return object
	struct hid_device_info *cur_dev = NULL;
	CFIndex num_devices;
	int i;
	
	setlocale(LC_ALL,"");

	/* Set up the HID Manager if it hasn't been done */
	hid_init();
	
	/* Get a list of the Devices */
	CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);

	/* Convert the list into a C array so we can iterate easily. */	
	num_devices = CFSetGetCount(device_set);
	IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
	CFSetGetValues(device_set, (const void **) device_array);

	/* Iterate over each device, making an entry for it. */	
	for (i = 0; i < num_devices; i++) {
		unsigned short dev_vid;
		unsigned short dev_pid;
		#define BUF_LEN 256
		wchar_t buf[BUF_LEN];
		char cbuf[BUF_LEN];

		IOHIDDeviceRef dev = device_array[i];

        if (!dev) {
            continue;
        }
		dev_vid = get_vendor_id(dev);
		dev_pid = get_product_id(dev);

		/* Check the VID/PID against the arguments */
		if ((vendor_id == 0x0 && product_id == 0x0) ||
		    (vendor_id == dev_vid && product_id == dev_pid)) {
			struct hid_device_info *tmp;
			size_t len;

		    	/* VID/PID match. Create the record. */
			tmp = malloc(sizeof(struct hid_device_info));
			if (cur_dev) {
				cur_dev->next = tmp;
			}
			else {
				root = tmp;
			}
			cur_dev = tmp;

			// Get the Usage Page and Usage for this device.
			cur_dev->usage_page = get_int_property(dev, CFSTR(kIOHIDPrimaryUsagePageKey));
			cur_dev->usage = get_int_property(dev, CFSTR(kIOHIDPrimaryUsageKey));

			/* Fill out the record */
			cur_dev->next = NULL;
			len = make_path(dev, cbuf, sizeof(cbuf));
			cur_dev->path = strdup(cbuf);

			/* Serial Number */
			get_serial_number(dev, buf, BUF_LEN);
			cur_dev->serial_number = dup_wcs(buf);

			/* Manufacturer and Product strings */
			get_manufacturer_string(dev, buf, BUF_LEN);
			cur_dev->manufacturer_string = dup_wcs(buf);
			get_product_string(dev, buf, BUF_LEN);
			cur_dev->product_string = dup_wcs(buf);
			
			/* VID/PID */
			cur_dev->vendor_id = dev_vid;
			cur_dev->product_id = dev_pid;

			/* Release Number */
			cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));

			/* Interface Number (Unsupported on Mac)*/
			cur_dev->interface_number = -1;
		}
	}
	
	free(device_array);
	CFRelease(device_set);
	
	return root;
}
Example #11
0
File: hid.c Project: billsq/hidapi
struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
	struct hid_device_info *root = NULL; /* return object */
	struct hid_device_info *cur_dev = NULL;
	CFIndex num_devices;
	int i;

	/* Set up the HID Manager if it hasn't been done */
	if (hid_init() < 0)
		return NULL;

	/* give the IOHIDManager a chance to update itself */
	process_pending_events();

	/* Get a list of the Devices */
	IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
	CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);

	/* Convert the list into a C array so we can iterate easily. */
	num_devices = CFSetGetCount(device_set);
	IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
	CFSetGetValues(device_set, (const void **) device_array);

	/* Iterate over each device, making an entry for it. */
	for (i = 0; i < num_devices; i++) {
		unsigned short dev_vid;
		unsigned short dev_pid;
		#define BUF_LEN 256
		wchar_t buf[BUF_LEN];

		IOHIDDeviceRef dev = device_array[i];

        if (!dev) {
            continue;
        }
		dev_vid = get_vendor_id(dev);
		dev_pid = get_product_id(dev);

		/* Check the VID/PID against the arguments */
		if ((vendor_id == 0x0 || vendor_id == dev_vid) &&
		    (product_id == 0x0 || product_id == dev_pid)) {
			struct hid_device_info *tmp;
			io_object_t iokit_dev;
			kern_return_t res;
			io_string_t path;

			/* VID/PID match. Create the record. */
			tmp = malloc(sizeof(struct hid_device_info));
			if (cur_dev) {
				cur_dev->next = tmp;
			}
			else {
				root = tmp;
			}
			cur_dev = tmp;

			/* Get the Usage Page and Usage for this device. */
			cur_dev->usage_page = get_int_property(dev, CFSTR(kIOHIDPrimaryUsagePageKey));
			cur_dev->usage = get_int_property(dev, CFSTR(kIOHIDPrimaryUsageKey));

			/* Fill out the record */
			cur_dev->next = NULL;

			/* Fill in the path (IOService plane) */
			iokit_dev = hidapi_IOHIDDeviceGetService(dev);
			res = IORegistryEntryGetPath(iokit_dev, kIOServicePlane, path);
			if (res == KERN_SUCCESS)
				cur_dev->path = strdup(path);
			else
				cur_dev->path = strdup("");

			/* Serial Number */
			get_serial_number(dev, buf, BUF_LEN);
			cur_dev->serial_number = dup_wcs(buf);

			/* Manufacturer and Product strings */
			get_manufacturer_string(dev, buf, BUF_LEN);
			cur_dev->manufacturer_string = dup_wcs(buf);
			get_product_string(dev, buf, BUF_LEN);
			cur_dev->product_string = dup_wcs(buf);

			/* VID/PID */
			cur_dev->vendor_id = dev_vid;
			cur_dev->product_id = dev_pid;

			/* Release Number */
			cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));

			/* Interface Number (Unsupported on Mac)*/
			cur_dev->interface_number = -1;
		}
	}

	free(device_array);
	CFRelease(device_set);

	return root;
}
Example #12
0
CK_RV parse_readers(ykpiv_state *state, const CK_BYTE_PTR readers, const CK_ULONG len,
                    ykcs11_slot_t *slots, CK_ULONG_PTR n_slots, CK_ULONG_PTR n_with_token) {

    CK_BYTE        i;
    CK_BYTE_PTR    p;
    CK_BYTE_PTR    s;
    CK_ULONG       l;
    slot_vendor_t  slot;

    *n_slots = 0;
    *n_with_token = 0;
    p = readers;

    /*
     * According to pcsc-lite, the format of a reader name is:
     * name [interface] (serial) index slot
     * http://ludovicrousseau.blogspot.se/2010/05/what-is-in-pcsc-reader-name.html
     */

    for (i = 0; i < len; i++)
        if (readers[i] == '\0' && i != len - 1) {
            slots[*n_slots].vid = get_vendor_id(p);

            if (slots[*n_slots].vid == UNKNOWN) { // TODO: distinguish between tokenless and unsupported?
                // Unknown slot, just save what info we have
                memset(&slots[*n_slots].info, 0, sizeof(CK_SLOT_INFO));
                memset(slots[*n_slots].info.slotDescription, ' ', sizeof(slots[*n_slots].info.slotDescription));
                if (strlen(p) <= sizeof(slots[*n_slots].info.slotDescription))
                    strncpy(slots[*n_slots].info.slotDescription, p, strlen(p));
                else
                    strncpy(slots[*n_slots].info.slotDescription, p, sizeof(slots[*n_slots].info.slotDescription));
            }
            else {
                // Supported slot
                slot = get_slot_vendor(slots[*n_slots].vid);

                // Values must NOT be null terminated and ' ' padded

                memset(slots[*n_slots].info.slotDescription, ' ', sizeof(slots[*n_slots].info.slotDescription));
                s = slots[*n_slots].info.slotDescription;
                l = sizeof(slots[*n_slots].info.slotDescription);
                strncpy((char *)s, (char*)p, l);

                memset(slots[*n_slots].info.manufacturerID, ' ', sizeof(slots[*n_slots].info.manufacturerID));
                s = slots[*n_slots].info.manufacturerID;
                l = sizeof(slots[*n_slots].info.manufacturerID);
                if(slot.get_slot_manufacturer(s, l) != CKR_OK)
                    goto failure;

                if (slot.get_slot_flags(&slots[*n_slots].info.flags) != CKR_OK)
                    goto failure;

                // Treating hw and fw version the same
                if (slot.get_slot_version(&slots[*n_slots].info.hardwareVersion) != CKR_OK)
                    goto failure;

                if (slot.get_slot_version(&slots[*n_slots].info.firmwareVersion) != CKR_OK)
                    goto failure;

                if (has_token(slots + *n_slots)) {
                    // Save token information
                    (*n_with_token)++;

                    if (create_token(state, p, slots + *n_slots) != CKR_OK)
                        goto failure;
                }
            }
            (*n_slots)++;
            p += i + 1;
        }

    return CKR_OK;

failure:
    // TODO: destroy all token objects
    for (i = 0; i < *n_slots; i++)
        if (has_token(slots + i))
            destroy_token(slots + i);

    return CKR_FUNCTION_FAILED;
}
Example #13
0
//! This function is documented in the header file
void findGpus(gmx_gpu_info_t *gpu_info)
{
    cl_uint         ocl_platform_count;
    cl_platform_id *ocl_platform_ids;
    cl_device_type  req_dev_type = CL_DEVICE_TYPE_GPU;

    ocl_platform_ids = nullptr;

    if (getenv("GMX_OCL_FORCE_CPU") != nullptr)
    {
        req_dev_type = CL_DEVICE_TYPE_CPU;
    }

    while (true)
    {
        cl_int status = clGetPlatformIDs(0, nullptr, &ocl_platform_count);
        if (CL_SUCCESS != status)
        {
            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %d was returned from clGetPlatformIDs: ",
                                                           status) + ocl_get_error_string(status)));
        }

        if (1 > ocl_platform_count)
        {
            // TODO this should have a descriptive error message that we only support one OpenCL platform
            break;
        }

        snew(ocl_platform_ids, ocl_platform_count);

        status = clGetPlatformIDs(ocl_platform_count, ocl_platform_ids, nullptr);
        if (CL_SUCCESS != status)
        {
            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %d was returned from clGetPlatformIDs: ",
                                                           status) + ocl_get_error_string(status)));
        }

        for (unsigned int i = 0; i < ocl_platform_count; i++)
        {
            cl_uint ocl_device_count;

            /* If requesting req_dev_type devices fails, just go to the next platform */
            if (CL_SUCCESS != clGetDeviceIDs(ocl_platform_ids[i], req_dev_type, 0, nullptr, &ocl_device_count))
            {
                continue;
            }

            if (1 <= ocl_device_count)
            {
                gpu_info->n_dev += ocl_device_count;
            }
        }

        if (1 > gpu_info->n_dev)
        {
            break;
        }

        snew(gpu_info->gpu_dev, gpu_info->n_dev);

        {
            int           device_index;
            cl_device_id *ocl_device_ids;

            snew(ocl_device_ids, gpu_info->n_dev);
            device_index = 0;

            for (unsigned int i = 0; i < ocl_platform_count; i++)
            {
                cl_uint ocl_device_count;

                /* If requesting req_dev_type devices fails, just go to the next platform */
                if (CL_SUCCESS != clGetDeviceIDs(ocl_platform_ids[i], req_dev_type, gpu_info->n_dev, ocl_device_ids, &ocl_device_count))
                {
                    continue;
                }

                if (1 > ocl_device_count)
                {
                    break;
                }

                for (unsigned int j = 0; j < ocl_device_count; j++)
                {
                    gpu_info->gpu_dev[device_index].ocl_gpu_id.ocl_platform_id = ocl_platform_ids[i];
                    gpu_info->gpu_dev[device_index].ocl_gpu_id.ocl_device_id   = ocl_device_ids[j];

                    gpu_info->gpu_dev[device_index].device_name[0] = 0;
                    clGetDeviceInfo(ocl_device_ids[j], CL_DEVICE_NAME, sizeof(gpu_info->gpu_dev[device_index].device_name), gpu_info->gpu_dev[device_index].device_name, nullptr);

                    gpu_info->gpu_dev[device_index].device_version[0] = 0;
                    clGetDeviceInfo(ocl_device_ids[j], CL_DEVICE_VERSION, sizeof(gpu_info->gpu_dev[device_index].device_version), gpu_info->gpu_dev[device_index].device_version, nullptr);

                    gpu_info->gpu_dev[device_index].device_vendor[0] = 0;
                    clGetDeviceInfo(ocl_device_ids[j], CL_DEVICE_VENDOR, sizeof(gpu_info->gpu_dev[device_index].device_vendor), gpu_info->gpu_dev[device_index].device_vendor, nullptr);

                    gpu_info->gpu_dev[device_index].compute_units = 0;
                    clGetDeviceInfo(ocl_device_ids[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(gpu_info->gpu_dev[device_index].compute_units), &(gpu_info->gpu_dev[device_index].compute_units), nullptr);

                    gpu_info->gpu_dev[device_index].adress_bits = 0;
                    clGetDeviceInfo(ocl_device_ids[j], CL_DEVICE_ADDRESS_BITS, sizeof(gpu_info->gpu_dev[device_index].adress_bits), &(gpu_info->gpu_dev[device_index].adress_bits), nullptr);

                    gpu_info->gpu_dev[device_index].vendor_e = get_vendor_id(gpu_info->gpu_dev[device_index].device_vendor);

                    gpu_info->gpu_dev[device_index].stat = is_gmx_supported_gpu_id(gpu_info->gpu_dev + device_index);

                    if (egpuCompatible == gpu_info->gpu_dev[device_index].stat)
                    {
                        gpu_info->n_dev_compatible++;
                    }

                    device_index++;
                }
            }

            gpu_info->n_dev = device_index;

            /* Dummy sort of devices -  AMD first, then NVIDIA, then Intel */
            // TODO: Sort devices based on performance.
            if (0 < gpu_info->n_dev)
            {
                int last = -1;
                for (int i = 0; i < gpu_info->n_dev; i++)
                {
                    if (OCL_VENDOR_AMD == gpu_info->gpu_dev[i].vendor_e)
                    {
                        last++;

                        if (last < i)
                        {
                            gmx_device_info_t ocl_gpu_info;
                            ocl_gpu_info            = gpu_info->gpu_dev[i];
                            gpu_info->gpu_dev[i]    = gpu_info->gpu_dev[last];
                            gpu_info->gpu_dev[last] = ocl_gpu_info;
                        }
                    }
                }

                /* if more than 1 device left to be sorted */
                if ((gpu_info->n_dev - 1 - last) > 1)
                {
                    for (int i = 0; i < gpu_info->n_dev; i++)
                    {
                        if (OCL_VENDOR_NVIDIA == gpu_info->gpu_dev[i].vendor_e)
                        {
                            last++;

                            if (last < i)
                            {
                                gmx_device_info_t ocl_gpu_info;
                                ocl_gpu_info            = gpu_info->gpu_dev[i];
                                gpu_info->gpu_dev[i]    = gpu_info->gpu_dev[last];
                                gpu_info->gpu_dev[last] = ocl_gpu_info;
                            }
                        }
                    }
                }
            }

            sfree(ocl_device_ids);
        }

        break;
    }

    sfree(ocl_platform_ids);
}
Example #14
0
File: main.c Project: vladsor/chaos
/*
 * ---===--- MAIN ---===---
 */
int main(int argc, char *argv[])
{
  int iofd;
  int ch;
  unsigned long fan1_info = 0;
  unsigned long fan2_info = 0;
  unsigned long fan3_info = 0;
  signed int system_temp = 0;
  double cpu1_temp = 0;
  double cpu2_temp = 0;
  char io_dev[FILENAME_MAX];

  strcpy(io_dev, "/dev/io");		// FreeBSD default

  /*
   * 'h' and '?' are not listed, to give an error message when used.
   */
  while ( (ch = getopt(argc, argv, "Adf:qt")) != -1 )
  {
    switch (ch)
    {
      case 'A':
        show_all_fans = 1;
        break;
      case 'd':
        debug = 1;
        break;
      case 'f':
        strcpy(io_dev, optarg);
        break;
      case 'q':
        quiet = 1;
        break;
      case 't':
        swap_cpu_temps = 1;
        break;
      case 'h':
      case '?':
      default:
        usage();
    }
  }
  argc -= optind;
  argv += optind;

  /*
   * Open /dev/io for inb() and outb() permissions.
   */
  if ( (iofd = open(io_dev, O_RDWR)) == -1 )
  {
    perror("open() failed");
    exit(1);
  }

  /*
   * Check to see if the vendor ID code returned from the chip matches
   * 0x5CA3 (Winbond chipset).
   */
  if ( (vendor_id = get_vendor_id()) != 0x5CA3 )
  {
    printf("You do not have a Winbond hardware monitoring chipset.\n");
    printf("Your vendor ID code is: 0x%4.4X\n", vendor_id);
    close(iofd);
    exit(1);
  }
  switch ( chip_id = get_chip_id() )
  {
    case 0x10:		strcpy(chip, "W83781D <untested>");	break;
    case 0x20:		strcpy(chip, "W83627HF <untested>");	break;
    case 0x30:		strcpy(chip, "W83782D");		break;
    case 0x40:		strcpy(chip, "W83783S <untested>");	break;
    default:		strcpy(chip, "(unknown)");		break;
  }

  if (!quiet)
  {
    printf("Winbond %s detected (vendor=0x%4.4X, chip=0x%2.2X)\n\n",
      chip, vendor_id, chip_id);
  }

  if (swap_cpu_temps)
  {
    /*
     * Swap CPU1 and CPU2 temperatures; the Abit BP6 has thermistors 1
     * and 2 reversed (hardware bug).
     */
    get_cpu_temperatures(&cpu2_temp, &cpu1_temp);
  }
  else
  {
    get_cpu_temperatures(&cpu1_temp, &cpu2_temp);
  }
  get_fan_statistics(&fan1_info, &fan2_info, &fan3_info);
  get_system_temperature(&system_temp);

  printf("System Temperature\t%3dF (%d.0C)\n",
	 C2F(system_temp), system_temp);
  printf("CPU1 Temperature\t%3dF (%3.01fC)\n",
	 C2F(cpu1_temp), cpu1_temp);
  printf("CPU2 Temperature\t%3dF (%3.01fC)\n",
	 C2F(cpu2_temp), cpu2_temp);
  if (show_all_fans == 1)
  {
    display_fan("FAN1", fan1_info);
    display_fan("FAN2", fan2_info);
    display_fan("FAN3", fan3_info);
  }
  else
  {
    if (fan1_info != 0)		display_fan("FAN1", fan1_info);
    if (fan2_info != 0)		display_fan("FAN2", fan2_info);
    if (fan3_info != 0)		display_fan("FAN3", fan3_info);
  }

  close(iofd);
  exit(0);
}