Changeset e5424e9 in mainline for uspace/lib/c/generic/irc.c


Ignore:
Timestamp:
2014-07-18T08:50:36Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ebc9c2c
Parents:
869d936
Message:

Defer connecting IRC service until actually needed. This allows the driver to be loaded even in its absence.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/irc.c

    r869d936 re5424e9  
    3939#include <irc.h>
    4040#include <ns.h>
     41#include <sysinfo.h>
    4142
    4243static async_sess_t *irc_sess;
    43 
    44 /** Enable interrupt.
    45  *
    46  * @param irq   IRQ number
    47  */
    48 void irc_enable_interrupt(int irq)
    49 {
    50         async_exch_t *exch = async_exchange_begin(irc_sess);
    51         async_msg_1(exch, IRC_ENABLE_INTERRUPT, irq);
    52         async_exchange_end(exch);
    53 }
    54 
    55 /** Disable interrupt.
    56  *
    57  * @param irq   IRQ number
    58  */
    59 void irc_disable_interrupt(int irq)
    60 {
    61         async_exch_t *exch = async_exchange_begin(irc_sess);
    62         async_msg_1(exch, IRC_CLEAR_INTERRUPT, irq);
    63         async_exchange_end(exch);
    64 }
    6544
    6645/** Connect to IRC service.
     
    6847 * @return      EOK on success, EIO on failure
    6948 */
    70 int irc_init(void)
     49static int irc_init(void)
    7150{
     51        sysarg_t apic;
     52        sysarg_t i8259;
     53
    7254        assert(irc_sess == NULL);
    7355
    74         irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_IRC,
    75             0, 0);
     56        if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
     57            || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
     58                irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
     59                    SERVICE_IRC, 0, 0);
     60        }
     61
    7662        if (irc_sess == NULL)
    7763                return EIO;
     
    8066}
    8167
     68/** Enable interrupt.
     69 *
     70 * @param irq   IRQ number
     71 */
     72int irc_enable_interrupt(int irq)
     73{
     74        int rc;
     75
     76        if (irc_sess == NULL) {
     77                rc = irc_init();
     78                if (rc != EOK)
     79                        return rc;
     80        }
     81
     82        async_exch_t *exch = async_exchange_begin(irc_sess);
     83        rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
     84        async_exchange_end(exch);
     85
     86        return rc;
     87}
     88
     89
     90/** Disable interrupt.
     91 *
     92 * @param irq   IRQ number
     93 */
     94int irc_disable_interrupt(int irq)
     95{
     96        int rc;
     97
     98        if (irc_sess == NULL) {
     99                rc = irc_init();
     100                if (rc != EOK)
     101                        return rc;
     102        }
     103
     104        async_exch_t *exch = async_exchange_begin(irc_sess);
     105        rc = async_req_1_0(exch, IRC_CLEAR_INTERRUPT, irq);
     106        async_exchange_end(exch);
     107
     108        return rc;
     109}
     110
    82111/** @}
    83112 */
Note: See TracChangeset for help on using the changeset viewer.