Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * SCLP early driver
0004  *
0005  * Copyright IBM Corp. 2013
0006  */
0007 
0008 #define KMSG_COMPONENT "sclp_early"
0009 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0010 
0011 #include <linux/errno.h>
0012 #include <linux/memblock.h>
0013 #include <asm/ctl_reg.h>
0014 #include <asm/sclp.h>
0015 #include <asm/ipl.h>
0016 #include <asm/setup.h>
0017 #include <asm/facility.h>
0018 #include "sclp_sdias.h"
0019 #include "sclp.h"
0020 
0021 static struct sclp_ipl_info sclp_ipl_info;
0022 
0023 struct sclp_info sclp;
0024 EXPORT_SYMBOL(sclp);
0025 
0026 static void __init sclp_early_facilities_detect(void)
0027 {
0028     struct sclp_core_entry *cpue;
0029     struct read_info_sccb *sccb;
0030     u16 boot_cpu_address, cpu;
0031 
0032     sccb = sclp_early_get_info();
0033     if (!sccb)
0034         return;
0035 
0036     sclp.facilities = sccb->facilities;
0037     sclp.has_sprp = !!(sccb->fac84 & 0x02);
0038     sclp.has_core_type = !!(sccb->fac84 & 0x01);
0039     sclp.has_gsls = !!(sccb->fac85 & 0x80);
0040     sclp.has_64bscao = !!(sccb->fac116 & 0x80);
0041     sclp.has_cmma = !!(sccb->fac116 & 0x40);
0042     sclp.has_esca = !!(sccb->fac116 & 0x08);
0043     sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
0044     sclp.has_ibs = !!(sccb->fac117 & 0x20);
0045     sclp.has_gisaf = !!(sccb->fac118 & 0x08);
0046     sclp.has_hvs = !!(sccb->fac119 & 0x80);
0047     sclp.has_kss = !!(sccb->fac98 & 0x01);
0048     sclp.has_aisii = !!(sccb->fac118 & 0x40);
0049     sclp.has_aeni = !!(sccb->fac118 & 0x20);
0050     sclp.has_aisi = !!(sccb->fac118 & 0x10);
0051     sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
0052     if (sccb->fac85 & 0x02)
0053         S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
0054     if (sccb->fac91 & 0x40)
0055         S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
0056     if (sccb->cpuoff > 134) {
0057         sclp.has_diag318 = !!(sccb->byte_134 & 0x80);
0058         sclp.has_iplcc = !!(sccb->byte_134 & 0x02);
0059     }
0060     if (sccb->cpuoff > 137)
0061         sclp.has_sipl = !!(sccb->cbl & 0x4000);
0062     sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
0063     sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
0064     sclp.rzm <<= 20;
0065     sclp.ibc = sccb->ibc;
0066 
0067     if (sccb->hamaxpow && sccb->hamaxpow < 64)
0068         sclp.hamax = (1UL << sccb->hamaxpow) - 1;
0069     else
0070         sclp.hamax = U64_MAX;
0071 
0072     if (!sccb->hcpua) {
0073         if (MACHINE_IS_VM)
0074             sclp.max_cores = 64;
0075         else
0076             sclp.max_cores = sccb->ncpurl;
0077     } else {
0078         sclp.max_cores = sccb->hcpua + 1;
0079     }
0080 
0081     boot_cpu_address = stap();
0082     cpue = (void *)sccb + sccb->cpuoff;
0083     for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
0084         if (boot_cpu_address != cpue->core_id)
0085             continue;
0086         sclp.has_siif = cpue->siif;
0087         sclp.has_sigpif = cpue->sigpif;
0088         sclp.has_sief2 = cpue->sief2;
0089         sclp.has_gpere = cpue->gpere;
0090         sclp.has_ib = cpue->ib;
0091         sclp.has_cei = cpue->cei;
0092         sclp.has_skey = cpue->skey;
0093         break;
0094     }
0095 
0096     /* Save IPL information */
0097     sclp_ipl_info.is_valid = 1;
0098     if (sccb->fac91 & 0x2)
0099         sclp_ipl_info.has_dump = 1;
0100     memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
0101 
0102     if (sccb->hsa_size)
0103         sclp.hsa_size = (sccb->hsa_size - 1) * PAGE_SIZE;
0104     sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
0105     sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
0106     sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
0107 
0108     sclp.hmfai = sccb->hmfai;
0109     sclp.has_dirq = !!(sccb->cpudirq & 0x80);
0110 }
0111 
0112 /*
0113  * This function will be called after sclp_early_facilities_detect(), which gets
0114  * called from early.c code. The sclp_early_facilities_detect() function retrieves
0115  * and saves the IPL information.
0116  */
0117 void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
0118 {
0119     *info = sclp_ipl_info;
0120 }
0121 
0122 int __init sclp_early_get_core_info(struct sclp_core_info *info)
0123 {
0124     struct read_cpu_info_sccb *sccb;
0125     int length = test_facility(140) ? EXT_SCCB_READ_CPU : PAGE_SIZE;
0126     int rc = 0;
0127 
0128     if (!SCLP_HAS_CPU_INFO)
0129         return -EOPNOTSUPP;
0130 
0131     sccb = memblock_alloc_low(length, PAGE_SIZE);
0132     if (!sccb)
0133         return -ENOMEM;
0134 
0135     memset(sccb, 0, length);
0136     sccb->header.length = length;
0137     sccb->header.control_mask[2] = 0x80;
0138     if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb)) {
0139         rc = -EIO;
0140         goto out;
0141     }
0142     if (sccb->header.response_code != 0x0010) {
0143         rc = -EIO;
0144         goto out;
0145     }
0146     sclp_fill_core_info(info, sccb);
0147 out:
0148     memblock_free(sccb, length);
0149     return rc;
0150 }
0151 
0152 static void __init sclp_early_console_detect(struct init_sccb *sccb)
0153 {
0154     if (sccb->header.response_code != 0x20)
0155         return;
0156 
0157     if (sclp_early_con_check_vt220(sccb))
0158         sclp.has_vt220 = 1;
0159 
0160     if (sclp_early_con_check_linemode(sccb))
0161         sclp.has_linemode = 1;
0162 }
0163 
0164 void __init sclp_early_adjust_va(void)
0165 {
0166     sclp_early_sccb = __va((unsigned long)sclp_early_sccb);
0167 }
0168 
0169 void __init sclp_early_detect(void)
0170 {
0171     void *sccb = sclp_early_sccb;
0172 
0173     sclp_early_facilities_detect();
0174 
0175     /*
0176      * Turn off SCLP event notifications.  Also save remote masks in the
0177      * sccb.  These are sufficient to detect sclp console capabilities.
0178      */
0179     sclp_early_set_event_mask(sccb, 0, 0);
0180     sclp_early_console_detect(sccb);
0181 }