Subversion Repositories HelenOS

Rev

Rev 3071 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2005 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup sparc64
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch/cpu_family.h>
  36. #include <cpu.h>
  37. #include <arch.h>
  38. #include <genarch/ofw/ofw_tree.h>
  39. #include <arch/drivers/tick.h>
  40. #include <print.h>
  41. #include <arch/cpu_node.h>
  42.  
  43. /**
  44.  * Finds out the clock frequency of the current CPU.
  45.  *
  46.  * @param node  node representing the current CPU in the OFW tree
  47.  * @return  clock frequency if "node" is the current CPU and no error
  48.  *      occurs, -1 if "node" is not the current CPU or on error
  49.  */
  50. static int find_cpu_frequency(ofw_tree_node_t *node)
  51. {
  52.     ofw_tree_property_t *prop;
  53.     uint32_t mid;
  54.  
  55.     /* 'upa-portid' for US, 'portid' for US-III, 'cpuid' for US-IV */
  56.     prop = ofw_tree_getprop(node, "upa-portid");
  57.     if ((!prop) || (!prop->value))
  58.         prop = ofw_tree_getprop(node, "portid");
  59.     if ((!prop) || (!prop->value))
  60.         prop = ofw_tree_getprop(node, "cpuid");
  61.    
  62.     if (prop && prop->value) {
  63.         mid = *((uint32_t *) prop->value);
  64.         if (mid == CPU->arch.mid) {
  65.             prop = ofw_tree_getprop(node, "clock-frequency");
  66.             if (prop && prop->value) {
  67.                 return *((uint32_t *) prop->value);
  68.             }
  69.         }
  70.     }
  71.    
  72.     return -1;
  73. }
  74.  
  75. /** Perform sparc64 specific initialization of the processor structure for the
  76.  * current processor.
  77.  */
  78. void cpu_arch_init(void)
  79. {
  80.     ofw_tree_node_t *node;
  81.     uint32_t clock_frequency = 0;
  82.    
  83.     CPU->arch.mid = read_mid();
  84.    
  85.     /*
  86.      * Detect processor frequency.
  87.      */
  88.     if (is_us() || is_us_iii()) {
  89.         node = ofw_tree_find_child_by_device_type(cpus_parent(), "cpu");
  90.         while (node) {
  91.             int f = find_cpu_frequency(node);
  92.             if (f != -1)
  93.                 clock_frequency = (uint32_t) f;
  94.             node = ofw_tree_find_peer_by_device_type(node, "cpu");
  95.         }
  96.     } else if (is_us_iv()) {
  97.         node = ofw_tree_find_child(cpus_parent(), "cmp");
  98.         while (node) {
  99.             int f;
  100.             f = find_cpu_frequency(
  101.                 ofw_tree_find_child(node, "cpu@0"));
  102.             if (f != -1)
  103.                 clock_frequency = (uint32_t) f;
  104.             f = find_cpu_frequency(
  105.                 ofw_tree_find_child(node, "cpu@1"));
  106.             if (f != -1)
  107.                 clock_frequency = (uint32_t) f;
  108.             node = ofw_tree_find_peer_by_name(node, "cmp");
  109.         }
  110.     }
  111.        
  112.     CPU->arch.clock_frequency = clock_frequency;
  113.     tick_init();
  114. }
  115.  
  116. /** Read version information from the current processor. */
  117. void cpu_identify(void)
  118. {
  119.     CPU->arch.ver.value = ver_read();
  120. }
  121.  
  122. /** Print version information for a processor.
  123.  *
  124.  * This function is called by the bootstrap processor.
  125.  *
  126.  * @param m Processor structure of the CPU for which version information is to
  127.  *  be printed.
  128.  */
  129. void cpu_print_report(cpu_t *m)
  130. {
  131.     char *manuf, *impl;
  132.  
  133.     switch (m->arch.ver.manuf) {
  134.     case MANUF_FUJITSU:
  135.         manuf = "Fujitsu";
  136.         break;
  137.     case MANUF_ULTRASPARC:
  138.         manuf = "UltraSPARC";
  139.         break;
  140.     case MANUF_SUN:
  141.             manuf = "Sun";
  142.         break;
  143.     default:
  144.         manuf = "Unknown";
  145.         break;
  146.     }
  147.    
  148.     switch (CPU->arch.ver.impl) {
  149.     case IMPL_ULTRASPARCI:
  150.         impl = "UltraSPARC I";
  151.         break;
  152.     case IMPL_ULTRASPARCII:
  153.         impl = "UltraSPARC II";
  154.         break;
  155.     case IMPL_ULTRASPARCII_I:
  156.         impl = "UltraSPARC IIi";
  157.         break;
  158.     case IMPL_ULTRASPARCII_E:
  159.         impl = "UltraSPARC IIe";
  160.         break;
  161.     case IMPL_ULTRASPARCIII:
  162.         impl = "UltraSPARC III";
  163.         break;
  164.     case IMPL_ULTRASPARCIII_PLUS:
  165.         impl = "UltraSPARC III+";
  166.         break;
  167.     case IMPL_ULTRASPARCIII_I:
  168.         impl = "UltraSPARC IIIi";
  169.         break;
  170.     case IMPL_ULTRASPARCIV:
  171.         impl = "UltraSPARC IV";
  172.         break;
  173.     case IMPL_ULTRASPARCIV_PLUS:
  174.         impl = "UltraSPARC IV+";
  175.         break;
  176.     case IMPL_SPARC64V:
  177.         impl = "SPARC 64V";
  178.         break;
  179.     default:
  180.         impl = "Unknown";
  181.         break;
  182.     }
  183.  
  184.     printf("cpu%d: manuf=%s, impl=%s, mask=%d (%d MHz)\n", m->id, manuf,
  185.         impl, m->arch.ver.mask, m->arch.clock_frequency / 1000000);
  186. }
  187.  
  188. /** @}
  189.  */
  190.