Changeset 0ffa3ef5 in mainline for genarch/src/ofw/ofw.c


Ignore:
Timestamp:
2006-07-10T20:57:30Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
11675207
Parents:
7f1c620
Message:

Sync OpenFirmware functionality with boot.
Random cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • genarch/src/ofw/ofw.c

    r7f1c620 r0ffa3ef5  
    3939#include <arch/types.h>
    4040
    41 ofw_entry ofw;
     41uintptr_t ofw_cif;      /**< OpenFirmware Client Interface address. */
    4242
    4343phandle ofw_chosen;
    44 ihandle ofw_stdin;
    4544ihandle ofw_stdout;
     45ihandle ofw_mmu;
    4646
    4747void ofw_init(void)
     
    5151                ofw_done();
    5252       
    53         if (ofw_get_property(ofw_chosen, "stdin",  &ofw_stdin, sizeof(ofw_stdin)) <= 0)
    54                 ofw_stdin = 0;
    55                
    5653        if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
    5754                ofw_stdout = 0;
     55
     56        if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0)
     57                ofw_mmu = 0;
    5858}
    5959
    6060void ofw_done(void)
    6161{
    62         (void) ofw_call("exit", 0, 0);
     62        (void) ofw_call("exit", 0, 1, NULL);
    6363        cpu_halt();
    6464}
    6565
    66 unative_t ofw_call(const char *service, const int nargs, const int nret, ...)
     66/** Perform a call to OpenFirmware client interface.
     67 *
     68 * @param service String identifying the service requested.
     69 * @param nargs Number of input arguments.
     70 * @param nret Number of output arguments. This includes the return value.
     71 * @param rets Buffer for output arguments or NULL. The buffer must accomodate nret - 1 items.
     72 *
     73 * @return Return value returned by the client interface.
     74 */
     75ofw_arg_t ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
    6776{
    6877        va_list list;
     
    7483        args.nret = nret;
    7584       
    76         va_start(list, nret);
     85        va_start(list, rets);
    7786        for (i = 0; i < nargs; i++)
    7887                args.args[i] = va_arg(list, ofw_arg_t);
     
    8291                args.args[i + nargs] = 0;
    8392       
    84         ofw(&args);
    85        
     93        (void) ofw(&args);
     94
     95        for (i = 1; i < nret; i++)
     96                rets[i - 1] = args.args[i + nargs];
     97
    8698        return args.args[nargs];
    8799}
     
    92104                return;
    93105       
    94         (void) ofw_call("write", 3, 1, ofw_stdout, &ch, 1);
    95 }
    96 
    97 /** Read character from OFW's input.
    98  *
    99  * This call is non-blocking.
    100  *
    101  * @return 0 if no character was read, character read otherwise.
    102  */
    103 char ofw_getchar(void)
    104 {
    105         char ch;
    106 
    107         if (ofw_stdin == 0)
    108                 return 0;
    109        
    110         if (ofw_call("read", 3, 1, ofw_stdin, &ch, 1) == 1)
    111                 return ch;
    112         else
    113                 return 0;
     106        (void) ofw_call("write", 3, 1, NULL, ofw_stdout, &ch, 1);
    114107}
    115108
    116109phandle ofw_find_device(const char *name)
    117110{
    118         return (phandle) ofw_call("finddevice", 1, 1, name);
     111        return (phandle) ofw_call("finddevice", 1, 1, NULL, name);
    119112}
    120113
    121 int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen)
     114int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
    122115{
    123         return (int) ofw_call("getprop", 4, 1, device, name, buf, buflen);
     116        return (int) ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
     117}
     118
     119/** Translate virtual address to physical address using OpenFirmware.
     120 *
     121 * Use this function only when OpenFirmware is in charge.
     122 *
     123 * @param virt Virtual address.
     124 * @return NULL on failure or physical address on success.
     125 */
     126void *ofw_translate(const void *virt)
     127{
     128        ofw_arg_t result[4];
     129        int shift;
     130       
     131        if (!ofw_mmu)
     132                return NULL;
     133       
     134        if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu, virt) != 0)
     135                return NULL;
     136
     137        if (result[0] != -1)
     138                return NULL;
     139                                                               
     140        if (sizeof(unative_t) == 8)
     141                shift = 32;
     142        else
     143                shift = 0;
     144       
     145        return (void *) ((result[2]<<shift)|result[3]);
    124146}
    125147
    126148void *ofw_claim(const void *addr, const int size, const int align)
    127149{
    128         return (void *) ofw_call("claim", 3, 1, addr, size, align);
     150        return (void *) ofw_call("claim", 3, 1, NULL, addr, size, align);
    129151}
    130152
Note: See TracChangeset for help on using the changeset viewer.