Ejemplo n.º 1
0
/* ARGSUSED */
int
hubspc_open(devfs_handle_t *devp, mode_t oflag, int otyp, cred_t *crp)
{
        int errcode = 0;
        
        switch ((hubspc_subdevice_t)(ulong)device_info_get(*devp)) {
        case HUBSPC_REFCOUNTERS:
                errcode = mem_refcnt_open(devp, oflag, otyp, crp);
                break;

        case HUBSPC_PROM:
		/* Check if the user has proper access rights to 
		 * read/write the prom space.
		 */
                if (!cap_able(CAP_DEVICE_MGT)) {
                        errcode = EPERM;
                }                
                break;

        default:
                errcode = ENODEV;
        }

#ifdef	HUBSPC_DEBUG
	printf("hubspc_open: Completed open for type %d\n",
               (hubspc_subdevice_t)(ulong)device_info_get(*devp));
#endif	/* HUBSPC_DEBUG */

        return (errcode);
}
Ejemplo n.º 2
0
/*ARGSUSED*/
int
mem_refcnt_open(devfs_handle_t *devp, mode_t oflag, int otyp, cred_t *crp)
{
        cnodeid_t node;
#ifndef CONFIG_IA64_SGI_SN1
	extern int numnodes;
#endif
        
        ASSERT( (hubspc_subdevice_t)(ulong)device_info_get(*devp) == HUBSPC_REFCOUNTERS );

        if (!cap_able(CAP_MEMORY_MGT)) {
                return (EPERM);
        }

        node = master_node_get(*devp);

        ASSERT( (node >= 0) && (node < numnodes) );

        if (NODEPDA(node)->migr_refcnt_counterbuffer == NULL) {
                return (ENODEV);
        }

        ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
        ASSERT( NODEPDA(node)->migr_refcnt_cbsize != (size_t)0 );

        return (0);
}
Ejemplo n.º 3
0
Archivo: hubspc.c Proyecto: nhanh0/hah
/* ARGSUSED */
int
hubspc_map(devfs_handle_t dev, vhandl_t *vt, off_t off, size_t len, uint prot)
{
    /*REFERENCED*/
    hubspc_subdevice_t subdevice;
    int errcode = 0;

    /* check validity of request */
    if( len == 0 ) {
        return ENXIO;
    }

    subdevice = (hubspc_subdevice_t)(ulong)device_info_get(dev);

#ifdef	HUBSPC_DEBUG
    printf("hubspc_map: subdevice: %d vaddr: 0x%x phyaddr: 0x%x len: 0x%x\n",
           subdevice, v_getaddr(vt), off, len);
#endif /* HUBSPC_DEBUG */

    switch ((hubspc_subdevice_t)(ulong)device_info_get(dev)) {
    case HUBSPC_REFCOUNTERS:
        errcode = mem_refcnt_mmap(dev, vt, off, len, prot);
        break;

    case HUBSPC_PROM:
        errcode = cpuprom_map(dev, vt, off, len);
        break;
    default:
        errcode = ENODEV;
    }

#ifdef	HUBSPC_DEBUG
    printf("hubspc_map finished: spctype: %d vaddr: 0x%x len: 0x%x\n",
           (hubspc_subdevice_t)(ulong)device_info_get(dev), v_getaddr(vt), len);
#endif /* HUBSPC_DEBUG */

    return errcode;
}
Ejemplo n.º 4
0
Archivo: hubspc.c Proyecto: nhanh0/hah
/* ARGSUSED */
int
hubspc_close(devfs_handle_t dev, int oflag, int otyp, cred_t *crp)
{
    int errcode = 0;

    switch ((hubspc_subdevice_t)(ulong)device_info_get(dev)) {
    case HUBSPC_REFCOUNTERS:
        errcode = mem_refcnt_close(dev, oflag, otyp, crp);
        break;

    case HUBSPC_PROM:
        break;
    default:
        errcode = ENODEV;
    }

#ifdef	HUBSPC_DEBUG
    printf("hubspc_close: Completed close for type %d\n",
           (hubspc_subdevice_t)(ulong)device_info_get(dev));
#endif	/* HUBSPC_DEBUG */

    return (errcode);
}
Ejemplo n.º 5
0
/*ARGSUSED*/
int
mem_refcnt_mmap(devfs_handle_t dev, vhandl_t *vt, off_t off, size_t len, uint prot)
{
        cnodeid_t node;
        int errcode;
        char* buffer;
        size_t blen;
#ifndef CONFIG_IA64_SGI_SN1
	extern int numnodes;
#endif
        
        ASSERT( (hubspc_subdevice_t)(ulong)device_info_get(dev) == HUBSPC_REFCOUNTERS );

        node = master_node_get(dev);

        ASSERT( (node >= 0) && (node < numnodes) );

        ASSERT( NODEPDA(node)->migr_refcnt_counterbuffer != NULL);
        ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
        ASSERT( NODEPDA(node)->migr_refcnt_cbsize != 0 );

        /*
         * XXXX deal with prot's somewhere around here....
         */

        buffer = NODEPDA(node)->migr_refcnt_counterbuffer;
        blen = NODEPDA(node)->migr_refcnt_cbsize;

        /*
         * Force offset to be a multiple of sizeof(refcnt_t)
         * We round up.
         */

        off = (((off - 1)/sizeof(refcnt_t)) + 1) * sizeof(refcnt_t);

        if ( ((buffer + blen) - (buffer + off + len)) < 0 ) {
                return (EPERM);
        }

        errcode = v_mapphys(vt,
                            buffer + off,
                            len);

        return errcode;
}
Ejemplo n.º 6
0
Archivo: hubspc.c Proyecto: nhanh0/hah
/* ARGSUSED */
int
hubspc_unmap(devfs_handle_t dev, vhandl_t *vt)
{
    int errcode = 0;

    switch ((hubspc_subdevice_t)(ulong)device_info_get(dev)) {
    case HUBSPC_REFCOUNTERS:
        errcode = mem_refcnt_unmap(dev, vt);
        break;

    case HUBSPC_PROM:
        errcode = cpuprom_unmap(dev, vt);
        break;

    default:
        errcode = ENODEV;
    }
    return errcode;

}
Ejemplo n.º 7
0
Archivo: hubspc.c Proyecto: nhanh0/hah
/* ARGSUSED */
int
hubspc_ioctl(devfs_handle_t dev,
             int cmd,
             void *arg,
             int mode,
             cred_t *cred_p,
             int *rvalp)
{
    int errcode = 0;

    switch ((hubspc_subdevice_t)(ulong)device_info_get(dev)) {
    case HUBSPC_REFCOUNTERS:
        errcode = mem_refcnt_ioctl(dev, cmd, arg, mode, cred_p, rvalp);
        break;

    case HUBSPC_PROM:
        break;

    default:
        errcode = ENODEV;
    }
    return errcode;

}
Ejemplo n.º 8
0
static ambit_device_info_t * ambit_device_info_new(const struct hid_device_info *dev)
{
    ambit_device_info_t *device = NULL;
    const ambit_known_device_t *known_device = NULL;

    const char *dev_path;

    uint16_t vid;
    uint16_t pid;

    hid_device *hid;

    if (!dev || !dev->path) {
        LOG_ERROR("internal error: expecting hidraw device");
        return NULL;
    }

    dev_path = dev->path;
    vid = dev->vendor_id;
    pid = dev->product_id;

    if (!libambit_device_support_known(vid, pid)) {
        LOG_INFO("ignoring unknown device (VID/PID: %04x/%04x)", vid, pid);
        return NULL;
    }

    dev_path = strdup(dev_path);
    if (!dev_path) return NULL;

    device = calloc(1, sizeof(*device));
    if (!device) {
        free ((char *) dev_path);
        return NULL;
    }

    device->path = dev_path;
    device->vendor_id  = vid;
    device->product_id = pid;

    {                           /* create name for display purposes */
        char *vendor  = utf8wcsconv(dev->manufacturer_string);
        char *product = utf8wcsconv(dev->product_string);
        if (vendor && product) {
            char *name = (char *)malloc((strlen(vendor) + 1
                                         + strlen(product) + 1)
                                        * sizeof(char));
            if (name) {
                strcpy(name, vendor);
                strcat(name, " ");
                strcat(name, product);
                free(vendor);
                free(product);
                device->name = name;
            }
            else {
                device->name = product;
                if (vendor) free(vendor);
            }
        }
        else {
            device->name = product;
            if (vendor) free(vendor);
        }
        device->serial = utf8wcsconv(dev->serial_number);
    }

    LOG_INFO("HID  : %s: '%s' (serial: %s, VID/PID: %04x/%04x)",
             device->path, device->name, device->serial,
             device->vendor_id, device->product_id);

    hid = hid_open_path(device->path);
    if (hid) {
        /* HACK ALERT: minimally initialize an ambit object so we can
         * call device_info_get().  Note that this function sets the
         * device's model and serial string fields.  Above the latter
         * has been set already using the HID information.
         */
        char *serial = device->serial;
        ambit_object_t obj;
        obj.handle = hid;
        obj.sequence_no = 0;
        if (0 == device_info_get(&obj, device)) {

            if (!device->serial) { /* fall back to HID information */
                device->serial = serial;
            }
            else {
                if (serial && 0 != strcmp(device->serial, serial)) {
                  LOG_INFO("preferring F/W serial number over HID '%s'",
                           serial);
                }
                if (serial) free(serial);
            }

            known_device = libambit_device_support_find(device->vendor_id, device->product_id, device->model, device->fw_version);
            if (known_device != NULL) {
                device->is_supported = known_device->supported;
                if (device->name && known_device->name
                    && 0 != strcmp(device->name, known_device->name)) {
                    char *name = strdup(known_device->name);
                    if (name) {
                        LOG_INFO("preferring known name over HID '%s'",
                                 device->name);
                        free(device->name);
                        device->name = name;
                    }
                }
            }

#ifdef DEBUG_PRINT_INFO
            {
                char fw_version[LIBAMBIT_VERSION_LENGTH+1];
                char hw_version[LIBAMBIT_VERSION_LENGTH+1];
                version_string(fw_version, device->fw_version);
                version_string(hw_version, device->hw_version);

                LOG_INFO("Ambit: %s: '%s' (serial: %s, VID/PID: %04x/%04x, "
                         "nick: %s, F/W: %s, H/W: %s, supported: %s)",
                         device->path, device->name, device->serial,
                         device->vendor_id, device->product_id,
                         device->model, fw_version, hw_version,
                         (device->is_supported ? "YES" : "NO"));
            }
#endif
        }
        else {
            LOG_ERROR("cannot get device info from %s", device->path);
        }
        hid_close(hid);
    }
    else {
        /* Store an educated guess as to why we cannot open the HID
         * device.  Without read/write access we cannot communicate
         * to begin with but there may be other reasons.
         */
        int fd = open(device->path, O_RDWR);

        if (-1 == fd) {
            device->access_status = errno;
            LOG_ERROR("cannot open HID device (%s): %s", device->path,
                      strerror (device->access_status));
        }
        else {
            LOG_WARNING("have read/write access to %s but cannot open HID "
                        "device", device->path);
            close(fd);
        }
    }

    return device;
}
Ejemplo n.º 9
0
/* ARGSUSED */
int
mem_refcnt_ioctl(devfs_handle_t dev,
                 int cmd,
                 void *arg,
                 int mode,
                 cred_t *cred_p,
                 int *rvalp)
{
        cnodeid_t node;
        int errcode;
	extern int numnodes;
        
        ASSERT( (hubspc_subdevice_t)(ulong)device_info_get(dev) == HUBSPC_REFCOUNTERS );

        node = master_node_get(dev);

        ASSERT( (node >= 0) && (node < numnodes) );

        ASSERT( NODEPDA(node)->migr_refcnt_counterbuffer != NULL);
        ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
        ASSERT( NODEPDA(node)->migr_refcnt_cbsize != 0 );

        errcode = 0;
        
        switch (cmd) {
        case RCB_INFO_GET:
        {
                rcb_info_t rcb;
                
                rcb.rcb_len = NODEPDA(node)->migr_refcnt_cbsize;
                
                rcb.rcb_sw_sets = NODEPDA(node)->migr_refcnt_numsets;
                rcb.rcb_sw_counters_per_set = numnodes;
                rcb.rcb_sw_counter_size = sizeof(refcnt_t);

                rcb.rcb_base_pages = NODEPDA(node)->migr_refcnt_numsets /
                                     NUM_OF_HW_PAGES_PER_SW_PAGE();  
                rcb.rcb_base_page_size = NBPP;
                rcb.rcb_base_paddr = ctob(slot_getbasepfn(node, 0));
                
                rcb.rcb_cnodeid = node;
                rcb.rcb_granularity = MD_PAGE_SIZE;
#ifdef notyet
                rcb.rcb_hw_counter_max = MIGR_COUNTER_MAX_GET(node);
                rcb.rcb_diff_threshold = MIGR_THRESHOLD_DIFF_GET(node);
#endif
                rcb.rcb_abs_threshold = MIGR_THRESHOLD_ABS_GET(node);
                rcb.rcb_num_slots = node_getnumslots(node);

                if (COPYOUT(&rcb, arg, sizeof(rcb_info_t))) {
                        errcode = EFAULT;
                }

                break;
        }
        case RCB_SLOT_GET:
        {
                rcb_slot_t slot[MAX_MEM_SLOTS];
                int s;
                int nslots;

                nslots = node_getnumslots(node);
                ASSERT(nslots <= MAX_MEM_SLOTS);
                for (s = 0; s < nslots; s++) {
                        slot[s].base = (uint64_t)ctob(slot_getbasepfn(node, s));
#ifdef notyet
                        slot[s].size  = (uint64_t)ctob(slot_getsize(node, s));
#else
                        slot[s].size  = (uint64_t)1;
#endif
                }
                if (COPYOUT(&slot[0], arg, nslots * sizeof(rcb_slot_t))) {
                        errcode = EFAULT;
                }
                
                *rvalp = nslots;
                break;
        }
                
        default:
                errcode = EINVAL;
                break;

        }
        
        return errcode;
}