• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ register_chrdev函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中register_chrdev函数的典型用法代码示例。如果您正苦于以下问题:C++ register_chrdev函数的具体用法?C++ register_chrdev怎么用?C++ register_chrdev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了register_chrdev函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: drm_core_init

static int __init drm_core_init(void)
{
	int ret = -ENOMEM;

	drm_global_init();
	drm_connector_ida_init();
	idr_init(&drm_minors_idr);

	if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
		goto err_p1;

	drm_class = drm_sysfs_create(THIS_MODULE, "drm");
	if (IS_ERR(drm_class)) {
		printk(KERN_ERR "DRM: Error creating drm class.\n");
		ret = PTR_ERR(drm_class);
		goto err_p2;
	}

	drm_debugfs_root = debugfs_create_dir("dri", NULL);
	if (!drm_debugfs_root) {
		DRM_ERROR("Cannot create /sys/kernel/debug/dri\n");
		ret = -1;
		goto err_p3;
	}

	DRM_INFO("Initialized %s %d.%d.%d %s\n",
		 CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
	return 0;
err_p3:
	drm_sysfs_destroy();
err_p2:
	unregister_chrdev(DRM_MAJOR, "drm");

	idr_destroy(&drm_minors_idr);
err_p1:
	return ret;
}
开发者ID:uarka,项目名称:linux-next,代码行数:37,代码来源:drm_drv.c


示例2: init_module

int init_module(void)
{
    int result, i;

    /*
     * Register your major, and accept a dynamic number
     */
    result = register_chrdev(scullp_major, "scullp", &scullp_fops);
    if (result < 0) return result;
    if (scullp_major == 0) scullp_major = result; /* dynamic */

    /* 
     * allocate the devices -- we can't have them static, as the number
     * can be specified at load time
     */
    scullp_devices = kmalloc(scullp_devs * sizeof (ScullP_Dev), GFP_KERNEL);
    if (!scullp_devices) {
        result = -ENOMEM;
        goto fail_malloc;
    }
    memset(scullp_devices, 0, scullp_devs * sizeof (ScullP_Dev));
    for (i=0; i < scullp_devs; i++) {
        scullp_devices[i].order = scullp_order;
        scullp_devices[i].qset = scullp_qset;
        sema_init (&scullp_devices[i].sem, 1);
    }


#ifdef SCULLP_USE_PROC /* only when available */
    create_proc_read_entry("scullpmem", 0, NULL, scullp_read_procmem, NULL);
#endif
    return 0; /* succeed */

  fail_malloc:
    unregister_chrdev(scullp_major, "scullp");
    return result;
}
开发者ID:dot-Sean,项目名称:linux_drivers,代码行数:37,代码来源:main.c


示例3: msr_init

static int __init msr_init(void)
{
	int i, err = 0;
	i = 0;

	if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) {
		printk(KERN_ERR "msr: unable to get major %d for msr\n",
		       MSR_MAJOR);
		err = -EBUSY;
		goto out;
	}
	msr_class = class_create(THIS_MODULE, "msr");
	if (IS_ERR(msr_class)) {
		err = PTR_ERR(msr_class);
		goto out_chrdev;
	}
	msr_class->devnode = msr_devnode;
	for_each_online_cpu(i) {
		err = msr_device_create(i);
		if (err != 0)
			goto out_class;
	}
	register_hotcpu_notifier(&msr_class_cpu_notifier);

	err = 0;
	goto out;

out_class:
	i = 0;
	for_each_online_cpu(i)
		msr_device_destroy(i);
	class_destroy(msr_class);
out_chrdev:
	unregister_chrdev(MSR_MAJOR, "cpu/msr");
out:
	return err;
}
开发者ID:Aircell,项目名称:asp-kernel,代码行数:37,代码来源:msr.c


示例4: example_init

static __init int example_init(void)
{
		int result;

		/*
		 * Register your major, and accept a dynamic number
		 */
		result = register_chrdev(example_major, "example", &example_fops);
		if (result < 0) {
				printk(KERN_WARNING "example: can't get major %d\n",example_major);
				return result;
		}
		if (example_major == 0) example_major = result; /* dynamic */
		printk("<1> example device driver version 4: loaded at major number %d\n", example_major);

		example_device_stats = (example_stats *) kmalloc(sizeof(example_stats),GFP_KERNEL);
		if (!example_device_stats) {
				result = -ENOMEM;
				goto fail_malloc;
		}
		init_example_device_stats();

		/* We assume that the /proc/driver exists. Otherwise we need to use proc_mkdir to
		 * create it as follows: proc_mkdir("driver", NULL);
		 */
		example_proc_file = proc_create("driver/example", 0, NULL, &example_proc_fops);
		if (!example_proc_file)  {
				result = -ENOMEM;
				goto fail_malloc;
		}

		return 0;

fail_malloc:
		unregister_chrdev(example_major, "example");
		return  result;
}
开发者ID:BoiseState,项目名称:CS453-resources,代码行数:37,代码来源:example.c


示例5: register_ipu_device

int register_ipu_device()
{
	int ret = 0;
	struct device *temp;
	mxc_ipu_major = register_chrdev(0, "mxc_ipu", &mxc_ipu_fops);
	if (mxc_ipu_major < 0) {
		printk(KERN_ERR
		       "Unable to register Mxc Ipu as a char device\n");
		return mxc_ipu_major;
	}

	mxc_ipu_class = class_create(THIS_MODULE, "mxc_ipu");
	if (IS_ERR(mxc_ipu_class)) {
		printk(KERN_ERR "Unable to create class for Mxc Ipu\n");
		ret = PTR_ERR(mxc_ipu_class);
		goto err1;
	}

	temp = device_create(mxc_ipu_class, NULL, MKDEV(mxc_ipu_major, 0), NULL,
			     "mxc_ipu");

	if (IS_ERR(temp)) {
		printk(KERN_ERR "Unable to create class device for Mxc Ipu\n");
		ret = PTR_ERR(temp);
		goto err2;
	}
	spin_lock_init(&queue_lock);
	init_waitqueue_head(&waitq);
	return ret;

      err2:
	class_destroy(mxc_ipu_class);
      err1:
	unregister_chrdev(mxc_ipu_major, "mxc_ipu");
	return ret;

}
开发者ID:tiagolb,项目名称:liboot-tz,代码行数:37,代码来源:ipu_device.c


示例6: bano_init

int bano_init(void) {
  int b;

  /* Registering device */
  b = register_chrdev(bano_major, "bano", &bano_fops);
  if (b < 0) {
    printk("<1>Bano: cannot obtain major number %d\n", bano_major);
    return b;
  }

  damas = 0;
  varones = 0;
  curr_size_d = 0;
  curr_size_v = 0;
  damas_pos = 0;
  varones_pos = 0;
  m_init(&mutex);
  c_init(&cond);

  /* Allocating syncread_buffer */
  buffer_d = kmalloc(MAX_SIZE, GFP_KERNEL);
  if (buffer_d == NULL) {
    bano_exit();
    return -ENOMEM;
  }
  memset(buffer_d, 0, MAX_SIZE);

  buffer_v = kmalloc(MAX_SIZE, GFP_KERNEL);
  if (buffer_v == NULL) {
    bano_exit();
    return -ENOMEM;
  }
  memset(buffer_v, 0, MAX_SIZE);

  printk("<1>Inserting bano module varones y damas\n");
  return 0;
}
开发者ID:Javier12,项目名称:tarea3sistemas,代码行数:37,代码来源:pub-impl.c


示例7: cpuid_init

static int __init cpuid_init(void)
{
	int i, err = 0;
	i = 0;

	if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
		printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
		       CPUID_MAJOR);
		err = -EBUSY;
		goto out;
	}
	cpuid_class = class_create(THIS_MODULE, "cpuid");
	if (IS_ERR(cpuid_class)) {
		err = PTR_ERR(cpuid_class);
		goto out_chrdev;
	}
	for_each_online_cpu(i) {
		err = cpuid_device_create(i);
		if (err != 0) 
			goto out_class;
	}
	register_hotcpu_notifier(&cpuid_class_cpu_notifier);

	err = 0;
	goto out;

out_class:
	i = 0;
	for_each_online_cpu(i) {
		device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, i));
	}
	class_destroy(cpuid_class);
out_chrdev:
	unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");	
out:
	return err;
}
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:37,代码来源:cpuid.c


示例8: load_module

static int __init load_module(void)
{
	int ret_val;

	ret_val = register_chrdev(MAJOR_NUMBER, DEVICE_NAME, &Fops);

	if(ret_val < 0){
		printk(KERN_ALERT "%s failed with %d\n",
                 	     "Sorry, registering the character device ", ret_val);
		return ret_val;
	}

	printk(KERN_INFO "%s The major device number is %d.\n",
               "Registeration is a success", MAJOR_NUMBER);
    printk(KERN_INFO "If you want to talk to the device driver,\n");
    printk(KERN_INFO "you'll have to create a device file. \n");
    printk(KERN_INFO "We suggest you use:\n");
    printk(KERN_INFO "mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUMBER);
    printk(KERN_INFO "The device file name is important, because\n");
    printk(KERN_INFO "the ioctl program assumes that's the\n");
    printk(KERN_INFO "file you'll use.\n");

    return 0;
}
开发者ID:Azhng,项目名称:azgt_wheels,代码行数:24,代码来源:chardev.c


示例9: dsp56k_init_driver

static int __init dsp56k_init_driver(void)
{
	int err = 0;

	if(!MACH_IS_ATARI || !ATARIHW_PRESENT(DSP56K)) {
		printk("DSP56k driver: Hardware not present\n");
		return -ENODEV;
	}

	if(register_chrdev(DSP56K_MAJOR, "dsp56k", &dsp56k_fops)) {
		printk("DSP56k driver: Unable to register driver\n");
		return -ENODEV;
	}
	dsp56k_class = class_simple_create(THIS_MODULE, "dsp56k");
	if (IS_ERR(dsp56k_class)) {
		err = PTR_ERR(dsp56k_class);
		goto out_chrdev;
	}
	class_simple_device_add(dsp56k_class, MKDEV(DSP56K_MAJOR, 0), NULL, "dsp56k");

	err = devfs_mk_cdev(MKDEV(DSP56K_MAJOR, 0),
		      S_IFCHR | S_IRUSR | S_IWUSR, "dsp56k");
	if(err)
		goto out_class;

	printk(banner);
	goto out;

out_class:
	class_simple_device_remove(MKDEV(DSP56K_MAJOR, 0));
	class_simple_destroy(dsp56k_class);
out_chrdev:
	unregister_chrdev(DSP56K_MAJOR, "dsp56k");
out:
	return err;
}
开发者ID:iPodLinux,项目名称:linux-2.6.7-ipod,代码行数:36,代码来源:dsp56k.c


示例10: xordev_init_module

static int
xordev_init_module(void)
{
  int result, i;

  /* clear structures */
  for(i = 0; i < MAX_DEVICES; i++) xordev_data[i].devno = 0;

  /* Registering character device */
  major = register_chrdev(0, DRVNAME, &xordev_fops);
  if (major < 0) {
    printk(KERN_NOTICE "Can't register a character device");
    result = major;
    goto fail;
  }
  xordev_class = class_create(THIS_MODULE, DRVNAME);
  if (IS_ERR(xordev_class)) {
    printk(KERN_NOTICE "Can't create device class");
    result = PTR_ERR(xordev_class);
    goto fail;
  }

  /* PCI probing */
  DBG printk(KERN_DEBUG "Probing PCI devices");
  result = pci_register_driver(&xordev_pci_driver);
  if (result < 0) {
    printk(KERN_NOTICE "Can't register pci driver");
    goto fail;
  }

  return 0; /* success */

fail:
  xordev_cleanup_module();
  return result;
}
开发者ID:wojtekzozlak,项目名称:Studia.Archiwum,代码行数:36,代码来源:xordev.c


示例11: ethinit_module

int ethinit_module(void)
{
	int res;
        printk(KERN_INFO "init module called \n");
        init_module2_2();

        spin_lock_init(&eth_lock);

	  schar_name = "schar2";
		
	
	/* register device with kernel */
	res = register_chrdev(SCHAR_MAJOR_2, schar_name, &schar_fops);
       
	if (res) {
	      printk(KERN_INFO "can't register device with kernel\n");
		return res;
	}
	
	/* register proc entry */
	schar_root_header_2 = register_sysctl_table(schar_root_dir_2, 0);

	return 0;
}
开发者ID:andrewpeck,项目名称:emu,代码行数:24,代码来源:eth_hook_2.c


示例12: pmic_rtc_probe

static int pmic_rtc_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct device *temp_class;

	pmic_rtc_major = register_chrdev(0, "pmic_rtc", &pmic_rtc_fops);
	if (pmic_rtc_major < 0) {
		printk(KERN_ERR "Unable to get a major for pmic_rtc\n");
		return pmic_rtc_major;
	}

	pmic_rtc_class = class_create(THIS_MODULE, "pmic_rtc");
	if (IS_ERR(pmic_rtc_class)) {
		printk(KERN_ERR "Error creating pmic rtc class.\n");
		ret = PTR_ERR(pmic_rtc_class);
		goto err_out1;
	}

	temp_class = device_create(pmic_rtc_class, NULL,
				   MKDEV(pmic_rtc_major, 0), NULL,
				   "pmic_rtc");
	if (IS_ERR(temp_class)) {
		printk(KERN_ERR "Error creating pmic rtc class device.\n");
		ret = PTR_ERR(temp_class);
		goto err_out2;
	}

	printk(KERN_INFO "PMIC RTC successfully probed\n");
	return ret;

      err_out2:
	class_destroy(pmic_rtc_class);
      err_out1:
	unregister_chrdev(pmic_rtc_major, "pmic_rtc");
	return ret;
}
开发者ID:AvalueAES,项目名称:rev-sa01,代码行数:36,代码来源:pmic_rtc.c


示例13: s3c_dma_init

static int s3c_dma_init(void)
{
	//分配src,dst对应的缓冲区
	src = dma_alloc_writecombine(NULL, BUF_SIZE, &src_phys, GFP_KERNEL);
	if(NULL == src)
	{
		printk("can not alloc buf for src");
		return -ENOMEM;
	}

	dst = dma_alloc_writecombine(NULL, BUF_SIZE, &dst_phys, GFP_KERNEL);
	if(NULL == dst)
	{
		dma_free_writecombine(NULL, BUF_SIZE, src, src_phys);
		printk("can not alloc buf for dst");
		return -ENOMEM;
	}

	major = register_chrdev(0, "s3c_dma", &dma_fops);

	cls = class_create(THIS_MODULE, "s3c_dma");
	class_device_create(cls, NULL, MKDEV(major, 0), NULL, "dma");
	return 0;
}
开发者ID:mallius,项目名称:drivers-m,代码行数:24,代码来源:22_drv_dma.c


示例14: gpsdrv_init

/** gpsdrv_init Function
 *  This function Initializes the gps driver parametes and exposes
 *  /dev/gps node to user space
 *
 *  Parameters : NULL
 *  Returns  GPS_SUCCESS on success
 *           else suitable error code
 */
static int __init gpsdrv_init(void)
{

	GPSDRV_DBG(" Inside %s", __func__);

	/* Expose the device DEVICE_NAME to user space
	 * And obtain the major number for the device
	 */
	gpsdrv_major = register_chrdev(0, DEVICE_NAME, \
			&gpsdrv_chrdev_ops);
	if (0 > gpsdrv_major) {
		GPSDRV_ERR("Error when registering to char dev");
		return GPS_ERR_FAILURE;
	}
	GPSDRV_VER("allocated %d, %d", gpsdrv_major, 0);

	/*  udev */
	gpsdrv_class = class_create(THIS_MODULE, DEVICE_NAME);
	if (IS_ERR(gpsdrv_class)) {
		GPSDRV_ERR(" Something went wrong in class_create");
		unregister_chrdev(gpsdrv_major, DEVICE_NAME);
		return GPS_ERR_CLASS;
	}

	gpsdrv_dev =
		device_create(gpsdrv_class, NULL, MKDEV(gpsdrv_major, 0),
				NULL, DEVICE_NAME);
	if (IS_ERR(gpsdrv_dev)) {
		GPSDRV_ERR(" Error in class_create");
		unregister_chrdev(gpsdrv_major, DEVICE_NAME);
		class_destroy(gpsdrv_class);
		return GPS_ERR_CLASS;
	}

	return GPS_SUCCESS;
}
开发者ID:ArgentymDIM,项目名称:android_kernel_huawei_D1_P1,代码行数:44,代码来源:gps_drv.c


示例15: dummy_init

static int __init dummy_init(void)
{
	int ret;

	printk(KERN_INFO "Dummy is loading\n");

	memory_buffer = kmalloc(1, GFP_KERNEL);
	if (!memory_buffer)
		return -ENOMEM;

	memset(memory_buffer, 0, 1);

	ret = register_chrdev(memory_major, "dummy", &memory_fops);
	if (ret < 0)
		goto fail;

	printk(KERN_INFO "Dummy initialized\n");
	return 0;

fail:
	printk(KERN_INFO "dummy: cannot obtain major number %d\n", memory_major);
	kfree(memory_buffer);
	return ret;
}
开发者ID:dr-itz,项目名称:zhaw-os,代码行数:24,代码来源:dummy.c


示例16: my_init

/*
 * This function is called when the module is loaded and registers a
 * device for the driver to use.
 */
static int __init my_init(void)
{

  /* Note that as soon as the device is registered we might get access
     to the functions pointed to by fops, hence the ordering. */
  
  // Linux kernel's version of printf
  printk(KERN_INFO "Mapping virtual address...\n");
	
  // map virtual address to multiplier physical address
  // use ioremap
  virt_addr = ioremap(PHY_ADDR, MEMSIZE); // might need to convert inputs to unsigned long
  printk(KERN_INFO "Multiplication physical address: %h \n", PHY_ADDR); // might need to change %p 
  printk(KERN_INFO "Multiplication virtual address: %h \n", virt_addr);
  
  /* This function call registers a device and returns a major number
     associated with it.  Be wary, the device file could be accessed
     as soon as you register it, make sure anything you need (ie
     buffers ect) are setup _BEFORE_ you register the device.*/

  Major = register_chrdev(0, DEVICE_NAME, &fops);
  
  /* Negative values indicate a problem */
  if (Major < 0) {		
    /* Make sure you release any other resources you've already
       grabbed if you get here so you don't leave the kernel in a
       broken state. */
    printk(KERN_ALERT "Registering char device failed with %d\n", Major);
    return Major;
  } 

  printk(KERN_INFO "Registered a device with dynamic Major number of %d\n", Major);
  //printk(KERN_INFO "Create a device file for this device with this command:\n'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);

  return 0;		/* success */
}
开发者ID:alanachtenberg,项目名称:ECEN-449,代码行数:40,代码来源:multiplier.c


示例17: load_module

int __init load_module(void)
{
	  _major = register_chrdev (0,"brightnessMajor",&mod_fops);
	  if (_major < 0) {
		  printk("Registering the character device failed with (Major)-  %d\n",  _major);
		  return _major;
	  }
	  if (_major > 0) {
		  printk("Registering the character device success with (Major)-  %d\n",  _major);
	  }

	  _minor=misc_register(&mod_misc);

	  if (_minor){
		printk("Registering the character device failed with (Minor) -  %d\n",  _minor);
		return -EIO;
	  }
	  printk("Registering the character device success with (Minor) -  %d\n",  _minor);

	  initPin();

	  printk(KERN_ALERT "brightness Module Load Successfuly\n");
	  return 0;
}
开发者ID:avrahamcohen,项目名称:PWM-Linux-Driver,代码行数:24,代码来源:brightnessAPI.c


示例18: tb_init

// tb_init(): invoked as part of the kernel bootup process
static int tb_init(void)	
{
	int err=0;

	Message("tb_init() invoked");
	tb_major = register_chrdev (240, "xlr_tracebuffer", &tb_fops);
	if (tb_major < 0) {
		ErrorMsg("tb_init() register_chrdev() failed");
		return tb_major;
	}
	
	// the handler too gets registered in the following call 
	err = request_irq(PIC_BRIDGE_TB_IRQ(), tb_int_handler, TB_INT_FLAGS, "trace buffer", NULL);
	if (err) {
		unregister_chrdev (tb_major, "trace buffer");
		ErrorMsg("tb_init(): request_irq() failed");
		return err;
	}
	tb_dev.data = (unsigned char *)kmalloc(TB_SIZE,GFP_KERNEL);
	Message("tb_init() request_irq() succeeded");
	printk("Registered tracebuffer driver with Major No. [%d]\n", 240);

	return 0;
}
开发者ID:millken,项目名称:zhuxianB30,代码行数:25,代码来源:nlm_common_tb.c


示例19: simple_init

int __init simple_init(void) {
    int result;

    /* Register an entry in /proc */
    proc_entry = proc_create("simple", 0, NULL, &proc_fops);

    /* Register a device with the given major number */
    result = register_chrdev(simple_major, "simple", &simple_fops);
    if (result < 0) {
        printk(KERN_WARNING "Cannot register the /dev/simple device with major number: %d\n", simple_major);
        return result;
    }

    mybuf = kmalloc(mybuf_size, GFP_KERNEL);
    if (!mybuf) {
        result = -ENOMEM;
        simple_exit();
        return result;
    } else {
        memset(mybuf, 0, 1);
        printk(KERN_INFO "The SIMPLE module has been inserted.\n");
        return 0;
    }
}
开发者ID:aksiazek,项目名称:prog-sys,代码行数:24,代码来源:simple_module.c


示例20: chardev_example_init

static int __init chardev_example_init(void) {
	major_number = register_chrdev(0, "Chardev_Device", &fops);\
	
	if (major_number < 0) {
		return -1;
	}
	
	sysfs_class = class_create(THIS_MODULE, "Sysfs_class");
	
	if (IS_ERR(sysfs_class)) {
		unregister_chrdev(major_number, "Sysfs_Device");
		return -1;
	}

	sysfs_device = device_create(sysfs_class, NULL, MKDEV(major_number, 0), NULL, "sysfs_class" "_" "sysfs_Device");	

	if (IS_ERR(sysfs_device)) {
		class_destroy(sysfs_class);
		unregister_chrdev(major_number, "Sysfs_Device");
		return -1;
	}	

	return 0;
}
开发者ID:HarryCoin,项目名称:fw,代码行数:24,代码来源:chardev_example.c



注:本文中的register_chrdev函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ register_chrdev_region函数代码示例发布时间:2022-05-30
下一篇:
C++ register_callback函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap