Changeset 0ffa3ef5 in mainline for genarch/src/ofw/ofw.c
- Timestamp:
- 2006-07-10T20:57:30Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 11675207
- Parents:
- 7f1c620
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
genarch/src/ofw/ofw.c
r7f1c620 r0ffa3ef5 39 39 #include <arch/types.h> 40 40 41 ofw_entry ofw; 41 uintptr_t ofw_cif; /**< OpenFirmware Client Interface address. */ 42 42 43 43 phandle ofw_chosen; 44 ihandle ofw_stdin;45 44 ihandle ofw_stdout; 45 ihandle ofw_mmu; 46 46 47 47 void ofw_init(void) … … 51 51 ofw_done(); 52 52 53 if (ofw_get_property(ofw_chosen, "stdin", &ofw_stdin, sizeof(ofw_stdin)) <= 0)54 ofw_stdin = 0;55 56 53 if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) 57 54 ofw_stdout = 0; 55 56 if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) 57 ofw_mmu = 0; 58 58 } 59 59 60 60 void ofw_done(void) 61 61 { 62 (void) ofw_call("exit", 0, 0);62 (void) ofw_call("exit", 0, 1, NULL); 63 63 cpu_halt(); 64 64 } 65 65 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 */ 75 ofw_arg_t ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) 67 76 { 68 77 va_list list; … … 74 83 args.nret = nret; 75 84 76 va_start(list, nret);85 va_start(list, rets); 77 86 for (i = 0; i < nargs; i++) 78 87 args.args[i] = va_arg(list, ofw_arg_t); … … 82 91 args.args[i + nargs] = 0; 83 92 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 86 98 return args.args[nargs]; 87 99 } … … 92 104 return; 93 105 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); 114 107 } 115 108 116 109 phandle ofw_find_device(const char *name) 117 110 { 118 return (phandle) ofw_call("finddevice", 1, 1, name);111 return (phandle) ofw_call("finddevice", 1, 1, NULL, name); 119 112 } 120 113 121 int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen)114 int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen) 122 115 { 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 */ 126 void *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]); 124 146 } 125 147 126 148 void *ofw_claim(const void *addr, const int size, const int align) 127 149 { 128 return (void *) ofw_call("claim", 3, 1, addr, size, align);150 return (void *) ofw_call("claim", 3, 1, NULL, addr, size, align); 129 151 } 130 152
Note:
See TracChangeset
for help on using the changeset viewer.