1 /* $Id: p1275.c,v 1.22 2001/10/18 09:40:00 davem Exp $
2 * p1275.c: Sun IEEE 1275 PROM low level interface routines
4 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 #include <linux/kernel.h>
8 #include <linux/init.h>
9 #include <linux/sched.h>
10 #include <linux/smp.h>
11 #include <linux/string.h>
12 #include <linux/spinlock.h>
14 #include <asm/openprom.h>
15 #include <asm/oplib.h>
16 #include <asm/system.h>
17 #include <asm/spitfire.h>
18 #include <asm/pstate.h>
21 long prom_callback; /* 0x00 */
22 void (*prom_cif_handler)(long *); /* 0x08 */
23 unsigned long prom_cif_stack; /* 0x10 */
24 unsigned long prom_args [23]; /* 0x18 */
25 char prom_buffer [3000];
28 extern void prom_world(int);
30 extern void prom_cif_interface(void);
31 extern void prom_cif_callback(void);
33 static inline unsigned long spitfire_get_primary_context(void)
37 __asm__ __volatile__("ldxa [%1] %2, %0"
39 : "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
44 * This provides SMP safety on the p1275buf. prom_callback() drops this lock
45 * to allow recursuve acquisition.
47 DEFINE_SPINLOCK(prom_entry_lock);
49 long p1275_cmd (char *service, long fmt, ...)
57 p = p1275buf.prom_buffer;
58 BUG_ON((spitfire_get_primary_context() & CTX_NR_MASK) != 0);
60 spin_lock_irqsave(&prom_entry_lock, flags);
62 p1275buf.prom_args[0] = (unsigned long)p; /* service */
64 p = (char *)(((long)(strchr (p, 0) + 8)) & ~7);
65 p1275buf.prom_args[1] = nargs = (fmt & 0x0f); /* nargs */
66 p1275buf.prom_args[2] = nrets = ((fmt & 0xf0) >> 4); /* nrets */
69 for (i = 0; i < nargs; i++, attrs >>= 3) {
70 switch (attrs & 0x7) {
71 case P1275_ARG_NUMBER:
72 p1275buf.prom_args[i + 3] =
73 (unsigned)va_arg(list, long);
75 case P1275_ARG_IN_64B:
76 p1275buf.prom_args[i + 3] =
77 va_arg(list, unsigned long);
79 case P1275_ARG_IN_STRING:
80 strcpy (p, va_arg(list, char *));
81 p1275buf.prom_args[i + 3] = (unsigned long)p;
82 p = (char *)(((long)(strchr (p, 0) + 8)) & ~7);
84 case P1275_ARG_OUT_BUF:
85 (void) va_arg(list, char *);
86 p1275buf.prom_args[i + 3] = (unsigned long)p;
87 x = va_arg(list, long);
89 p = (char *)(((long)(p + (int)x + 7)) & ~7);
90 p1275buf.prom_args[i + 3] = x;
92 case P1275_ARG_IN_BUF:
93 q = va_arg(list, char *);
94 p1275buf.prom_args[i + 3] = (unsigned long)p;
95 x = va_arg(list, long);
97 memcpy (p, q, (int)x);
98 p = (char *)(((long)(p + (int)x + 7)) & ~7);
99 p1275buf.prom_args[i + 3] = x;
101 case P1275_ARG_OUT_32B:
102 (void) va_arg(list, char *);
103 p1275buf.prom_args[i + 3] = (unsigned long)p;
106 case P1275_ARG_IN_FUNCTION:
107 p1275buf.prom_args[i + 3] =
108 (unsigned long)prom_cif_callback;
109 p1275buf.prom_callback = va_arg(list, long);
116 prom_cif_interface();
121 for (i = 0; i < nargs; i++, attrs >>= 3) {
122 switch (attrs & 0x7) {
123 case P1275_ARG_NUMBER:
124 (void) va_arg(list, long);
126 case P1275_ARG_IN_STRING:
127 (void) va_arg(list, char *);
129 case P1275_ARG_IN_FUNCTION:
130 (void) va_arg(list, long);
132 case P1275_ARG_IN_BUF:
133 (void) va_arg(list, char *);
134 (void) va_arg(list, long);
137 case P1275_ARG_OUT_BUF:
138 p = va_arg(list, char *);
139 x = va_arg(list, long);
140 memcpy (p, (char *)(p1275buf.prom_args[i + 3]), (int)x);
143 case P1275_ARG_OUT_32B:
144 p = va_arg(list, char *);
145 memcpy (p, (char *)(p1275buf.prom_args[i + 3]), 32);
150 x = p1275buf.prom_args [nargs + 3];
152 spin_unlock_irqrestore(&prom_entry_lock, flags);
157 void prom_cif_init(void *cif_handler, void *cif_stack)
159 p1275buf.prom_cif_handler = (void (*)(long *))cif_handler;
160 p1275buf.prom_cif_stack = (unsigned long)cif_stack;