Esempio n. 1
0
static ssize_t scanlog_read(struct file *file, char __user *buf,
			    size_t count, loff_t *ppos)
{
        struct inode * inode = file->f_dentry->d_inode;
	struct proc_dir_entry *dp;
	unsigned int *data;
	int status;
	unsigned long len, off;
	unsigned int wait_time;

        dp = PDE(inode);
 	data = (unsigned int *)dp->data;

	if (!data) {
		printk(KERN_ERR "scanlog: read failed no data\n");
		return -EIO;
	}

	if (count > RTAS_DATA_BUF_SIZE)
		count = RTAS_DATA_BUF_SIZE;

	if (count < 1024) {
		/* This is the min supported by this RTAS call.  Rather
		 * than do all the buffering we insist the user code handle
		 * larger reads.  As long as cp works... :)
		 */
		printk(KERN_ERR "scanlog: cannot perform a small read (%ld)\n", count);
		return -EINVAL;
	}

	if (!access_ok(VERIFY_WRITE, buf, count))
		return -EFAULT;

	for (;;) {
		wait_time = 500;	/* default wait if no data */
		spin_lock(&rtas_data_buf_lock);
		memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);
		status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,
				   (u32) __pa(rtas_data_buf), (u32) count);
		memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);
		spin_unlock(&rtas_data_buf_lock);

		DEBUG("status=%d, data[0]=%x, data[1]=%x, data[2]=%x\n",
		      status, data[0], data[1], data[2]);
		switch (status) {
		    case SCANLOG_COMPLETE:
			DEBUG("hit eof\n");
			return 0;
		    case SCANLOG_HWERROR:
			DEBUG("hardware error reading scan log data\n");
			return -EIO;
		    case SCANLOG_CONTINUE:
			/* We may or may not have data yet */
			len = data[1];
			off = data[2];
			if (len > 0) {
				if (copy_to_user(buf, ((char *)data)+off, len))
					return -EFAULT;
				return len;
			}
			/* Break to sleep default time */
			break;
		    default:
			if (status > 9900 && status <= 9905) {
				wait_time = rtas_extended_busy_delay_time(status);
			} else {
				printk(KERN_ERR "scanlog: unknown error from rtas: %d\n", status);
				return -EIO;
			}
		}
		/* Apparently no data yet.  Wait and try again. */
		msleep_interruptible(wait_time);
	}
	/*NOTREACHED*/
}
Esempio n. 2
0
static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
{
    return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
}
static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
{
	return single_open(file, acpi_processor_power_seq_show,
			   PDE(inode)->data);
}
Esempio n. 4
0
static int vlandev_seq_open(struct inode *inode, struct file *file)
{
	return single_open(file, vlandev_seq_show, PDE(inode)->data);
}
Esempio n. 5
0
File: fan.c Progetto: 274914765/C
static int acpi_fan_state_open_fs(struct inode *inode, struct file *file)
{
    return single_open(file, acpi_fan_read_state, PDE(inode)->data);
}
Esempio n. 6
0
static int fb_counter_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, fb_counter_proc_show, PDE(inode)->data);
}
Esempio n. 7
0
static int rpc_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, rpc_proc_show, PDE(inode)->data);
}
Esempio n. 8
0
/* Note: ignore ppos*/
ssize_t ambsync_proc_read(struct file *file, char __user *buf,
	size_t size, loff_t *ppos)
{
	int				retval = 0;
	struct ambsync_proc_pinfo	*pinfo = file->private_data;
	struct proc_dir_entry		*dp;
	struct ambsync_proc_hinfo	*hinfo;
	struct inode			*inode = file->f_path.dentry->d_inode;
	char				*start;
	int				len;
	size_t				count;

	dp = PDE(inode);
	hinfo = (struct ambsync_proc_hinfo *)dp->data;
	if (!hinfo) {
		retval = -EPERM;
		goto ambsync_proc_read_exit;
	}
	if (!hinfo->sync_read_proc) {
		retval = -EPERM;
		goto ambsync_proc_read_exit;
	}

	if (!pinfo) {
		retval = -ENOMEM;
		goto ambsync_proc_read_exit;
	}

	count = min_t(size_t, AMBA_SYNC_PROC_PAGE_SIZE, size);
	start = pinfo->page;
	len = 0;
	while (1) {
		wait_event_interruptible(hinfo->sync_proc_head,
			(atomic_read(&hinfo->sync_proc_flag) & pinfo->mask));
		atomic_clear_mask(pinfo->mask,
			(unsigned long *)&hinfo->sync_proc_flag);

		len = hinfo->sync_read_proc(start, hinfo->sync_read_data);
		if (len < count) {
			start += len;
			count -= len;
		} else if (len == count) {
			start += len;
			count -= len;
			break;
		} else {
			break;
		}
	}
	len = start - pinfo->page;
	if (len == 0) {
		retval = -EFAULT;
	} else {
		if (copy_to_user(buf, pinfo->page, len)) {
			retval = -EFAULT;
		} else {
			retval = len;
		}
	}

ambsync_proc_read_exit:
	return retval;
}
Esempio n. 9
0
int ambsync_proc_open(struct inode *inode, struct file *file)
{
	int				retval = 0;
	struct ambsync_proc_pinfo	*pinfo = file->private_data;
	struct proc_dir_entry		*dp;
	struct ambsync_proc_hinfo	*hinfo;
	int				id;

	dp = PDE(inode);
	hinfo = (struct ambsync_proc_hinfo *)dp->data;
	if (!hinfo) {
		retval = -EPERM;
		goto ambsync_proc_open_exit;
	}
	if (hinfo->maxid > AMBA_SYNC_PROC_MAX_ID) {
		retval = -EPERM;
		goto ambsync_proc_open_exit;
	}

	if (pinfo) {
		retval = -EPERM;
		goto ambsync_proc_open_exit;
	}
	pinfo = kmalloc(sizeof(*pinfo), GFP_KERNEL);
	if (!pinfo) {
		retval = -ENOMEM;
		goto ambsync_proc_open_exit;
	}
	memset(pinfo, 0, sizeof(*pinfo));

	if (idr_pre_get(&hinfo->sync_proc_idr, GFP_KERNEL) == 0) {
		retval = -ENOMEM;
		goto ambsync_proc_open_kfree_p;
	}
	mutex_lock(&hinfo->sync_proc_lock);
	retval = idr_get_new_above(&hinfo->sync_proc_idr, pinfo, 0, &id);
	mutex_unlock(&hinfo->sync_proc_lock);
	if (retval != 0)
		goto ambsync_proc_open_kfree_p;
	if (id > 31) {
		retval = -ENOMEM;
		goto ambsync_proc_open_remove_id;
	}

	if (!(pinfo->page = (char*) __get_free_page(GFP_KERNEL))) {
		retval = -ENOMEM;
		goto ambsync_proc_open_remove_id;
	}
	pinfo->id = id;
	pinfo->mask = (0x01 << id);

	file->private_data = pinfo;
	file->f_version = 0;
	file->f_mode &= ~FMODE_PWRITE;

	goto ambsync_proc_open_exit;

ambsync_proc_open_remove_id:
	mutex_lock(&hinfo->sync_proc_lock);
	idr_remove(&hinfo->sync_proc_idr, id);
	mutex_unlock(&hinfo->sync_proc_lock);

ambsync_proc_open_kfree_p:
	kfree(pinfo);

ambsync_proc_open_exit:
	return retval;
}
Esempio n. 10
0
File: stats.c Progetto: sderr/9pmod
static int stats_open(struct inode *inode, struct file *file)
{
	return single_open(file, stats_show, PDE(inode)->data);
}
Esempio n. 11
0
/*
 * dgrp_dpa_open -- open the DPA device for a particular PortServer
 */
static int dgrp_dpa_open(struct inode *inode, struct file *file)
{
	struct nd_struct *nd;
	int rtn = 0;

	struct proc_dir_entry *de;

	rtn = try_module_get(THIS_MODULE);
	if (!rtn)
		return -ENXIO;

	rtn = 0;

	if (!capable(CAP_SYS_ADMIN)) {
		rtn = -EPERM;
		goto done;
	}

	/*
	 *  Make sure that the "private_data" field hasn't already been used.
	 */
	if (file->private_data) {
		rtn = -EINVAL;
		goto done;
	}

	/*
	 *  Get the node pointer, and fail if it doesn't exist.
	 */
	de = PDE(inode);
	if (!de) {
		rtn = -ENXIO;
		goto done;
	}
	nd = (struct nd_struct *)de->data;
	if (!nd) {
		rtn = -ENXIO;
		goto done;
	}

	file->private_data = (void *) nd;

	/*
	 * Allocate the DPA buffer.
	 */

	if (nd->nd_dpa_buf) {
		rtn = -EBUSY;
	} else {
		nd->nd_dpa_buf = kmalloc(DPA_MAX, GFP_KERNEL);

		if (!nd->nd_dpa_buf) {
			rtn = -ENOMEM;
		} else {
			nd->nd_dpa_out = 0;
			nd->nd_dpa_in = 0;
			nd->nd_dpa_lbolt = jiffies;
		}
	}

done:

	if (rtn)
		module_put(THIS_MODULE);
	return rtn;
}
Esempio n. 12
0
static void walk_pagetable(uint64_t max_addr) {
    uint32_t pml4 = PML4(0);
    int dbg = 0;

    if (dbg) {
        printk("pml4pgs: %d\n", NUM_PML4PGS(max_addr));
        printk("pdppgs:  %d\n", NUM_PDPPGS(max_addr));
        printk("pdpgs:   %d\n", NUM_PDPGS(max_addr));
        printk("ptpgs:   %d\n", NUM_PTPGS(max_addr));
        
        printk("pml4(0) is at 0x%lx\n", PML4(0));
        printk("pml4e(0) is 0x%llx ", PT_ADDR(*(uint64_t *)pml4));
        printk("should be 0x%llx\n", PML4E(0));
    }
    assert(PT_ADDR(*(uint64_t *)pml4) == PML4E(0));

    uint64_t *pdp, *pd, *pt;
    size_t i, j, k;
    for (i = 0; i < NUM_ENTRIES; i++) {
        pdp = (uint64_t *)(PT_ADDR(*(uint64_t *)pml4)) + i;
        if (!(*pdp & 0x1))
            continue;

        if (dbg) {
            printk("PDP(%d) is at ", i);
            printk("0x%llx ", pdp);
            printk("should be 0x%llx\n", PDP(i));
        }
        assert((uint32_t)pdp == PDP(i));
        if (dbg) {
            printk("PDPE(%d) is at ", i);
            printk("0x%llx ", PT_ADDR(*pdp));
            printk("should be 0x%llx\n", PDPE(i));
        }
        assert(PT_ADDR(*pdp) == PDPE(i));

        for (j = 0; j < NUM_ENTRIES; j++) {
            pd = ((uint64_t *)PT_ADDR(*pdp)) + j; 
            if (!(*pd & 0x1))
                continue;
            size_t jdx = i * NUM_ENTRIES + j;
            if (dbg) {
                printk("PD(%d) is at ", jdx);
                printk("0x%llx ", pd);
                printk("should be 0x%llx\n", PD(jdx));
            }
            assert((uint32_t)pd == PD(jdx));
            if (dbg) {
                printk("PDE(%d) is at ", jdx);
                printk("0x%llx ", PT_ADDR(*pd));
                printk("should be 0x%llx\n", PDE(jdx));
            }
            assert(PT_ADDR(*pd) == PDE(jdx));

            for (k = 0; k < NUM_ENTRIES; k++) {
                pt = ((uint64_t *)PT_ADDR(*pd)) + k; 
                if (!(*pt & 0x1))
                    continue;
                size_t idx = jdx * NUM_ENTRIES + k;
                if (dbg) {
                    printk("PT(%d) is at ", idx);
                    printk("0x%llx ", pt);
                    printk("should be 0x%llx\n", PT(idx));
                }
                assert((uint32_t)pt == PT(idx));
                if (dbg) {
                    printk("PTE(%d) is at ", idx);
                    printk("0x%llx ", PT_ADDR(*pt));
                    printk("should be 0x%llx\n", PTE(idx));
                }
                assert(PT_ADDR(*pt) == PTE(idx));
            }
        }
    }
}
Esempio n. 13
0
struct net *get_proc_net(const struct inode *inode)
{
	return maybe_get_net(PDE_NET(PDE(inode)));
}
static int segment_info_open_fs(struct inode *inode, struct file *file)
{
	return single_open(file, segment_info_seq_show, PDE(inode)->data);
}
Esempio n. 15
0
static int
hysdn_conf_open(struct inode *ino, struct file *filep)
{
	hysdn_card *card;
	struct proc_dir_entry *pd;
	struct conf_writedata *cnf;
	char *cp, *tmp;

	/* now search the addressed card */
	lock_kernel();
	card = card_root;
	while (card) {
		pd = card->procconf;
		if (pd == PDE(ino))
			break;
		card = card->next;	/* search next entry */
	}
	if (!card) {
		unlock_kernel();
		return (-ENODEV);	/* device is unknown/invalid */
	}
	if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
		hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x",
			     filep->f_cred->fsuid, filep->f_cred->fsgid,
			     filep->f_mode);

	if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
		/* write only access -> write boot file or conf line */

		if (!(cnf = kmalloc(sizeof(struct conf_writedata), GFP_KERNEL))) {
			unlock_kernel();
			return (-EFAULT);
		}
		cnf->card = card;
		cnf->buf_size = 0;	/* nothing buffered */
		cnf->state = CONF_STATE_DETECT;		/* start auto detect */
		filep->private_data = cnf;

	} else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
		/* read access -> output card info data */

		if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) {
			unlock_kernel();
			return (-EFAULT);	/* out of memory */
		}
		filep->private_data = tmp;	/* start of string */

		/* first output a headline */
		sprintf(tmp, "id bus slot type irq iobase dp-mem     b-chans fax-chans state device");
		cp = tmp;	/* start of string */
		while (*cp)
			cp++;
		while (((cp - tmp) % (INFO_OUT_LEN + 1)) != INFO_OUT_LEN)
			*cp++ = ' ';
		*cp++ = '\n';

		/* and now the data */
		sprintf(cp, "%d  %3d %4d %4d %3d 0x%04x 0x%08lx %7d %9d %3d   %s",
			card->myid,
			card->bus,
			PCI_SLOT(card->devfn),
			card->brdtype,
			card->irq,
			card->iobase,
			card->membase,
			card->bchans,
			card->faxchans,
			card->state,
			hysdn_net_getname(card));
		while (*cp)
			cp++;
		while (((cp - tmp) % (INFO_OUT_LEN + 1)) != INFO_OUT_LEN)
			*cp++ = ' ';
		*cp++ = '\n';
		*cp = 0;	/* end of string */
	} else {		/* simultaneous read/write access forbidden ! */
		unlock_kernel();
		return (-EPERM);	/* no permission this time */
	}
	unlock_kernel();
	return nonseekable_open(ino, filep);
}				/* hysdn_conf_open */
Esempio n. 16
0
static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file)
{
	return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data);
}
static int zoran_open(struct inode *inode, struct file *file)
{
	struct zoran *data = PDE(inode)->data;
	return single_open(file, zoran_show, data);
}
Esempio n. 18
0
	pde->size = 4096;
	pde->proc_fops = &page_map_fops;

#ifdef CONFIG_PPC_PSERIES
	if ((systemcfg->platform & PLATFORM_PSERIES))
		proc_ppc64_create_ofdt();
#endif

	return 0;
}
__initcall(proc_ppc64_init);

static loff_t page_map_seek( struct file *file, loff_t off, int whence)
{
	loff_t new;
	struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);

	switch(whence) {
	case 0:
		new = off;
		break;
	case 1:
		new = file->f_pos + off;
		break;
	case 2:
		new = dp->size + off;
		break;
	default:
		return -EINVAL;
	}
	if ( new < 0 || new > dp->size )