Home | History | Annotate | Line # | Download | only in rmi
rmixlvar.h revision 1.1.2.21
      1 /*	$NetBSD: rmixlvar.h,v 1.1.2.21 2011/12/24 01:57:54 matt Exp $	*/
      2 
      3 /*
      4  * Copyright 2002 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Simon Burge for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed for the NetBSD Project by
     20  *      Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 #ifndef _MIPS_RMI_RMIXLVAR_H_
     39 #define _MIPS_RMI_RMIXLVAR_H_
     40 
     41 #include <sys/bus.h>
     42 #include <sys/extent.h>
     43 
     44 #include <dev/pci/pcivar.h>
     45 
     46 #include <mips/cpu.h>
     47 #include <mips/locore.h>
     48 
     49 #include <mips/rmi/rmixl_firmware.h>
     50 #include <mips/rmi/rmixlreg.h>
     51 
     52 void rmixl_pcr_init_core(bool);
     53 
     54 static inline int
     55 cpu_rmixl_chip_type(const struct pridtab *ct)
     56 {
     57 	return ct->cpu_cidflags & MIPS_CIDFL_RMI_TYPE;
     58 }
     59 
     60 static inline bool
     61 cpu_rmixl(const struct pridtab *ct)
     62 {
     63 	return ct->cpu_cid == MIPS_PRID_CID_RMI;
     64 }
     65 
     66 static inline bool
     67 cpu_rmixlr(const struct pridtab *ct)
     68 {
     69 	return cpu_rmixl(ct) && cpu_rmixl_chip_type(ct) == CIDFL_RMI_TYPE_XLR;
     70 }
     71 
     72 static inline bool
     73 cpu_rmixls(const struct pridtab *ct)
     74 {
     75 	return cpu_rmixl(ct) && cpu_rmixl_chip_type(ct) == CIDFL_RMI_TYPE_XLS;
     76 }
     77 
     78 static inline bool
     79 cpu_rmixlp(const struct pridtab *ct)
     80 {
     81 	return cpu_rmixl(ct) && cpu_rmixl_chip_type(ct) == CIDFL_RMI_TYPE_XLP;
     82 }
     83 
     84 typedef enum {
     85 	PSB_TYPE_UNKNOWN=0,
     86 	PSB_TYPE_RMI,
     87 	PSB_TYPE_DELL,
     88 } rmixlfw_psb_type_t;
     89 
     90 static inline const char *
     91 rmixlfw_psb_type_name(rmixlfw_psb_type_t type)
     92 {
     93 	switch(type) {
     94 	case PSB_TYPE_UNKNOWN:
     95 		return "unknown";
     96 	case PSB_TYPE_RMI:
     97 		return "RMI";
     98 	case PSB_TYPE_DELL:
     99 		return "DELL";
    100 	default:
    101 		return "undefined";
    102 	}
    103 }
    104 
    105 typedef enum {
    106 	RMIXLP_8XX,
    107 	RMIXLP_4XX,
    108 	/* These next 4 need to be in this order */
    109 	RMIXLP_3XX,
    110 	RMIXLP_3XXL,
    111 	RMIXLP_3XXH,
    112 	RMIXLP_3XXQ,
    113 	RMIXLP_ANY,		/* must be last */
    114 } rmixlp_variant_t;
    115 
    116 struct rmixl_region {
    117 	bus_addr_t		r_pbase;
    118 	bus_size_t		r_size;
    119 };
    120 
    121 struct rmixl_config {
    122 	struct rmixl_region	rc_io;
    123 	struct rmixl_region	rc_flash[4];		/* FLASH_BAR */
    124 	struct rmixl_region	rc_pci_cfg;
    125 	struct rmixl_region	rc_pci_ecfg;
    126 	struct rmixl_region	rc_pci_mem;
    127 	struct rmixl_region	rc_pci_io;
    128 	struct rmixl_region	rc_pci_link_mem[4];
    129 	struct rmixl_region	rc_pci_link_io[4];
    130 	struct rmixl_region	rc_srio_mem;
    131 	struct mips_bus_space	rc_obio_eb_memt; 	/* DEVIO -eb */
    132 	struct mips_bus_space	rc_obio_el_memt; 	/* DEVIO -el */
    133 	struct mips_bus_space	rc_iobus_memt; 		/* Peripherals IO Bus */
    134 	struct mips_bus_space	rc_pci_cfg_memt; 	/* PCI CFG */
    135 	struct mips_bus_space	rc_pci_ecfg_eb_memt; 	/* PCI ECFG */
    136 	struct mips_bus_space	rc_pci_ecfg_el_memt; 	/* PCI ECFG */
    137 	struct mips_bus_space	rc_pci_memt; 		/* PCI MEM */
    138 	struct mips_bus_space	rc_pci_iot; 		/* PCI IO */
    139 	struct mips_bus_space	rc_srio_memt; 		/* SRIO MEM */
    140 	struct mips_bus_dma_tag	rc_dma_tag;
    141 	struct mips_pci_chipset rc_pci_chipset;		/* pci_chipset_t */
    142 	bus_space_handle_t	rc_pci_cfg_memh;
    143 	bus_space_handle_t	rc_pci_ecfg_eb_memh;
    144 	bus_space_handle_t	rc_pci_ecfg_el_memh;
    145 	bus_dma_tag_t		rc_dmat64;
    146 	bus_dma_tag_t		rc_dmat32;
    147 	bus_dma_tag_t		rc_dmat29;
    148 	struct extent *		rc_phys_ex;		/* Note: MB units */
    149 	struct extent *		rc_obio_eb_ex;
    150 	struct extent *		rc_obio_el_ex;
    151 	struct extent *		rc_iobus_ex;
    152 	struct extent *		rc_pci_mem_ex;
    153 	struct extent *		rc_pci_io_ex;
    154 	struct extent *		rc_srio_mem_ex;
    155 	int			rc_mallocsafe;
    156 	rmixlfw_info_t 		rc_psb_info;
    157 	rmixlfw_psb_type_t	rc_psb_type;
    158 	volatile struct rmixlfw_cpu_wakeup_info *
    159 				rc_cpu_wakeup_info;
    160 	const void *		rc_cpu_wakeup_end;
    161 };
    162 
    163 extern struct rmixl_config rmixl_configuration;
    164 extern const char *rmixl_cpuname;
    165 
    166 extern void rmixl_obio_eb_bus_mem_init(bus_space_tag_t, void *);
    167 extern void rmixl_obio_el_bus_mem_init(bus_space_tag_t, void *);
    168 extern void rmixl_iobus_bus_mem_init(bus_space_tag_t, void *);
    169 extern void rmixl_pci_cfg_el_bus_mem_init(bus_space_tag_t, void *);
    170 extern void rmixl_pci_cfg_eb_bus_mem_init(bus_space_tag_t, void *);
    171 extern void rmixl_pci_ecfg_el_bus_mem_init(bus_space_tag_t, void *);
    172 extern void rmixl_pci_ecfg_eb_bus_mem_init(bus_space_tag_t, void *);
    173 extern void rmixl_pci_bus_mem_init(bus_space_tag_t, void *);
    174 extern void rmixl_pci_bus_io_init(bus_space_tag_t, void *);
    175 
    176 void	rmixlp_pcie_pc_init(void);
    177 
    178 extern void rmixl_addr_error_init(void);
    179 extern int  rmixl_addr_error_check(void);
    180 extern rmixlp_variant_t rmixl_xlp_variant;
    181 
    182 extern uint64_t rmixl_mfcr(u_int);
    183 extern void rmixl_mtcr(uint64_t, u_int);
    184 
    185 extern void rmixl_eirr_ack(uint64_t, uint64_t, uint64_t);
    186 
    187 
    188 /*
    189  * rmixl_cache_err_dis:
    190  * - disable Cache, Data ECC, Snoop Tag Parity, Tag Parity errors
    191  * - clear the cache error log
    192  * - return previous value from RMIXL_PCR_L1D_CONFIG0
    193  */
    194 static inline uint64_t
    195 rmixl_cache_err_dis(void)
    196 {
    197 	uint64_t r;
    198 
    199 	r = rmixl_mfcr(RMIXL_PCR_L1D_CONFIG0);
    200 	rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r & ~0x2e);
    201 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG, 0);
    202 	return r;
    203 }
    204 
    205 /*
    206  * rmixl_cache_err_restore:
    207  * - clear the cache error log, cache error overflow log,
    208  *   and cache interrupt registers
    209  * - restore previous value to RMIXL_PCR_L1D_CONFIG0
    210  */
    211 static inline void
    212 rmixl_cache_err_restore(uint64_t r)
    213 {
    214 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG, 0);
    215 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_OVF_LO, 0);
    216 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_INTERRUPT, 0);
    217 	rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r);
    218 }
    219 
    220 static inline uint64_t
    221 rmixl_cache_err_check(void)
    222 {
    223 	return rmixl_mfcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG);
    224 }
    225 
    226 static inline int
    227 rmixl_probe_4(volatile uint32_t *va)
    228 {
    229 	uint32_t tmp;
    230 	uint32_t r;
    231 	int err;
    232 	int s;
    233 
    234 	s = splhigh();
    235 	r = rmixl_cache_err_dis();
    236 	tmp = *va;			/* probe */
    237 	err = rmixl_cache_err_check();
    238 	rmixl_cache_err_restore(r);
    239 	splx(s);
    240 
    241 	return (err == 0);
    242 }
    243 
    244 static inline uint32_t
    245 rmixlp_read_4(uint32_t tag, bus_size_t offset)
    246 {
    247 #if 0
    248 	const struct rmixl_config * const rcp = &rmixl_configuration;
    249 
    250 	return bus_space_read_4(rcp->rc_pci_ecfg_memt, rcp->rc_pci_ecfg_memh,
    251 	    offset);
    252 #else
    253 	const paddr_t ecfg_addr = rmixl_configuration.rc_pci_ecfg.r_pbase
    254 	    + tag + offset;
    255 
    256 	return be32toh(*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(ecfg_addr));
    257 #endif
    258 }
    259 
    260 static inline uint64_t
    261 rmixlp_read_8(uint32_t tag, bus_size_t offset)
    262 {
    263 #if 0
    264 	const struct rmixl_config * const rcp = &rmixl_configuration;
    265 
    266 	return bus_space_read_8(rcp->rc_pci_ecfg_memt, rcp->rc_pci_ecfg_memh,
    267 	    offset);
    268 #else
    269 	const paddr_t ecfg_addr = rmixl_configuration.rc_pci_ecfg.r_pbase
    270 	    + tag + offset;
    271 
    272 	return be64toh(*(volatile uint64_t *)MIPS_PHYS_TO_KSEG1(ecfg_addr));
    273 #endif
    274 }
    275 
    276 static inline void
    277 rmixlp_write_4(uint32_t tag, bus_size_t offset, uint32_t v)
    278 {
    279 	const paddr_t ecfg_addr = rmixl_configuration.rc_pci_ecfg.r_pbase
    280 	    + tag + offset;
    281 
    282 	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(ecfg_addr) = htobe32(v);
    283 	__asm __volatile("sync");
    284 }
    285 
    286 static inline void
    287 rmixlp_write_8(uint32_t tag, bus_size_t offset, uint64_t v)
    288 {
    289 	const paddr_t ecfg_addr = rmixl_configuration.rc_pci_ecfg.r_pbase
    290 	    + tag + offset;
    291 
    292 	*(volatile uint64_t *)MIPS_PHYS_TO_KSEG1(ecfg_addr) = htobe64(v);
    293 	__asm __volatile("sync");
    294 }
    295 
    296 static inline void
    297 rmixl_physaddr_add(struct extent *ext, const char *name,
    298     struct rmixl_region *rp, bus_addr_t xpbase, bus_size_t xsize)
    299 {
    300 	rp->r_pbase = xpbase;
    301 	rp->r_size = xsize;
    302 	u_long base = xpbase >> 20;
    303 	u_long size = xsize >> 20;
    304 	if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0) {
    305 		panic("%s: %s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    306 		    "failed", __func__, name, ext, base, size, EX_NOWAIT);
    307 	}
    308 }
    309 
    310 #endif	/* _MIPS_RMI_RMIXLVAR_H_ */
    311