本文整理汇总了C++中sema_init函数的典型用法代码示例。如果您正苦于以下问题:C++ sema_init函数的具体用法?C++ sema_init怎么用?C++ sema_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sema_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _rtw_init_sema
void _rtw_init_sema(struct semaphore *sema, int init_val)
{
sema_init(sema, init_val);
}
示例2: rknand_device_lock_init
void rknand_device_lock_init(void)
{
sema_init(&g_rk_nand_ops_mutex, 1);
}
示例3: mephisto_probe
static int mephisto_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
int err = ME_ERRNO_SUCCESS;
mephisto_usb_device_t* dev; /// The usb device.
me_device_t* n_device = NULL;
me_device_t* o_device = NULL;
long unsigned int serial_no;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
char* tmp;
#endif
PDEBUG("executed.\n");
/// Allocate structures.
dev = kzalloc(sizeof(mephisto_usb_device_t), GFP_KERNEL);
if (!dev)
{
PERROR_CRITICAL("Can't get memory for device's instance.\n");
err = -ENOMEM;
goto ERROR_0;
}
/// Initialize USB lock.
dev->usb_semaphore = kzalloc(sizeof(struct semaphore), GFP_KERNEL);
if (!dev->usb_semaphore)
{
PERROR_CRITICAL("Can't get memory for usb lock.\n");
err = -ENOMEM;
goto ERROR_1;
}
#ifndef init_MUTEX
sema_init(dev->usb_semaphore, 1);
#else
init_MUTEX(dev->usb_semaphore);
#endif
/// Initialize variables.
dev->dev = usb_get_dev(interface_to_usbdev(interface));
if(!dev->dev)
{
PERROR("Error while request for usb device.\n");
err = -ENODEV;
goto ERROR_2;
}
/// Initialize hardware
usb_set_intfdata(interface, dev);
/// Read serial number
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
tmp = (dev->dev->serial + strlen(dev->dev->serial));
serial_no = simple_strtoul(dev->dev->serial + 2, &tmp, 16);
#else
if (strict_strtoul(dev->dev->serial + 2, 16, &serial_no))
{
serial_no = 0;
}
#endif
dev->serial_no = serial_no;
/// Hardware init
mephisto_endpoints_reset(dev);
/**
Choice:
a) New device connected. Add to device list.
b) Old device reconected. Refresh device structure.
*/
o_device = find_device_on_list(dev, ME_PLUGGED_ANY);
if(o_device)
{
PDEBUG("Old device.\n");
// Old device.
if (o_device->bus.plugged == ME_PLUGGED_IN)
{
// Error device is already on list mark as active!
PERROR("Device is already on list mark as active!\n");
o_device->me_device_disconnect(o_device);
}
}
else
{
PDEBUG("New device.\n");
}
PINFO("CALLING %s constructor\n", "mephisto_constr");
n_device = mephisto_constr(dev, o_device);
if (!n_device)
{
PERROR("Executing '%s()' failed.\n", "mephisto_constr");
err = -ENODEV;
goto ERROR_3;
}
else if (!o_device)
{
PINFO("Adding new entry to device list.\n");
insert_to_device_list(n_device);
//.........这里部分代码省略.........
示例4: tty0tty_open
static int tty0tty_open(struct tty_struct *tty, struct file *file)
{
struct tty0tty_serial *tty0tty;
int index;
int msr = 0;
int mcr = 0;
#ifdef SCULL_DEBUG
printk(KERN_DEBUG "%s - \n", __FUNCTION__);
#endif
/* initialize the pointer in case something fails */
tty->driver_data = NULL;
/* get the serial object associated with this tty pointer */
index = tty->index;
tty0tty = tty0tty_table[index];
if (tty0tty == NULL) {
/* first time accessing this device, let's create it */
tty0tty = kmalloc(sizeof(*tty0tty), GFP_KERNEL);
if (!tty0tty)
return -ENOMEM;
sema_init(&tty0tty->sem, 1);
tty0tty->open_count = 0;
tty0tty_table[index] = tty0tty;
}
tport[index].tty = tty;
tty->port = &tport[index];
if ((index % 2) == 0) {
if (tty0tty_table[index + 1] != NULL)
if (tty0tty_table[index + 1]->open_count > 0)
mcr = tty0tty_table[index + 1]->mcr;
} else {
if (tty0tty_table[index - 1] != NULL)
if (tty0tty_table[index - 1]->open_count > 0)
mcr = tty0tty_table[index - 1]->mcr;
}
//null modem connection
if ((mcr & MCR_RTS) == MCR_RTS) {
msr |= MSR_CTS;
}
if ((mcr & MCR_DTR) == MCR_DTR) {
msr |= MSR_DSR;
msr |= MSR_CD;
}
tty0tty->msr = msr;
tty0tty->mcr = 0;
/* register the tty driver */
down(&tty0tty->sem);
/* save our structure within the tty structure */
tty->driver_data = tty0tty;
tty0tty->tty = tty;
++tty0tty->open_count;
up(&tty0tty->sem);
return 0;
}
示例5: cshell_init
/*******************************************************************************
* 函 数 名 : cshell_init
*
* 功能描述 : cshell初始化接口
*
* 输入参数 : 无
*
* 输出参数 : 无
*
* 返 回 值 : CSHELL_ERROR-初始化失败,CSHELL_OK-初始化成功
*
*******************************************************************************/
int cshell_init(void)
{
cshell_ctx_t *cshell_ctx = &g_cshell_ctx;
DRV_UART_SHELL_FLAG uartcshell_nv = {.extendedbits = 0};
u32 channel_id = 0;
printk("A:cshell_init start \n");
cshell_ctx->ccshell_work_flg = 1;
cshell_ctx->cshell_acm_fd = 0;
cshell_ctx->usb_send_buf = (u8*)kmalloc(CSHELL_BUFFER_SIZE, GFP_KERNEL);
if(!cshell_ctx->usb_send_buf)
{
printk("[ACSHELL]kmalloc fails line:%d", __LINE__);
goto error;
}
cshell_ctx->usb_send_buf_size = CSHELL_BUFFER_SIZE;
cshell_ctx->usb_send_buf_r = 0;
cshell_ctx->usb_send_buf_w = 0;
cshell_icc_init();
sema_init(&(cshell_ctx->cshell_send_sem), 0);
sema_init(&(cshell_ctx->cshell_recv_sem), 0);
sema_init(&(cshell_ctx->cshell_usb_send_sem), 0);
spin_lock_init(&g_cshell_ctx.cshell_spin_loc_permit);
if(bsp_nvm_read(NV_ID_DRV_UART_SHELL_FLAG, (u8 *)&uartcshell_nv, sizeof(DRV_UART_SHELL_FLAG)))
{
printk("[A:CSHELL]:bsp_nvm_read fails line:%d uartcshell_nv.cshell_to_auart:%d\n", __LINE__, uartcshell_nv.extendedbits);
}
if(uartcshell_nv.extendedbits & 0x1U)
{
cshell_set_bit(AUART_CSHELL);
}else{
cshell_clear_bit(AUART_CSHELL);
}
printk("A :icc channel[%d] open sucess \n", ICC_CHN_CSHELL);
channel_id = cshell_ctx->icc_channel_id << 16;
if(bsp_icc_event_register(channel_id ,cshell_read_cb, NULL, NULL, NULL))
printk(KERN_ERR "A:CSHELL bsp_icc_event_register fail");
cshell_ctx->send_task = kthread_run(cshell_send_thread, NULL, "cshell_send_thread");
if (IS_ERR(cshell_ctx->send_task))
{
printk("A:cshell_init send thread create fail\n");
goto error;
}
cshell_ctx->recv_task = kthread_run(cshell_recv_thread, NULL, "cshell_recv_thread");
if (IS_ERR(cshell_ctx->recv_task))
{
printk("A:cshell_init recv thread create fail\n");
goto error;
}
cshell_ctx->send_task_usb = kthread_run(cshell_usb_send_thread, NULL, "cshell_usb_send_thread");
if (IS_ERR(cshell_ctx->recv_task))
{
printk("[ACSHELL] fail to create cshell_usb_send_thread\n");
goto error;
}
printk("A:cshell_init udi cb register\n");
/* 注册USB插入回调函数*/
bsp_usb_register_enablecb(cshell_udi_open_cb);
bsp_usb_register_disablecb(cshell_udi_close_cb);
cshell_ctx->valid = 1;
printk("A:cshell_init ok\n");
return CSHELL_OK;
error:
cshell_uninit();
printk("A:cshell_init fail...\n");
return CSHELL_ERROR;
}
//#ifndef OS_ANDROID_USE_K3V3_KERNEL
module_init(cshell_init);
//#endif
#ifdef __cplusplus
}
开发者ID:fly2436732935,项目名称:android_kernel_honor7_PLK-AL10_PLK-TL01H_PLK-UL00_PLK-CL00_PLK-TL00,代码行数:99,代码来源:cshell.c
示例6: _r8712_init_xmit_priv
sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
struct _adapter *padapter)
{
sint i;
struct xmit_buf *pxmitbuf;
struct xmit_frame *pxframe;
memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv));
spin_lock_init(&pxmitpriv->lock);
sema_init(&pxmitpriv->xmit_sema, 0);
sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
/*
Please insert all the queue initializaiton using _init_queue below
*/
pxmitpriv->adapter = padapter;
_init_queue(&pxmitpriv->be_pending);
_init_queue(&pxmitpriv->bk_pending);
_init_queue(&pxmitpriv->vi_pending);
_init_queue(&pxmitpriv->vo_pending);
_init_queue(&pxmitpriv->bm_pending);
_init_queue(&pxmitpriv->legacy_dz_queue);
_init_queue(&pxmitpriv->apsd_queue);
_init_queue(&pxmitpriv->free_xmit_queue);
/*
Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
and initialize free_xmit_frame below.
Please also apply free_txobj to link_up all the xmit_frames...
*/
pxmitpriv->pallocated_frame_buf = _malloc(NR_XMITFRAME *
sizeof(struct xmit_frame) + 4);
if (pxmitpriv->pallocated_frame_buf == NULL) {
pxmitpriv->pxmit_frame_buf = NULL;
return _FAIL;
}
pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 -
((addr_t) (pxmitpriv->pallocated_frame_buf) & 3);
pxframe = (struct xmit_frame *) pxmitpriv->pxmit_frame_buf;
for (i = 0; i < NR_XMITFRAME; i++) {
_init_listhead(&(pxframe->list));
pxframe->padapter = padapter;
pxframe->frame_tag = DATA_FRAMETAG;
pxframe->pkt = NULL;
pxframe->buf_addr = NULL;
pxframe->pxmitbuf = NULL;
list_insert_tail(&(pxframe->list),
&(pxmitpriv->free_xmit_queue.queue));
pxframe++;
}
pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
/*
init xmit hw_txqueue
*/
_r8712_init_hw_txqueue(&pxmitpriv->be_txqueue, BE_QUEUE_INX);
_r8712_init_hw_txqueue(&pxmitpriv->bk_txqueue, BK_QUEUE_INX);
_r8712_init_hw_txqueue(&pxmitpriv->vi_txqueue, VI_QUEUE_INX);
_r8712_init_hw_txqueue(&pxmitpriv->vo_txqueue, VO_QUEUE_INX);
_r8712_init_hw_txqueue(&pxmitpriv->bmc_txqueue, BMC_QUEUE_INX);
pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
pxmitpriv->txirp_cnt = 1;
sema_init(&(pxmitpriv->tx_retevt), 0);
/*per AC pending irp*/
pxmitpriv->beq_cnt = 0;
pxmitpriv->bkq_cnt = 0;
pxmitpriv->viq_cnt = 0;
pxmitpriv->voq_cnt = 0;
/*init xmit_buf*/
_init_queue(&pxmitpriv->free_xmitbuf_queue);
_init_queue(&pxmitpriv->pending_xmitbuf_queue);
pxmitpriv->pallocated_xmitbuf = _malloc(NR_XMITBUFF *
sizeof(struct xmit_buf) + 4);
if (pxmitpriv->pallocated_xmitbuf == NULL)
return _FAIL;
pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 -
((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3);
pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
for (i = 0; i < NR_XMITBUFF; i++) {
_init_listhead(&pxmitbuf->list);
pxmitbuf->pallocated_buf = _malloc(MAX_XMITBUF_SZ +
XMITBUF_ALIGN_SZ);
if (pxmitbuf->pallocated_buf == NULL)
return _FAIL;
pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ -
((addr_t) (pxmitbuf->pallocated_buf) &
(XMITBUF_ALIGN_SZ - 1));
r8712_xmit_resource_alloc(padapter, pxmitbuf);
list_insert_tail(&pxmitbuf->list,
&(pxmitpriv->free_xmitbuf_queue.queue));
pxmitbuf++;
}
pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
alloc_hwxmits(padapter);
init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
tasklet_init(&pxmitpriv->xmit_tasklet,
(void(*)(addr_t))r8712_xmit_bh,
(addr_t)padapter);
return _SUCCESS;
}
示例7: load_exeso_binary
//.........这里部分代码省略.........
((PEB *)process->peb)->ProcessParameters = ppb;
}
/* allocate a Win32 thread object */
retval = create_object(KernelMode,
thread_object_type,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(struct ethread),
0,
0,
(PVOID *)&thread);
if (retval) {
goto out_free_process_cid;
}
thread->cid.unique_thread = create_cid_handle(thread, thread_object_type);
thread->cid.unique_process = process->unique_processid;
if (!thread->cid.unique_thread)
goto out_free_ethread;
/* set the teb */
init_teb.StackBase = (PVOID)(bprm->p);
init_teb.StackLimit = (PVOID)WIN32_LOWEST_ADDR + PAGE_SIZE;
thread->tcb.teb = create_teb(process, (PCLIENT_ID)&thread->cid, &init_teb);
if (IS_ERR(thread->tcb.teb)) {
retval = PTR_ERR(thread->tcb.teb);
goto out_free_thread_cid;
}
/* Init KThreaad */
ethread_init(thread, process, current);
sema_init(&thread->exec_semaphore,0);
if (is_win32 == TRUE) //parent is a windows process
{
down(&thread->exec_semaphore); //wait for the parent
child_w32process = process->win32process;
parent_w32process = parent_eprocess->win32process;
info = child_w32process->startup_info;
//now parent has finished its work
if(thread->inherit_all)
{
create_handle_table(parent_eprocess, TRUE, process);
child_w32process = create_w32process(parent_w32process, TRUE, process);
}
}
deref_object(process);
deref_object(thread);
set_teb_selector(current, (long)thread->tcb.teb);
thread->start_address = (void *)pe_entry; /* FIXME */
/* save current trap frame */
thread->tcb.trap_frame = (struct ktrap_frame *)regs;
/* init apc, to call LdrInitializeThunk */
#if 0
thread_apc = kmalloc(sizeof(KAPC), GFP_KERNEL);
if (!thread_apc) {
retval = -ENOMEM;
goto out_free_thread_cid;
示例8: zfcp_adapter_enqueue
/**
* zfcp_adapter_enqueue - enqueue a new adapter to the list
* @ccw_device: pointer to the struct cc_device
*
* Returns: 0 if a new adapter was successfully enqueued
* -ENOMEM if alloc failed
* Enqueues an adapter at the end of the adapter list in the driver data.
* All adapter internal structures are set up.
* Proc-fs entries are also created.
* locks: config_sema must be held to serialise changes to the adapter list
*/
int zfcp_adapter_enqueue(struct ccw_device *ccw_device)
{
struct zfcp_adapter *adapter;
/*
* Note: It is safe to release the list_lock, as any list changes
* are protected by the config_sema, which must be held to get here
*/
adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL);
if (!adapter)
return -ENOMEM;
adapter->gs = kzalloc(sizeof(struct zfcp_wka_ports), GFP_KERNEL);
if (!adapter->gs) {
kfree(adapter);
return -ENOMEM;
}
ccw_device->handler = NULL;
adapter->ccw_device = ccw_device;
atomic_set(&adapter->refcount, 0);
if (zfcp_qdio_allocate(adapter))
goto qdio_allocate_failed;
if (zfcp_allocate_low_mem_buffers(adapter))
goto failed_low_mem_buffers;
if (zfcp_reqlist_alloc(adapter))
goto failed_low_mem_buffers;
if (zfcp_adapter_debug_register(adapter))
goto debug_register_failed;
init_waitqueue_head(&adapter->remove_wq);
init_waitqueue_head(&adapter->erp_thread_wqh);
init_waitqueue_head(&adapter->erp_done_wqh);
INIT_LIST_HEAD(&adapter->port_list_head);
INIT_LIST_HEAD(&adapter->erp_ready_head);
INIT_LIST_HEAD(&adapter->erp_running_head);
spin_lock_init(&adapter->req_list_lock);
spin_lock_init(&adapter->hba_dbf_lock);
spin_lock_init(&adapter->san_dbf_lock);
spin_lock_init(&adapter->scsi_dbf_lock);
spin_lock_init(&adapter->rec_dbf_lock);
spin_lock_init(&adapter->req_q_lock);
spin_lock_init(&adapter->qdio_stat_lock);
rwlock_init(&adapter->erp_lock);
rwlock_init(&adapter->abort_lock);
sema_init(&adapter->erp_ready_sem, 0);
INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
INIT_WORK(&adapter->scan_work, _zfcp_scan_ports_later);
adapter->service_level.seq_print = zfcp_print_sl;
/* mark adapter unusable as long as sysfs registration is not complete */
atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
dev_set_drvdata(&ccw_device->dev, adapter);
if (sysfs_create_group(&ccw_device->dev.kobj,
&zfcp_sysfs_adapter_attrs))
goto sysfs_failed;
atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
zfcp_fc_wka_ports_init(adapter);
if (!zfcp_adapter_scsi_register(adapter))
return 0;
sysfs_failed:
zfcp_adapter_debug_unregister(adapter);
debug_register_failed:
dev_set_drvdata(&ccw_device->dev, NULL);
kfree(adapter->req_list);
failed_low_mem_buffers:
zfcp_free_low_mem_buffers(adapter);
qdio_allocate_failed:
zfcp_qdio_free(adapter);
kfree(adapter);
return -ENOMEM;
}
示例9: pn544_probe
static int pn544_probe(
struct i2c_client *client, const struct i2c_device_id *id)
{
int ret;
struct pn544_i2c_platform_data *pdata;
if (pn544_dev != NULL) {
printk(KERN_ERR "pn544_probe: multiple devices NOT supported\n");
ret = -ENODEV;
goto err_single_device;
}
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
printk(KERN_ERR "pn544_probe: need I2C_FUNC_I2C\n");
ret = -ENODEV;
goto err_check_functionality_failed;
}
pn544_dev = kzalloc(sizeof(*pn544_dev), GFP_KERNEL);
if (pn544_dev == NULL) {
printk(KERN_ERR "pn544_probe: out of memory\n");
ret = -ENOMEM;
goto err_alloc_data_failed;
}
pn544_dev->client = client;
pdata = client->dev.platform_data;
if (pdata) {
pn544_dev->irq_gpio=pdata->irq_gpio;
pn544_dev->firm_gpio=pdata->firm_gpio;
pn544_dev->ven_gpio=pdata->ven_gpio;
pn544_dev->clock_gpio=pdata->clock_gpio;
pn544_dev->dcdc_gpio=pdata->dcdc_gpio;
pn544_dev->int_active_low=pdata->int_active_low;
printk( "pn544_probe: gpio config data,irq=%d,download=%d,ven=%d,clock=%d,dcdc=%d,int_active_low=%d\n",pn544_dev->irq_gpio,pn544_dev->firm_gpio,pn544_dev->ven_gpio,pn544_dev->clock_gpio,pn544_dev->dcdc_gpio,pn544_dev->int_active_low);
}
else
{
printk(KERN_ERR "pn544_probe: no gpio config data\n");
ret = -ENODEV;
goto err_alloc_data_failed;
}
/* init semaphore and queues */
sema_init(&pn544_dev->sem, 1);
init_waitqueue_head(&pn544_dev->read_queue);
/* register this device with the driver core */
/*3. slf note 20110328--->create: sys/class/nfc-dev/pn544 , 注册设备节点/dev/pn544*/
pn544_dev->dev = device_create(pn544_dev_class, &client->dev,
MKDEV(pn544_major, pn544_minor), NULL, DEVNAME);
if (IS_ERR(pn544_dev->dev)) {
printk(KERN_ERR "pn544_probe: device_create() failed\n");
ret = PTR_ERR(pn544_dev->dev);
goto err_device_create_failed;
}
/*4. slf note 20110328--->create: sys/class/nfc-dev/pn544/name */
ret = device_create_file(pn544_dev->dev, &dev_attr_name);
if (ret) {
goto err_device_create_file_failed;
}
ret =nxp_pn544_reset();
if (ret < 0) {
printk(KERN_ERR "pn544: can't reset device\n");
goto err_device_create_file_failed;
}
/* set irq/polling mode */
if (client->irq && !pn544_disable_irq) {
if(pn544_dev->int_active_low==1)
{
ret = request_irq(client->irq, pn544_dev_irq_handler, IRQF_TRIGGER_FALLING, client->name, pn544_dev);
}
else
{
ret = request_irq(client->irq, pn544_dev_irq_handler, IRQF_TRIGGER_RISING, client->name, pn544_dev);
}
if (ret == 0) {
pn544_dev->use_irq = 1;
}
else {
dev_err(&client->dev, "request_irq failed\n");
}
}
if (!pn544_dev->use_irq) {
hrtimer_init(&pn544_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
pn544_dev->timer.function = pn544_dev_timer_handler;
hrtimer_start(&pn544_dev->timer, ktime_set(0, pn544_poll_value), HRTIMER_MODE_REL);
}
printk(KERN_INFO "pn544_probe: Start in %s mode,IRQ=%d,GPIO=%d\n", pn544_dev->use_irq ? "interrupt" : "polling",client->irq,INT_TO_MSM_GPIO(client->irq));
return 0;
err_device_create_file_failed:
device_destroy(pn544_dev_class, MKDEV(pn544_major, pn544_minor));
//.........这里部分代码省略.........
示例10: urbtc_probe
static int urbtc_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
struct usb_urbtc *dev = NULL;
struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint;
size_t buffer_size;
int i;
int retval = -ENOMEM;
/* allocate memory for our device state and initialize it */
dev = kmalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL) {
//err("Out of memory");
goto error;
}
memset(dev, 0, sizeof(*dev));
kref_init(&dev->kref);
sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
//init_MUTEX(&dev->readbuf_sem);
sema_init(&dev->readbuf_sem,1); //chg t.miyo
init_waitqueue_head(&dev->readbuf_wait);
dev->udev = usb_get_dev(interface_to_usbdev(interface));
dev->interface = interface;
dev->readreq_buffer = NULL;
dev->readbuf_urb = NULL;
dev->readbuf_work = NULL;
dev->readbuf_buffered = NULL;
dev->readbuf_last_read = 0;
dev->readbuf_last_buffered = 0;
iface_desc = interface->cur_altsetting;
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
endpoint = &iface_desc->endpoint[i].desc;
/* dbg("endpoint %d(%d) %s", */
/* endpoint->bEndpointAddress, */
/* endpoint->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK, */
/* endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK? "in": "out"); */
if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
== USB_DIR_IN) &&
((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
== USB_ENDPOINT_XFER_BULK)) {
switch (endpoint->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK) {
case EP_READREQ:
buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
dev->readreq_size = buffer_size;
dev->readreq_buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!dev->readreq_buffer) {
//err("Could not allocate readreq_buffer");
goto error;
}
break;
case EP_READ:
buffer_size = sizeof(struct uin);
dev->readbuf_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->readbuf_urb) {
//err("Could not allocate readbuf_urb");
goto error;
}
dev->readbuf_size = buffer_size;
dev->readbuf_work = kmalloc(buffer_size, GFP_KERNEL);
if (!dev->readbuf_work) {
//err("Could not allocate readbuf_work");
goto error;
}
dev->readbuf_buffered = kmalloc(buffer_size, GFP_KERNEL);
if (!dev->readbuf_buffered) {
//err("Could not allocate readbuf_buffer");
goto error;
}
usb_fill_bulk_urb(dev->readbuf_urb, dev->udev,
usb_rcvbulkpipe(dev->udev, endpoint->bEndpointAddress),
dev->readbuf_work, dev->readbuf_size,
urbtc_read_bulk_callback, dev);
break;
default:
break;
}
}
if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
== USB_DIR_OUT) &&
((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
== USB_ENDPOINT_XFER_BULK)) {
switch (endpoint->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK) {
case EP_CCMD:
buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
dev->write_counter_size = buffer_size;
dev->write_counter_buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!dev->write_counter_buffer) {
//err("Could not allocate write_counter_buffer");
goto error;
}
break;
case EP_SCMD:
default:
break;
}
//.........这里部分代码省略.........
示例11: fifo_module_init
/**
Function Name : fifo_module_init
Function Type : Module INIT
Description : Initialization method of the Kernel module. The
method gets invoked when the kernel module is being
inserted using the command insmod.
*/
static int __init fifo_module_init(void)
{
int ret;
printk(KERN_INFO "FIFO:FIFO module is being loaded.\n");
/**Proc FS is created with RD&WR permissions with name fifo_config*/
fifo_config_file_entry = proc_create(FIFO_CONFIG,0777,NULL,&fifo_config_module_fops);
/** Condition to verify if fifo_config creation was successful*/
if(fifo_config_file_entry == NULL) {
printk(KERN_ALERT "FIFO ERROR: Could not initialize /proc/%s\n",FIFO_CONFIG);
/** FILE CREATION PROBLEM */
return -ENOMEM;
}
/**
Registering the Device with a major number as 240 and
configuring the file operations associated with it.
*/
ret = register_chrdev(MAJOR_NUM, FIFO_DEVICE, &fifo_module_fops);
/** Condition code to check if the registration was successful.*/
if (ret < 0) {
printk(KERN_ALERT "FIFO ERROR: %s failed with %d\n",
"Sorry, registering the character device ", MAJOR_NUM);
/** Registration error.*/
return ret;
}
printk(KERN_INFO "FIFO:registered correctly with major number %d\n", MAJOR_NUM);
/** Registering device class and associating devices with it.*/
fifoClass = class_create(THIS_MODULE, CLASS_NAME);
/** Condition check if the class creation was successful. */
if (IS_ERR(fifoClass)){
/** Unregister the device due to failed class creation. */
unregister_chrdev(MAJOR_NUM, FIFO_DEVICE);
printk(KERN_ALERT "FIFO ERROR:Failed to register device class\n");
/** Class creation error.*/
return PTR_ERR(fifoClass);
}
printk(KERN_INFO "FIFO: device class registered correctly\n");
/**
Registering the device driver for the provided device class. The
device driver is associated with fifo0 with minor number as 0.
*/
fifo = device_create(fifoClass, NULL, MKDEV(MAJOR_NUM, MINOR_NUM_FIFO), NULL, FIFO_DEVICE_NAME);
/** Condition for error verification during driver creation.*/
if (IS_ERR(fifo)){
/** Class destroyed associated with the device drivers.*/
class_destroy(fifoClass);
/** Unregister the device due to failed driver creation. */
unregister_chrdev(MAJOR_NUM, FIFO_DEVICE);
printk(KERN_ALERT "FIFO ERROR:Failed to create the device\n");
/** Driver creation error.*/
return PTR_ERR(fifo);
}
printk(KERN_INFO "FIFO:device class created correctly\n");
/** Device Status flag set to false because device not in use.*/
device_open = 0;
/** Default Memory size of queue set to 8*/
mem_alloc_size = fifo_size;
/** Queue Allocated with the default size.*/
queue = (struct data_item*)kmalloc(mem_alloc_size*sizeof(struct data_item),GFP_KERNEL);
/** Condition to check if the memory allocation was successful.*/
if(!queue) {
printk(KERN_ERR "FIFO ERROR:Memory allocation problem.\n");
/** Memory allocation problem.*/
return -ENOMEM;
}
/** FIFO HEAD Set to FIRST Location. */
head = -1;
tail = -1;
/** Initializing push and pop counters*/
push = 0;
pop = 0;
/** Initializing the semaphores */
sema_init(&mutex,1);
sema_init(&empty,0);
sema_init(&full,mem_alloc_size);
sema_init(&producer_mutex,1);
//.........这里部分代码省略.........
示例12: EplLinInit
static int __init EplLinInit(void)
{
tEplKernel EplRet;
int iErr;
int iRet;
#ifdef CONFIG_DEVFS_FS
int nMinorNumber;
#endif
TRACE0("EPL: + EplLinInit...\n");
TRACE2("EPL: Driver build: %s / %s\n", __DATE__, __TIME__);
iRet = 0;
// initialize global variables
atomic_set(&AtomicEventState_g, EVENT_STATE_INIT);
sema_init(&SemaphoreCbEvent_g, 1);
init_waitqueue_head(&WaitQueueCbEvent_g);
init_waitqueue_head(&WaitQueueProcess_g);
init_waitqueue_head(&WaitQueueRelease_g);
#ifdef CONFIG_DEVFS_FS
// register character device handler
TRACE2("EPL: Installing Driver '%s', Version %s...\n",
EPLLIN_DRV_NAME, EPL_PRODUCT_VERSION);
TRACE0("EPL: (using dynamic major number assignment)\n");
nDrvMajorNumber_g =
register_chrdev(0, EPLLIN_DRV_NAME, &EplLinFileOps_g);
if (nDrvMajorNumber_g != 0) {
TRACE2
("EPL: Driver '%s' installed successful, assigned MajorNumber=%d\n",
EPLLIN_DRV_NAME, nDrvMajorNumber_g);
} else {
TRACE1
("EPL: ERROR: Driver '%s' is unable to get a free MajorNumber!\n",
EPLLIN_DRV_NAME);
iRet = -EIO;
goto Exit;
}
// create device node in DEVFS
nMinorNumber = 0;
TRACE1("EPL: Creating device node '/dev/%s'...\n", EPLLIN_DEV_NAME);
iErr =
devfs_mk_cdev(MKDEV(nDrvMajorNumber_g, nMinorNumber),
S_IFCHR | S_IRUGO | S_IWUGO, EPLLIN_DEV_NAME);
if (iErr == 0) {
TRACE1("EPL: Device node '/dev/%s' created successful.\n",
EPLLIN_DEV_NAME);
} else {
TRACE1("EPL: ERROR: unable to create device node '/dev/%s'\n",
EPLLIN_DEV_NAME);
iRet = -EIO;
goto Exit;
}
#else
// register character device handler
// only one Minor required
TRACE2("EPL: Installing Driver '%s', Version %s...\n",
EPLLIN_DRV_NAME, EPL_PRODUCT_VERSION);
iRet = alloc_chrdev_region(&nDevNum_g, 0, 1, EPLLIN_DRV_NAME);
if (iRet == 0) {
TRACE2
("EPL: Driver '%s' installed successful, assigned MajorNumber=%d\n",
EPLLIN_DRV_NAME, MAJOR(nDevNum_g));
} else {
TRACE1
("EPL: ERROR: Driver '%s' is unable to get a free MajorNumber!\n",
EPLLIN_DRV_NAME);
iRet = -EIO;
goto Exit;
}
// register cdev structure
pEpl_cdev_g = cdev_alloc();
pEpl_cdev_g->ops = &EplLinFileOps_g;
pEpl_cdev_g->owner = THIS_MODULE;
iErr = cdev_add(pEpl_cdev_g, nDevNum_g, 1);
if (iErr) {
TRACE2("EPL: ERROR %d: Driver '%s' could not be added!\n",
iErr, EPLLIN_DRV_NAME);
iRet = -EIO;
goto Exit;
}
#endif
// create device node in PROCFS
EplRet = EplLinProcInit();
if (EplRet != kEplSuccessful) {
goto Exit;
}
Exit:
TRACE1("EPL: - EplLinInit (iRet=%d)\n", iRet);
return (iRet);
//.........这里部分代码省略.........
示例13: frandom_init_module
static int frandom_init_module(void)
{
int result;
/* The buffer size MUST be at least 256 bytes, because we assume that
minimal length in init_rand_state().
*/
if (frandom_bufsize < 256) {
printk(KERN_ERR "frandom: Refused to load because frandom_bufsize=%d < 256\n",frandom_bufsize);
return -EINVAL;
}
if ((frandom_chunklimit != 0) && (frandom_chunklimit < 256)) {
printk(KERN_ERR "frandom: Refused to load because frandom_chunklimit=%d < 256 and != 0\n",frandom_chunklimit);
return -EINVAL;
}
erandom_state = kmalloc(sizeof(struct frandom_state), GFP_KERNEL);
if (!erandom_state)
return -ENOMEM;
/* This specific buffer is only used for seeding, so we need
256 bytes exactly */
erandom_state->buf = kmalloc(256, GFP_KERNEL);
if (!erandom_state->buf) {
kfree(erandom_state);
return -ENOMEM;
}
sema_init(&erandom_state->sem, 1); /* Init semaphore as a mutex */
erandom_seeded = 0;
frandom_class = class_create(THIS_MODULE, "fastrng");
if (IS_ERR(frandom_class)) {
result = PTR_ERR(frandom_class);
printk(KERN_WARNING "frandom: Failed to register class fastrng\n");
goto error0;
}
/*
* Register your major, and accept a dynamic number. This is the
* first thing to do, in order to avoid releasing other module's
* fops in frandom_cleanup_module()
*/
cdev_init(&frandom_cdev, &frandom_fops);
frandom_cdev.owner = THIS_MODULE;
result = cdev_add(&frandom_cdev, MKDEV(frandom_major, frandom_minor), 1);
if (result) {
printk(KERN_WARNING "frandom: Failed to add cdev for /dev/frandom\n");
goto error1;
}
result = register_chrdev_region(MKDEV(frandom_major, frandom_minor), 1, "/dev/frandom");
if (result < 0) {
printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, frandom_minor);
goto error2;
}
frandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, frandom_minor), NULL, "frandom");
if (IS_ERR(frandom_device)) {
printk(KERN_WARNING "frandom: Failed to create frandom device\n");
goto error3;
}
cdev_init(&erandom_cdev, &frandom_fops);
erandom_cdev.owner = THIS_MODULE;
result = cdev_add(&erandom_cdev, MKDEV(frandom_major, erandom_minor), 1);
if (result) {
printk(KERN_WARNING "frandom: Failed to add cdev for /dev/erandom\n");
goto error4;
}
result = register_chrdev_region(MKDEV(frandom_major, erandom_minor), 1, "/dev/erandom");
if (result < 0) {
printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, erandom_minor);
goto error5;
}
erandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, erandom_minor), NULL, "erandom");
if (IS_ERR(erandom_device)) {
printk(KERN_WARNING "frandom: Failed to create erandom device\n");
goto error6;
}
return 0; /* succeed */
error6:
unregister_chrdev_region(MKDEV(frandom_major, erandom_minor), 1);
error5:
cdev_del(&erandom_cdev);
error4:
device_destroy(frandom_class, MKDEV(frandom_major, frandom_minor));
error3:
unregister_chrdev_region(MKDEV(frandom_major, frandom_minor), 1);
error2:
cdev_del(&frandom_cdev);
error1:
class_destroy(frandom_class);
//.........这里部分代码省略.........
示例14: islpci_setup
struct net_device *
islpci_setup(struct pci_dev *pdev)
{
islpci_private *priv;
struct net_device *ndev = alloc_etherdev(sizeof (islpci_private));
if (!ndev)
return ndev;
SET_MODULE_OWNER(ndev);
pci_set_drvdata(pdev, ndev);
#if defined(SET_NETDEV_DEV)
SET_NETDEV_DEV(ndev, &pdev->dev);
#endif
/* setup the structure members */
ndev->base_addr = pci_resource_start(pdev, 0);
ndev->irq = pdev->irq;
/* initialize the function pointers */
ndev->open = &islpci_open;
ndev->stop = &islpci_close;
ndev->get_stats = &islpci_statistics;
ndev->do_ioctl = &prism54_ioctl;
ndev->wireless_handlers =
(struct iw_handler_def *) &prism54_handler_def;
ndev->ethtool_ops = &islpci_ethtool_ops;
ndev->hard_start_xmit = &islpci_eth_transmit;
/* ndev->set_multicast_list = &islpci_set_multicast_list; */
ndev->addr_len = ETH_ALEN;
ndev->set_mac_address = &prism54_set_mac_address;
/* Get a non-zero dummy MAC address for nameif. Jean II */
memcpy(ndev->dev_addr, dummy_mac, 6);
#ifdef HAVE_TX_TIMEOUT
ndev->watchdog_timeo = ISLPCI_TX_TIMEOUT;
ndev->tx_timeout = &islpci_eth_tx_timeout;
#endif
/* allocate a private device structure to the network device */
priv = netdev_priv(ndev);
priv->ndev = ndev;
priv->pdev = pdev;
priv->monitor_type = ARPHRD_IEEE80211;
priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
priv->monitor_type : ARPHRD_ETHER;
/* Add pointers to enable iwspy support. */
priv->wireless_data.spy_data = &priv->spy_data;
ndev->wireless_data = &priv->wireless_data;
/* save the start and end address of the PCI memory area */
ndev->mem_start = (unsigned long) priv->device_base;
ndev->mem_end = ndev->mem_start + ISL38XX_PCI_MEM_SIZE;
#if VERBOSE > SHOW_ERROR_MESSAGES
DEBUG(SHOW_TRACING, "PCI Memory remapped to 0x%p\n", priv->device_base);
#endif
init_waitqueue_head(&priv->reset_done);
/* init the queue read locks, process wait counter */
sema_init(&priv->mgmt_sem, 1);
priv->mgmt_received = NULL;
init_waitqueue_head(&priv->mgmt_wqueue);
sema_init(&priv->stats_sem, 1);
spin_lock_init(&priv->slock);
/* init state machine with off#1 state */
priv->state = PRV_STATE_OFF;
priv->state_off = 1;
/* initialize workqueue's */
INIT_WORK(&priv->stats_work, prism54_update_stats);
priv->stats_timestamp = 0;
INIT_WORK(&priv->reset_task, islpci_do_reset_and_wake);
priv->reset_task_pending = 0;
/* allocate various memory areas */
if (islpci_alloc_memory(priv))
goto do_free_netdev;
/* select the firmware file depending on the device id */
switch (pdev->device) {
case 0x3877:
strcpy(priv->firmware, ISL3877_IMAGE_FILE);
break;
case 0x3886:
strcpy(priv->firmware, ISL3886_IMAGE_FILE);
break;
default:
strcpy(priv->firmware, ISL3890_IMAGE_FILE);
break;
}
if (register_netdev(ndev)) {
//.........这里部分代码省略.........
示例15: ieee80211_alloc_hw
//.........这里部分代码省略.........
hw->sta_data_size = sizeof(struct cw1200_sta_priv);
hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &cw1200_band_2ghz;
#ifdef CONFIG_CW1200_5GHZ_SUPPORT
hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &cw1200_band_5ghz;
#endif /* CONFIG_CW1200_5GHZ_SUPPORT */
/* Channel params have to be cleared before registering wiphy again */
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
sband = hw->wiphy->bands[band];
if (!sband)
continue;
for (i = 0; i < sband->n_channels; i++) {
sband->channels[i].flags = 0;
sband->channels[i].max_antenna_gain = 0;
sband->channels[i].max_power = 30;
}
}
hw->wiphy->max_scan_ssids = 2;
hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
SET_IEEE80211_PERM_ADDR(hw, cw1200_mac_template);
if (hw->wiphy->perm_addr[3] == 0 &&
hw->wiphy->perm_addr[4] == 0 &&
hw->wiphy->perm_addr[5] == 0) {
get_random_bytes(&hw->wiphy->perm_addr[3], 3);
}
mutex_init(&priv->wsm_cmd_mux);
mutex_init(&priv->conf_mutex);
priv->workqueue = create_singlethread_workqueue("cw1200_wq");
sema_init(&priv->scan.lock, 1);
INIT_WORK(&priv->scan.work, cw1200_scan_work);
INIT_DELAYED_WORK(&priv->scan.probe_work, cw1200_probe_work);
INIT_DELAYED_WORK(&priv->scan.timeout, cw1200_scan_timeout);
INIT_DELAYED_WORK(&priv->clear_recent_scan_work, cw1200_clear_recent_scan_work);
INIT_WORK(&priv->join_work, cw1200_join_work);
INIT_DELAYED_WORK(&priv->join_timeout, cw1200_join_timeout);
INIT_WORK(&priv->unjoin_work, cw1200_unjoin_work);
INIT_WORK(&priv->offchannel_work, cw1200_offchannel_work);
INIT_WORK(&priv->join_complete_work, cw1200_join_complete_work);
INIT_WORK(&priv->wep_key_work, cw1200_wep_key_work);
INIT_WORK(&priv->tx_policy_upload_work, tx_policy_upload_work);
spin_lock_init(&priv->event_queue_lock);
INIT_LIST_HEAD(&priv->event_queue);
INIT_WORK(&priv->event_handler, cw1200_event_handler);
INIT_DELAYED_WORK(&priv->bss_loss_work, cw1200_bss_loss_work);
INIT_DELAYED_WORK(&priv->connection_loss_work,
cw1200_connection_loss_work);
spin_lock_init(&priv->bss_loss_lock);
INIT_WORK(&priv->tx_failure_work, cw1200_tx_failure_work);
spin_lock_init(&priv->ps_state_lock);
INIT_DELAYED_WORK(&priv->set_cts_work, cw1200_set_cts_work);
INIT_WORK(&priv->set_tim_work, cw1200_set_tim_work);
INIT_WORK(&priv->multicast_start_work, cw1200_multicast_start_work);
INIT_WORK(&priv->multicast_stop_work, cw1200_multicast_stop_work);
INIT_WORK(&priv->link_id_work, cw1200_link_id_work);
INIT_DELAYED_WORK(&priv->link_id_gc_work, cw1200_link_id_gc_work);
#if defined(CONFIG_CW1200_USE_STE_EXTENSIONS)
INIT_WORK(&priv->linkid_reset_work, cw1200_link_id_reset);
#endif
INIT_WORK(&priv->update_filtering_work, cw1200_update_filtering_work);
INIT_WORK(&priv->set_beacon_wakeup_period_work,
cw1200_set_beacon_wakeup_period_work);