4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <fcode/private.h>
34 #include <fcode/log.h>
36 #include <fcdriver/fcdriver.h>
39 mem_map_in(fcode_env_t
*env
, fstack_t hi
, fstack_t lo
, fstack_t len
)
41 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
43 fstack_t mcookie
= NULL
;
44 char *service
= "map-in";
49 * The calculation of the offset, lo and len are left here
50 * due to historical precedence.
53 offset
= lo
& PAGEOFFSET
;
55 len
= (len
+ offset
+ PAGEOFFSET
) & PAGEMASK
;
57 error
= fc_run_priv(pdp
->common
, service
, 3, 1, fc_size2cell(len
),
58 fc_uint32_t2cell(hi
), fc_uint32_t2cell(lo
), &virt
);
61 throw_from_fclib(env
, 1, "gp2:%s: failed\n", service
);
63 mcookie
= mapping_to_mcookie(virt
, len
, NULL
, NULL
);
66 throw_from_fclib(env
, 1, "gp2:%s: mapping_to_mcookie failed\n",
71 debug_msg(DEBUG_REG_ACCESS
, "gp2:%s: %llx -> %x\n", service
,
72 (uint64_t)virt
, (uint32_t)mcookie
);
78 mem_map_out(fcode_env_t
*env
, fstack_t mcookie
, fstack_t len
)
80 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
82 char *service
= "map-out";
87 * The calculation of the offset, lo and len are left here
88 * due to historical precedence.
91 offset
= mcookie
& PAGEOFFSET
;
93 len
= (len
+ offset
+ PAGEOFFSET
) & PAGEMASK
;
95 if (!is_mcookie(mcookie
)) {
96 log_message(MSG_ERROR
, "gp2:%s: %x not an mcookie!\n",
97 service
, (int)mcookie
);
100 virt
= mcookie_to_addr(mcookie
);
101 debug_msg(DEBUG_REG_ACCESS
, "gp2:%s: %x -> %llx\n", service
,
102 (int)mcookie
, (uint64_t)virt
);
103 delete_mapping(mcookie
);
106 error
= fc_run_priv(pdp
->common
, service
, 2, 0, fc_size2cell(len
),
109 log_message(MSG_ERROR
, "gp2:%s: failed\n", service
);
113 do_get_portid(fcode_env_t
*env
)
115 fstack_t phi
, plo
, portid
;
116 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
118 CHECK_DEPTH(env
, 2, "gp2:get-portid");
122 portid
= ((plo
& 0xff800000) >> 23) | ((phi
& 1) << 9);
123 debug_msg(DEBUG_REG_ACCESS
, "gp2:get-portid ( %x %x ) -> %x\n",
124 (int)phi
, (int)plo
, (int)portid
);
129 do_map_in(fcode_env_t
*env
)
131 fstack_t phi
, pmid
, plo
, len
, addr
;
133 CHECK_DEPTH(env
, 3, "gp2:map-in");
137 addr
= mem_map_in(env
, phi
, plo
, len
);
142 do_map_out(fcode_env_t
*env
)
146 CHECK_DEPTH(env
, 2, "gp2:map-out");
149 mem_map_out(env
, addr
, len
);
153 do_encode_unit(fcode_env_t
*env
)
156 fstack_t hi
, mid
, lo
;
159 CHECK_DEPTH(env
, 2, "gp2:encode-unit");
163 hi
= (hi
& 0x00000001); /* get high order agent id bit */
164 id
= (hi
<< 9) | (lo
>> 23); /* build extended agent id */
165 off
= lo
& 0x7fffff; /* build config offset */
168 sprintf(enc_buf
, "%x,%x", id
, off
);
170 sprintf(enc_buf
, "%x", id
);
172 debug_msg(DEBUG_REG_ACCESS
, "gp2:encode_unit ( %x %x ) -> '%s'\n",
173 (int)hi
, (int)lo
, enc_buf
);
174 push_a_string(env
, STRDUP(enc_buf
));
178 do_decode_unit(fcode_env_t
*env
)
184 CHECK_DEPTH(env
, 2, "gp2:decode-unit");
185 buf
= pop_a_string(env
, NULL
);
186 if (sscanf(buf
, "%x,%x", &agent
, &offset
) != 2) {
187 if (sscanf(buf
, "%x", &agent
) != 1) {
188 throw_from_fclib(env
, 1, "gp2:decode_unit:%s", buf
);
192 lo
= offset
| (agent
<< 23);
193 hi
= (agent
>> 9) | 0x400;
194 debug_msg(DEBUG_REG_ACCESS
, "gp2:decode_unit ( '%s' ) -> %x %x\n", buf
,
201 do_claim_addr(fcode_env_t
*env
)
203 fstack_t portid
, bar
, align
, type
, size_hi
, size_lo
;
205 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
206 char *service
= "claim-address";
209 CHECK_DEPTH(env
, 6, "gp2:claim-address");
217 error
= fc_run_priv(pdp
->common
, service
, 6, 2,
218 fc_int2cell(portid
), fc_int2cell(bar
), fc_int2cell(align
),
219 fc_int2cell(type
), fc_int2cell(size_hi
), fc_int2cell(size_lo
),
223 throw_from_fclib(env
, 1, "gp2:%s: failed\n", service
);
225 debug_msg(DEBUG_REG_ACCESS
,
226 "gp2:%s ( %x %x %x %x %x %x ) -> %x %x\n", service
, (int)portid
,
227 (int)bar
, (int)align
, (int)type
, (int)size_hi
, (int)size_lo
,
228 (uint32_t)hi
, (uint32_t)lo
);
230 PUSH(DS
, (uint32_t)lo
);
231 PUSH(DS
, (uint32_t)hi
);
235 do_master_interrupt(fcode_env_t
*env
)
240 CHECK_DEPTH(env
, 2, "gp2:master-interrput");
244 debug_msg(DEBUG_REG_ACCESS
, "gp2:master-interrupt ( %x %x ) -> %x\n",
245 portid
, xt
, (int)FALSE
);
249 do_register_vectory_entry(fcode_env_t
*env
)
253 CHECK_DEPTH(env
, 3, "gp2:register-vector-entry");
258 debug_msg(DEBUG_REG_ACCESS
, "gp2:register-vector-entry ( %x %x %x ) ->"
259 " %x\n", ign
, ino
, level
, (int)FALSE
);
263 do_get_interrupt_target(fcode_env_t
*env
)
268 debug_msg(DEBUG_REG_ACCESS
, "gp2:get-interrupt-target ( ) -> %x\n",
273 do_device_id(fcode_env_t
*env
)
275 fstack_t phi
, plo
, addr
;
277 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
281 CHECK_DEPTH(env
, 2, "gp2:device-id");
293 virtaddr
= mcookie_to_addr(addr
);
295 /* Try to read the wci_id register */
296 rc
= fc_run_priv(pdp
->common
, "rx@", 1, 1, virtaddr
+ 0xe0,
299 mem_map_out(env
, addr
, 0x100);
302 * Get the part id from the jtag ID register
304 parid
= ((wci_id_reg
>> 12) & 0xffff);
306 if (!rc
&& parid
== 0x4478) {
307 debug_msg(DEBUG_FIND_FCODE
, "gp2: do_device_id: gp2-wci\n");
308 push_a_string(env
, "SUNW,wci");
310 debug_msg(DEBUG_FIND_FCODE
, "gp2: do_device_id: gp2-pci\n");
311 push_a_string(env
, "gp2-pci");
320 fcode_env_t
*env
= initial_env
;
323 ASSERT(env
->current_device
);
326 create_int_prop(env
, "#address-cells", 2);
328 FORTH(0, "map-in", do_map_in
);
329 FORTH(0, "get-portid", do_get_portid
);
330 FORTH(0, "map-out", do_map_out
);
331 FORTH(0, "decode-unit", do_decode_unit
);
332 FORTH(0, "encode-unit", do_encode_unit
);
333 FORTH(0, "claim-address", do_claim_addr
);
334 FORTH(0, "master-interrupt", do_master_interrupt
);
335 FORTH(0, "register-vector-entry", do_register_vectory_entry
);
336 FORTH(0, "get-interrupt-target", do_get_interrupt_target
);
337 FORTH(0, "device-id", do_device_id
);
339 install_dma_methods(env
);