static int alloc_descs(unsigned int start, unsigned int cnt, int node, struct module *owner) { struct irq_desc *desc; int i; for (i = 0; i < cnt; i++) { desc = alloc_desc(start + i, node, owner); if (!desc) goto err; mutex_lock(&sparse_irq_lock); irq_insert_desc(start + i, desc); mutex_unlock(&sparse_irq_lock); } return start; err: for (i--; i >= 0; i--) free_desc(start + i); mutex_lock(&sparse_irq_lock); bitmap_clear(allocated_irqs, start, cnt); mutex_unlock(&sparse_irq_lock); return -ENOMEM; }
int16 RmvTime(uint32 tm) { D(bug("RmvTime %08lx\n", tm)); // Find descriptor int i = find_desc(tm); if (i < 0) { D(bug("WARNING: RmvTime(%08lx): Descriptor not found\n", tm)); return 0; } // Task active? if (ReadMacInt16(tm + qType) & 0x8000) { // Yes, make task inactive and remove it from the Time Manager queue WriteMacInt16(tm + qType, ReadMacInt16(tm + qType) & 0x7fff); dequeue_tm(tm); // Compute remaining time tm_time_t remaining, current; timer_current_time(current); timer_sub_time(remaining, desc[i].wakeup, current); WriteMacInt32(tm + tmCount, timer_host2mac_time(remaining)); } else WriteMacInt32(tm + tmCount, 0); D(bug(" tmCount %ld\n", ReadMacInt32(tm + tmCount))); // Free descriptor free_desc(i); return 0; }
void free_network_name_desc(NetworkNameDesc* head){ free(head->network_name); head->network_name = NULL; free_desc(head->next_desc); head->next_desc = NULL; free(head); head = NULL; }
void free_cable_delivery_system_desc(DESCRIPTOR_COMMON * head) { // uprintf("prepare to free : 0x%x\n",head->descriptor_tag); CABLE_DELIVERY_SYSTEM_DESC * phead = (CABLE_DELIVERY_SYSTEM_DESC *)head; free_desc(phead->next_desc); phead->next_desc = NULL; free(phead); phead = NULL; head = NULL; }
void free_component_desc(DESCRIPTOR_COMMON* head) { COMPONENT_DESC * phead = (COMPONENT_DESC *)head; free(phead->text_char); phead->text_char = NULL; free_desc(phead->next_desc); phead->next_desc = NULL; free(phead); phead = NULL; head = NULL; }
/** * irq_free_descs - free irq descriptors * @from: Start of descriptor range * @cnt: Number of consecutive irqs to free */ void irq_free_descs(unsigned int from, unsigned int cnt) { int i; if (from >= nr_irqs || (from + cnt) > nr_irqs) return; for (i = 0; i < cnt; i++) free_desc(from + i); mutex_lock(&sparse_irq_lock); bitmap_clear(allocated_irqs, from, cnt); mutex_unlock(&sparse_irq_lock); }
void free_local_time_offset_desc(DESCRIPTOR_COMMON *head) { LOCAL_TIME_OFFSET_DESC *phead = (LOCAL_TIME_OFFSET_DESC *)head; free_localtime_offset_item(phead->first_item); phead->first_item = NULL; free_desc(phead->next_desc); phead->next_desc = NULL; free(phead); phead = NULL; head = NULL; }
int rmconn( struct CONN * prev_ring ) /* removes from the linked-list and deallocates a connection * prev_ring */ { struct CONN * curr = prev_ring->next; struct CONN * conn; prev_ring->next = curr->next; if( curr->next == NULL ) last_conn = prev_ring; free_desc( &(curr->client), 1, curr); if (flags.writer.type == UNIQUE) free_desc( &(curr->server), 0, curr); else free_desc( &(curr->server), 1, curr); S_free( curr ); conn = first_conn; if( flags.exitclosed ) { if( flags.exitclosed_first ) { /* -Ef */ while( conn->num > flags.exitclosed ) { if(! (conn->next) ) exit( EXIT_SUCCESS ); conn = conn->next; } } else { /* -E */ --flags.exitclosed; if( flags.exitclosed == 0) exit( EXIT_SUCCESS ); } } if( flags.trackonly && (! flags.trackonly_first) ) count_opened--; }
static int alloc_descs(unsigned int start, unsigned int cnt, int node, const struct irq_affinity_desc *affinity, struct module *owner) { struct irq_desc *desc; int i; /* Validate affinity mask(s) */ if (affinity) { for (i = 0; i < cnt; i++) { if (cpumask_empty(&affinity[i].mask)) return -EINVAL; } } for (i = 0; i < cnt; i++) { const struct cpumask *mask = NULL; unsigned int flags = 0; if (affinity) { if (affinity->is_managed) { flags = IRQD_AFFINITY_MANAGED | IRQD_MANAGED_SHUTDOWN; } mask = &affinity->mask; node = cpu_to_node(cpumask_first(mask)); affinity++; } desc = alloc_desc(start + i, node, flags, mask, owner); if (!desc) goto err; irq_insert_desc(start + i, desc); irq_sysfs_add(start + i, desc); irq_add_debugfs_entry(start + i, desc); } bitmap_set(allocated_irqs, start, cnt); return start; err: for (i--; i >= 0; i--) free_desc(start + i); return -ENOMEM; }
static int alloc_descs(unsigned int start, unsigned int cnt, int node, const struct cpumask *affinity, struct module *owner) { const struct cpumask *mask = NULL; struct irq_desc *desc; unsigned int flags; int i; /* Validate affinity mask(s) */ if (affinity) { for (i = 0, mask = affinity; i < cnt; i++, mask++) { if (cpumask_empty(mask)) return -EINVAL; } } flags = affinity ? IRQD_AFFINITY_MANAGED : 0; mask = NULL; for (i = 0; i < cnt; i++) { if (affinity) { node = cpu_to_node(cpumask_first(affinity)); mask = affinity; affinity++; } desc = alloc_desc(start + i, node, flags, mask, owner); if (!desc) goto err; mutex_lock(&sparse_irq_lock); irq_insert_desc(start + i, desc); irq_sysfs_add(start + i, desc); mutex_unlock(&sparse_irq_lock); } return start; err: for (i--; i >= 0; i--) free_desc(start + i); mutex_lock(&sparse_irq_lock); bitmap_clear(allocated_irqs, start, cnt); mutex_unlock(&sparse_irq_lock); return -ENOMEM; }
/** * Get and a device descriptor and byteswap it appropriately. */ static bool usbProxyGetDeviceDesc(PUSBPROXYDEV pProxyDev, PVUSBDESCDEVICE pOut) { /* * Get the descriptor from the device. */ PVUSBDESCDEVICE pIn = (PVUSBDESCDEVICE)GetStdDescSync(pProxyDev, VUSB_DT_DEVICE, 0, 0, VUSB_DT_DEVICE_MIN_LEN); if (!pIn) { Log(("usbProxyGetDeviceDesc: pProxyDev=%s: GetStdDescSync failed\n", pProxyDev->pUsbIns->pszName)); return false; } if (pIn->bLength < VUSB_DT_DEVICE_MIN_LEN) { Log(("usb-proxy: pProxyDev=%s: Corrupted device descriptor. bLength=%d\n", pProxyDev->pUsbIns->pszName, pIn->bLength)); return false; } /* * Convert it. */ pOut->bLength = VUSB_DT_DEVICE_MIN_LEN; pOut->bDescriptorType = VUSB_DT_DEVICE; pOut->bcdUSB = RT_LE2H_U16(pIn->bcdUSB); pOut->bDeviceClass = pIn->bDeviceClass; pOut->bDeviceSubClass = pIn->bDeviceSubClass; pOut->bDeviceProtocol = pIn->bDeviceProtocol; pOut->bMaxPacketSize0 = pIn->bMaxPacketSize0; pOut->idVendor = RT_LE2H_U16(pIn->idVendor); pOut->idProduct = RT_LE2H_U16(pIn->idProduct); pOut->bcdDevice = RT_LE2H_U16(pIn->bcdDevice); pOut->iManufacturer = pIn->iManufacturer; pOut->iProduct = pIn->iProduct; pOut->iSerialNumber = pIn->iSerialNumber; pOut->bNumConfigurations = pIn->bNumConfigurations; free_desc(pIn); return true; }
void free_servicelist_desc(ServiceListDesc* head){ free_desc(head->next_desc); head->next_desc = NULL; free(head); head = NULL; }
void irq_init_desc(unsigned int irq) { free_desc(irq); }
int16 RmvTime(uint32 tm) { D(bug("RmvTime %08lx\n", tm)); // Find descriptor TMDesc *desc = find_desc(tm); if (!desc) { printf("WARNING: RmvTime(%08lx): Descriptor not found\n", (long unsigned int)tm); return 0; } // Task active? #if PRECISE_TIMING_BEOS while (acquire_sem(wakeup_time_sem) == B_INTERRUPTED) ; suspend_thread(timer_thread); #endif #ifdef PRECISE_TIMING_MACH semaphore_wait(wakeup_time_sem); thread_suspend(timer_thread); #endif #if PRECISE_TIMING_POSIX timer_thread_suspend(); pthread_mutex_lock(&wakeup_time_lock); #endif if (ReadMacInt16(tm + qType) & 0x8000) { // Yes, make task inactive and remove it from the Time Manager queue WriteMacInt16(tm + qType, ReadMacInt16(tm + qType) & 0x7fff); dequeue_tm(tm); #if PRECISE_TIMING // Look for next task to be called and set wakeup_time wakeup_time = wakeup_time_max; for (TMDesc *d = tmDescList; d; d = d->next) if ((ReadMacInt16(d->task + qType) & 0x8000)) if (timer_cmp_time(d->wakeup, wakeup_time) < 0) wakeup_time = d->wakeup; #endif // Compute remaining time tm_time_t remaining, current; timer_current_time(current); timer_sub_time(remaining, desc->wakeup, current); WriteMacInt32(tm + tmCount, timer_host2mac_time(remaining)); } else WriteMacInt32(tm + tmCount, 0); D(bug(" tmCount %ld\n", ReadMacInt32(tm + tmCount))); #if PRECISE_TIMING_BEOS release_sem(wakeup_time_sem); thread_info info; do { resume_thread(timer_thread); // This will unblock the thread get_thread_info(timer_thread, &info); } while (info.state == B_THREAD_SUSPENDED); // Sometimes, resume_thread() doesn't work (BeOS bug?) #endif #ifdef PRECISE_TIMING_MACH semaphore_signal(wakeup_time_sem); thread_abort(timer_thread); thread_resume(timer_thread); #endif #if PRECISE_TIMING_POSIX pthread_mutex_unlock(&wakeup_time_lock); timer_thread_resume(); assert(suspend_count == 0); #endif // Free descriptor free_desc(desc); return 0; }
// ARM10C 20141115 // start: 16, cnt: 144, node: 0, owner: NULL // ARM10C 20141213 // start: 160, cnt: 256, node: 0, owner: NULL static int alloc_descs(unsigned int start, unsigned int cnt, int node, struct module *owner) { struct irq_desc *desc; int i; // cnt: 144 for (i = 0; i < cnt; i++) { // i: 0, start: 16, node: 0, owner: NULL // alloc_desc(16, 0, NULL): kmem_cache#28-oX (irq 16) // i: 48, start: 16, node: 0, owner: NULL // alloc_desc(64, 0, NULL): kmem_cache#28-oX (irq 64) desc = alloc_desc(start + i, node, owner); // desc: kmem_cache#28-oX (irq 16) // desc: kmem_cache#28-oX (irq 64) // alloc_desc(16)에서 한일: // (kmem_cache#28-oX)->kstat_irqs: pcp 4 byte 공간 // (kmem_cache#28-oX)->lock 을 이용한 spinlock 초기화 수행 // (kmem_cache#28-oX)->irq_data.irq: 16 // (kmem_cache#28-oX)->irq_data.chip: &no_irq_chip // (kmem_cache#28-oX)->irq_data.chip_data: NULL // (kmem_cache#28-oX)->irq_data.handler_data: NULL // (kmem_cache#28-oX)->irq_data.msi_desc: NULL // (kmem_cache#28-oX)->status_use_accessors: 0xc00 // (&(kmem_cache#28-oX)->irq_data)->state_use_accessors: 0x10000 // (kmem_cache#28-oX)->handle_irq: handle_bad_irq // (kmem_cache#28-oX)->depth: 1 // (kmem_cache#28-oX)->irq_count: 0 // (kmem_cache#28-oX)->irqs_unhandled: 0 // (kmem_cache#28-oX)->name: NULL // (kmem_cache#28-oX)->owner: null // [pcp0...3] (kmem_cache#28-oX)->kstat_irqs: 0 // (kmem_cache#28-oX)->irq_data.node: 0 // (kmem_cache#28-oX)->irq_data.affinity.bits[0]: 0xF // alloc_desc(64)에서 한일: // (kmem_cache#28-oX)->kstat_irqs: pcp 4 byte 공간 // (kmem_cache#28-oX)->lock 을 이용한 spinlock 초기화 수행 // (kmem_cache#28-oX)->irq_data.irq: 64 // (kmem_cache#28-oX)->irq_data.chip: &no_irq_chip // (kmem_cache#28-oX)->irq_data.chip_data: NULL // (kmem_cache#28-oX)->irq_data.handler_data: NULL // (kmem_cache#28-oX)->irq_data.msi_desc: NULL // (kmem_cache#28-oX)->status_use_accessors: 0xc00 // (&(kmem_cache#28-oX)->irq_data)->state_use_accessors: 0x10000 // (kmem_cache#28-oX)->handle_irq: handle_bad_irq // (kmem_cache#28-oX)->depth: 1 // (kmem_cache#28-oX)->irq_count: 0 // (kmem_cache#28-oX)->irqs_unhandled: 0 // (kmem_cache#28-oX)->name: NULL // (kmem_cache#28-oX)->owner: null // [pcp0...3] (kmem_cache#28-oX)->kstat_irqs: 0 // (kmem_cache#28-oX)->irq_data.node: 0 // (kmem_cache#28-oX)->irq_data.affinity.bits[0]: 0xF // desc: kmem_cache#28-oX (irq 16) // desc: kmem_cache#28-oX (irq 64) if (!desc) goto err; mutex_lock(&sparse_irq_lock); // sparse_irq_lock을 이용한 mutex lock 수행 // sparse_irq_lock을 이용한 mutex lock 수행 // i: 0, start: 16, desc: kmem_cache#28-oX (irq 16), irq_insert_desc(16, kmem_cache#28-oX (irq 16)): 0 // i: 48, start: 16, desc: kmem_cache#28-oX (irq 64), irq_insert_desc(48, kmem_cache#28-oX (irq 64)): 0 irq_insert_desc(start + i, desc); // 2014/11/15 종료 // 2014/11/22 시작 // irq_insert_desc(16)에서 한일: // (kmem_cache#20-o0)->count: 16 // (kmem_cache#20-o0)->slots[16]: kmem_cache#28-o16 (irq 16) mutex_unlock(&sparse_irq_lock); // sparse_irq_lock을 이용한 mutex unlock 수행 // sparse_irq_lock을 이용한 mutex unlock 수행 // i: 1 ... 143 까지 루프 수행 } /* // 위 loop의 수행 결과 // // irq 16 ~ 159를 위한 struct irq_desc 메모리를 할당 받아 초기화 수행 // (kmem_cache#28-oX (irq 16...159))->lock 을 이용한 spinlock 초기화 수행 // (kmem_cache#28-oX (irq 16...159))->status_use_accessors: 0xc00 // (kmem_cache#28-oX (irq 16...159))->handle_irq: handle_bad_irq // (kmem_cache#28-oX (irq 16...159))->depth: 1 // (kmem_cache#28-oX (irq 16...159))->irq_count: 0 // (kmem_cache#28-oX (irq 16...159))->irqs_unhandled: 0 // (kmem_cache#28-oX (irq 16...159))->name: NULL // (kmem_cache#28-oX (irq 16...159))->owner: null // (kmem_cache#28-oX (irq 16...159))->kstat_irqs: pcp 4 byte 공간 // [pcp0...3] (kmem_cache#28-oX (irq 16...159))->kstat_irqs: 0 // (kmem_cache#28-oX (irq 16...159))->irq_data.irq: 16...159 // (kmem_cache#28-oX (irq 16...159))->irq_data.chip: &no_irq_chip // (kmem_cache#28-oX (irq 16...159))->irq_data.chip_data: NULL // (kmem_cache#28-oX (irq 16...159))->irq_data.handler_data: NULL // (kmem_cache#28-oX (irq 16...159))->irq_data.msi_desc: NULL // (kmem_cache#28-oX (irq 16...159))->irq_data.state_use_accessors: 0x10000 // (kmem_cache#28-oX (irq 16...159))->irq_data.node: 0 // (kmem_cache#28-oX (irq 16...159))->irq_data.affinity.bits[0]: 0xF // // radix tree의 root node: &irq_desc_tree 값을 변경 // (&irq_desc_tree)->rnode: kmem_cache#20-o1 (RADIX_LSB: 1) // (&irq_desc_tree)->height: 2 // // (kmem_cache#20-o1)->height: 2 // (kmem_cache#20-o1)->count: 3 // (kmem_cache#20-o1)->parent: NULL // (kmem_cache#20-o1)->slots[0]: kmem_cache#20-o0 (radix height 1 관리 주소) // (kmem_cache#20-o1)->slots[1]: kmem_cache#20-o2 (radix height 1 관리 주소) // (kmem_cache#20-o1)->slots[2]: kmem_cache#20-o3 (radix height 1 관리 주소) // // (kmem_cache#20-o0)->height: 1 // (kmem_cache#20-o0)->count: 63 // (kmem_cache#20-o0)->parent: kmem_cache#20-o1 (RADIX_LSB: 1) // (kmem_cache#20-o0)->slots[0...63]: kmem_cache#28-oX (irq 0...63) // // (kmem_cache#20-o2)->height: 1 // (kmem_cache#20-o2)->count: 63 // (kmem_cache#20-o2)->parent: kmem_cache#20-o1 (RADIX_LSB: 1) // (kmem_cache#20-o2)->slots[0...63]: kmem_cache#28-oX (irq 63...127) // // (kmem_cache#20-o3)->height: 1 // (kmem_cache#20-o3)->count: 32 // (kmem_cache#20-o3)->parent: kmem_cache#20-o1 (RADIX_LSB: 1) // (kmem_cache#20-o3)->slots[0...63]: kmem_cache#28-oX (irq 127...159) // // 위 loop의 수행 결과를 나타낸 그림 // // (&irq_desc_tree)->rnode --> +-----------------------+ // | radix_tree_node | // | (kmem_cache#20-o1) | // +-----------------------+ // | height: 2 | count: 3 | // +-----------------------+ // | radix_tree_node 0 ~ 2 | // +-----------------------+ // / | \ // slot: 0 / slot: 1 | \ slot: 2 // +-----------------------+ +-----------------------+ +-----------------------+ // | radix_tree_node | | radix_tree_node | | radix_tree_node | // | (kmem_cache#20-o0) | | (kmem_cache#20-o2) | | (kmem_cache#20-o3) | // +-----------------------+ +-----------------------+ +-----------------------+ // | height: 1 | count: 64 | | height: 1 | count: 64 | | height: 1 | count: 32 | // +-----------------------+ +-----------------------+ +-----------------------+ // | irq 0 ~ 63 | | irq 64 ~ 127 | | irq 128 ~ 159 | // +-----------------------+ +-----------------------+ +-----------------------+ */ // start: 16 return start; // return 16 err: for (i--; i >= 0; i--) free_desc(start + i); mutex_lock(&sparse_irq_lock); bitmap_clear(allocated_irqs, start, cnt); mutex_unlock(&sparse_irq_lock); return -ENOMEM; }
void TimerReset(void) { // Mark all descriptors as inactive for (int i=0; i<NUM_DESCS; i++) free_desc(i); }