/***************************************************************************** * _ddekit_minix_queue_msg * ****************************************************************************/ static void _ddekit_minix_queue_msg(struct ddekit_minix_msg_q *mq, message *m) { int full; full = ddekit_sem_down_try(mq->msg_w_sem); if (full) { /* Our message queue is full... inform the sender. */ int result; DDEBUG_MSG_WARN("Receive queue is full. Ommiting ingoing msg.\n"); m->m_type = TASK_REPLY; m->REP_STATUS = EAGAIN; result = asynsend(m->m_source, m); if (result != 0) { ddekit_panic("unable to send reply to %d: %d\n", m->m_source, result); } } else { /* queue the message */ memcpy(&mq->messages[mq->msg_w_pos], m, sizeof(message)); if (++mq->msg_w_pos == MESSAGE_QUEUE_SIZE) { mq->msg_w_pos = 0; } DDEBUG_MSG_VERBOSE("ddekit_minix_queue_msg: queueing msg %x\n", m->m_type); ddekit_sem_up(mq->msg_r_sem); } }
PRIVATE void dispatcher_thread(void *unused) { /* * Gets all messages and dispatches them. * * NOTE: this thread runs only when no other ddekit is * ready. So please take care that youre threads * leave some time for the others! */ message m; int r; int i; _ddekit_thread_set_myprio(0); for( ; ; ) { /* Trigger a timer interrupt at each loop iteration */ _ddekit_timer_update(); /* Wait for messages */ if ((r = sef_receive(ANY, &m)) != 0) { ddekit_panic("ddekit", "sef_receive failed", r); } _ddekit_timer_interrupt(); _ddekit_thread_wakeup_sleeping(); if (is_notify(m.m_type)) { switch (_ENDPOINT_P(m.m_source)) { case HARDWARE: for (i =0 ; i < 32 ; i++) { if(m.NOTIFY_ARG & (1 << i)) { _ddekit_interrupt_trigger(i); } } break; case CLOCK: _ddekit_timer_pending = 0; break; default: ddekit_thread_schedule(); } } else { /* * I don't know how to handle this msg, * but maybe we have a msg queue which can * handle this msg. */ ddekit_minix_queue_msg(&m); } } }
/****************************************************************************** * ddekit_lock_lock * *****************************************************************************/ PUBLIC void ddekit_lock_lock (ddekit_lock_t *mtx) { if ((*mtx)->owner == NULL) { (*mtx)->owner = ddekit_thread_myself(); } else { if ((*mtx)->wait_queue == NULL) { (*mtx)->wait_queue = ddekit_thread_myself(); } else { ddekit_thread_t *pos = (*mtx)->wait_queue; while(pos->next != NULL) { pos = pos->next; } pos->next = ddekit_thread_myself(); } _ddekit_thread_schedule(); if ((*mtx)->owner != NULL) { _ddekit_print_backtrace((*mtx)->owner); _ddekit_print_backtrace(ddekit_thread_myself()); ddekit_panic("owner!=NULL: %s (I am %s)\n", (*mtx)->owner->name, ddekit_thread_myself()->name); } (*mtx)->owner = ddekit_thread_myself(); } }
void dad_announce_disk(dad_disk_t *dsk) { ddekit_lock_lock(&ann_buf_lock); if (buffer_announcements) { if (dbg_this) ddekit_printf("buffering announcement of %s (%d sects with %d Bytes)\n", dsk->name, dsk->sects, dsk->sectsize); dsk->next = NULL; if (! ann_buffer) ann_buffer = dsk; else { dad_disk_t *d = ann_buffer; while (d->next) d=d->next; d->next = dsk; } } else { if (disk_announce) { if (dbg_this) ddekit_printf("announcing %s (%d sects with %d Bytes)\n", dsk->name, dsk->sects, dsk->sectsize); disk_announce(dsk); } else ddekit_panic("disk found, but no announcing function set yet"); } ddekit_lock_unlock(&ann_buf_lock); }
void ddekit_pci_init_only_one(int skip) { /* * If skip is not PCI_TAKE_ALL this function will skip skip PCI DEVICES * and than only take on PCI device. */ int res, count, more, take_all = 0; if (skip == -1) { take_all = 1; } DDEBUG_MSG_INFO("Initializing PCI subsystem..."); pci_init(); /* * Iterate the PCI-bus */ more = 1; for (count = 0 ; count < PCI_MAX_DEVS ; count++) { struct ddekit_pci_dev *d = &pci_devs[count]; if (more) { if ( count==0 ) { res = pci_first_dev(&d->devind, &d->vid, &d->did); } else { d->devind = pci_devs[count-1].devind; res = pci_next_dev(&d->devind, &d->vid, &d->did); } if (res && d->devind!=0 && (take_all || skip == 0)) { DDEBUG_MSG_VERBOSE("Found pci device: " "(ind: %x, vid: %x, did: %x) " "mapped to slot %x", d->devind, d->vid, d->did, count); d->slot = count; d->bus = 0; d->func = 0; res = pci_reserve_ok(d->devind); if (res != 0) { ddekit_panic("ddekit_pci_init_only_one: " "pci_reserve_ok failed (%d)\n",res); } } else { /* no more PCI devices */ DDEBUG_MSG_VERBOSE("Found %d PCI devices.", count); d->devind = -1; more = 0; } /*if (res) */ } else { d->devind = -1; } if (!take_all) { skip--; } } }