blob: 42602f30949fe6428c643e18c8fd688c8132808d [file] [log] [blame]
Paul Burton9f98f3d2014-01-15 10:31:51 +00001/*
2 * Copyright (C) 2013 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <linux/errno.h>
12
13#include <asm/mips-cm.h>
14#include <asm/mipsregs.h>
15
16void __iomem *mips_cm_base;
17void __iomem *mips_cm_l2sync_base;
18
Ralf Baechle15d45cc2014-11-22 00:22:09 +010019phys_addr_t __mips_cm_phys_base(void)
Paul Burton9f98f3d2014-01-15 10:31:51 +000020{
21 u32 config3 = read_c0_config3();
22 u32 cmgcr;
23
24 /* Check the CMGCRBase register is implemented */
25 if (!(config3 & MIPS_CONF3_CMGCR))
26 return 0;
27
28 /* Read the address from CMGCRBase */
29 cmgcr = read_c0_cmgcrbase();
30 return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32);
31}
32
Ralf Baechle15d45cc2014-11-22 00:22:09 +010033phys_addr_t mips_cm_phys_base(void)
Paul Burton9f98f3d2014-01-15 10:31:51 +000034 __attribute__((weak, alias("__mips_cm_phys_base")));
35
Ralf Baechle15d45cc2014-11-22 00:22:09 +010036phys_addr_t __mips_cm_l2sync_phys_base(void)
Paul Burton9f98f3d2014-01-15 10:31:51 +000037{
38 u32 base_reg;
39
40 /*
41 * If the L2-only sync region is already enabled then leave it at it's
42 * current location.
43 */
44 base_reg = read_gcr_l2_only_sync_base();
45 if (base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK)
46 return base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK;
47
48 /* Default to following the CM */
49 return mips_cm_phys_base() + MIPS_CM_GCR_SIZE;
50}
51
Ralf Baechle15d45cc2014-11-22 00:22:09 +010052phys_addr_t mips_cm_l2sync_phys_base(void)
Paul Burton9f98f3d2014-01-15 10:31:51 +000053 __attribute__((weak, alias("__mips_cm_l2sync_phys_base")));
54
55static void mips_cm_probe_l2sync(void)
56{
57 unsigned major_rev;
Ralf Baechle15d45cc2014-11-22 00:22:09 +010058 phys_addr_t addr;
Paul Burton9f98f3d2014-01-15 10:31:51 +000059
60 /* L2-only sync was introduced with CM major revision 6 */
61 major_rev = (read_gcr_rev() & CM_GCR_REV_MAJOR_MSK) >>
62 CM_GCR_REV_MAJOR_SHF;
63 if (major_rev < 6)
64 return;
65
66 /* Find a location for the L2 sync region */
67 addr = mips_cm_l2sync_phys_base();
68 BUG_ON((addr & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK) != addr);
69 if (!addr)
70 return;
71
72 /* Set the region base address & enable it */
73 write_gcr_l2_only_sync_base(addr | CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK);
74
75 /* Map the region */
76 mips_cm_l2sync_base = ioremap_nocache(addr, MIPS_CM_L2SYNC_SIZE);
77}
78
79int mips_cm_probe(void)
80{
Ralf Baechle15d45cc2014-11-22 00:22:09 +010081 phys_addr_t addr;
Paul Burton9f98f3d2014-01-15 10:31:51 +000082 u32 base_reg;
83
Markos Chandrasc014d162015-07-09 10:40:43 +010084 /*
85 * No need to probe again if we have already been
86 * here before.
87 */
88 if (mips_cm_base)
89 return 0;
90
Paul Burton9f98f3d2014-01-15 10:31:51 +000091 addr = mips_cm_phys_base();
92 BUG_ON((addr & CM_GCR_BASE_GCRBASE_MSK) != addr);
93 if (!addr)
94 return -ENODEV;
95
96 mips_cm_base = ioremap_nocache(addr, MIPS_CM_GCR_SIZE);
97 if (!mips_cm_base)
98 return -ENXIO;
99
100 /* sanity check that we're looking at a CM */
101 base_reg = read_gcr_base();
102 if ((base_reg & CM_GCR_BASE_GCRBASE_MSK) != addr) {
103 pr_err("GCRs appear to have been moved (expected them at 0x%08lx)!\n",
104 (unsigned long)addr);
105 mips_cm_base = NULL;
106 return -ENODEV;
107 }
108
109 /* set default target to memory */
110 base_reg &= ~CM_GCR_BASE_CMDEFTGT_MSK;
111 base_reg |= CM_GCR_BASE_CMDEFTGT_MEM;
112 write_gcr_base(base_reg);
113
114 /* disable CM regions */
115 write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
116 write_gcr_reg0_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
117 write_gcr_reg1_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
118 write_gcr_reg1_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
119 write_gcr_reg2_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
120 write_gcr_reg2_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
121 write_gcr_reg3_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
122 write_gcr_reg3_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
123
124 /* probe for an L2-only sync region */
125 mips_cm_probe_l2sync();
126
127 return 0;
128}