rmixlvar.h revision 1.2.10.1       1       1.2    matt /*	$NetBSD: rmixlvar.h,v 1.2.10.1 2011/03/05 15:09:51 bouyer Exp $	*/
      2       1.2    matt 
      3       1.2    matt /*
      4       1.2    matt  * Copyright 2002 Wasabi Systems, Inc.
      5       1.2    matt  * All rights reserved.
      6       1.2    matt  *
      7       1.2    matt  * Written by Simon Burge for Wasabi Systems, Inc.
      8       1.2    matt  *
      9       1.2    matt  * Redistribution and use in source and binary forms, with or without
     10       1.2    matt  * modification, are permitted provided that the following conditions
     11       1.2    matt  * are met:
     12       1.2    matt  * 1. Redistributions of source code must retain the above copyright
     13       1.2    matt  *    notice, this list of conditions and the following disclaimer.
     14       1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     16       1.2    matt  *    documentation and/or other materials provided with the distribution.
     17       1.2    matt  * 3. All advertising materials mentioning features or use of this software
     18       1.2    matt  *    must display the following acknowledgement:
     19       1.2    matt  *      This product includes software developed for the NetBSD Project by
     20       1.2    matt  *      Wasabi Systems, Inc.
     21       1.2    matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.2    matt  *    or promote products derived from this software without specific prior
     23       1.2    matt  *    written permission.
     24       1.2    matt  *
     25       1.2    matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.2    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.2    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.2    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.2    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.2    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.2    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.2    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.2    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.2    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.2    matt  * POSSIBILITY OF SUCH DAMAGE.
     36       1.2    matt  */
     37       1.2    matt 
     38       1.2    matt #ifndef _MIPS_RMI_RMIXLVAR_H_
     39       1.2    matt #define _MIPS_RMI_RMIXLVAR_H_
     40       1.2    matt 
     41       1.2    matt #include <mips/cpu.h>
     42  1.2.10.1  bouyer #include <mips/locore.h>
     43  1.2.10.1  bouyer #include <mips/rmi/rmixl_firmware.h>
     44  1.2.10.1  bouyer 
     45       1.2    matt #include <machine/bus.h>
     46       1.2    matt 
     47  1.2.10.1  bouyer #include <dev/pci/pcivar.h>
     48  1.2.10.1  bouyer 
     49  1.2.10.1  bouyer extern void rmixl_pcr_init_core(void);
     50  1.2.10.1  bouyer 
     51       1.2    matt static inline bool
     52       1.2    matt cpu_rmixl(const struct pridtab *ct)
     53       1.2    matt {
     54       1.2    matt 	if (ct->cpu_cid == MIPS_PRID_CID_RMI)
     55       1.2    matt 		return true;
     56       1.2    matt 	return false;
     57       1.2    matt }
     58       1.2    matt 
     59       1.2    matt static inline bool
     60       1.2    matt cpu_rmixlr(const struct pridtab *ct)
     61       1.2    matt {
     62       1.2    matt 	u_int type = ct->cpu_cidflags & MIPS_CIDFL_RMI_TYPE;
     63       1.2    matt 	if (cpu_rmixl(ct) && type == CIDFL_RMI_TYPE_XLR)
     64       1.2    matt 		return true;
     65       1.2    matt 	return false;
     66       1.2    matt }
     67       1.2    matt 
     68       1.2    matt static inline bool
     69       1.2    matt cpu_rmixls(const struct pridtab *ct)
     70       1.2    matt {
     71       1.2    matt 	u_int type = ct->cpu_cidflags & MIPS_CIDFL_RMI_TYPE;
     72       1.2    matt 	if (cpu_rmixl(ct) && type == CIDFL_RMI_TYPE_XLS)
     73       1.2    matt 		return true;
     74       1.2    matt 	return false;
     75       1.2    matt }
     76       1.2    matt 
     77       1.2    matt static inline bool
     78       1.2    matt cpu_rmixlp(const struct pridtab *ct)
     79       1.2    matt {
     80       1.2    matt 	u_int type = ct->cpu_cidflags & MIPS_CIDFL_RMI_TYPE;
     81       1.2    matt 	if (cpu_rmixl(ct) && type == CIDFL_RMI_TYPE_XLP)
     82       1.2    matt 		return true;
     83       1.2    matt 	return false;
     84       1.2    matt }
     85       1.2    matt 
     86  1.2.10.1  bouyer static inline int
     87  1.2.10.1  bouyer cpu_rmixl_chip_type(const struct pridtab *ct)
     88  1.2.10.1  bouyer {
     89  1.2.10.1  bouyer 	return ct->cpu_cidflags & MIPS_CIDFL_RMI_TYPE;
     90  1.2.10.1  bouyer }
     91       1.2    matt 
     92       1.2    matt typedef enum {
     93  1.2.10.1  bouyer 	PSB_TYPE_UNKNOWN=0,
     94  1.2.10.1  bouyer 	PSB_TYPE_RMI,
     95  1.2.10.1  bouyer 	PSB_TYPE_DELL,
     96  1.2.10.1  bouyer } rmixlfw_psb_type_t;
     97       1.2    matt 
     98  1.2.10.1  bouyer static inline const char *
     99  1.2.10.1  bouyer rmixlfw_psb_type_name(rmixlfw_psb_type_t type)
    100  1.2.10.1  bouyer {
    101  1.2.10.1  bouyer 	switch(type) {
    102  1.2.10.1  bouyer 	case PSB_TYPE_UNKNOWN:
    103  1.2.10.1  bouyer 		return "unknown";
    104  1.2.10.1  bouyer 	case PSB_TYPE_RMI:
    105  1.2.10.1  bouyer 		return "RMI";
    106  1.2.10.1  bouyer 	case PSB_TYPE_DELL:
    107  1.2.10.1  bouyer 		return "DELL";
    108  1.2.10.1  bouyer 	default:
    109  1.2.10.1  bouyer 		return "undefined";
    110  1.2.10.1  bouyer 	}
    111  1.2.10.1  bouyer }
    112       1.2    matt 
    113       1.2    matt struct rmixl_config {
    114       1.2    matt 	uint64_t		 rc_io_pbase;
    115  1.2.10.1  bouyer 	bus_addr_t		 rc_pci_cfg_pbase;
    116  1.2.10.1  bouyer 	bus_size_t		 rc_pci_cfg_size;
    117  1.2.10.1  bouyer 	bus_addr_t		 rc_pci_ecfg_pbase;
    118  1.2.10.1  bouyer 	bus_size_t		 rc_pci_ecfg_size;
    119       1.2    matt 	bus_addr_t		 rc_pci_mem_pbase;
    120       1.2    matt 	bus_size_t		 rc_pci_mem_size;
    121       1.2    matt 	bus_addr_t		 rc_pci_io_pbase;
    122       1.2    matt 	bus_size_t		 rc_pci_io_size;
    123  1.2.10.1  bouyer 	struct mips_bus_space	 rc_obio_eb_memt; 	/* DEVIO -eb */
    124  1.2.10.1  bouyer 	struct mips_bus_space	 rc_obio_el_memt; 	/* DEVIO -el */
    125  1.2.10.1  bouyer 	struct mips_bus_space	 rc_pci_cfg_memt; 	/* PCI CFG  */
    126  1.2.10.1  bouyer 	struct mips_bus_space	 rc_pci_ecfg_memt; 	/* PCI ECFG */
    127       1.2    matt 	struct mips_bus_space	 rc_pci_memt; 		/* PCI MEM */
    128       1.2    matt 	struct mips_bus_space	 rc_pci_iot; 		/* PCI IO  */
    129  1.2.10.1  bouyer 	struct mips_bus_dma_tag	 rc_dma_tag;
    130  1.2.10.1  bouyer 	bus_dma_tag_t		 rc_64bit_dmat;
    131  1.2.10.1  bouyer 	bus_dma_tag_t		 rc_32bit_dmat;
    132  1.2.10.1  bouyer 	bus_dma_tag_t		 rc_29bit_dmat;
    133       1.2    matt 	struct extent		*rc_phys_ex;	/* Note: MB units */
    134  1.2.10.1  bouyer 	struct extent		*rc_obio_eb_ex;
    135  1.2.10.1  bouyer 	struct extent		*rc_obio_el_ex;
    136  1.2.10.1  bouyer 	struct extent		*rc_pci_cfg_ex;
    137  1.2.10.1  bouyer 	struct extent		*rc_pci_ecfg_ex;
    138  1.2.10.1  bouyer 	struct extent		*rc_pci_mem_ex;
    139  1.2.10.1  bouyer 	struct extent		*rc_pci_io_ex;
    140       1.2    matt 	int			 rc_mallocsafe;
    141  1.2.10.1  bouyer 	rmixlfw_info_t 		 rc_psb_info;
    142  1.2.10.1  bouyer 	rmixlfw_psb_type_t	 rc_psb_type;
    143  1.2.10.1  bouyer 	volatile struct rmixlfw_cpu_wakeup_info
    144  1.2.10.1  bouyer 				*rc_cpu_wakeup_info;
    145  1.2.10.1  bouyer 	const void		*rc_cpu_wakeup_end;
    146       1.2    matt };
    147       1.2    matt 
    148       1.2    matt extern struct rmixl_config rmixl_configuration;
    149       1.2    matt 
    150  1.2.10.1  bouyer extern void rmixl_obio_eb_bus_mem_init(bus_space_tag_t, void *);
    151  1.2.10.1  bouyer extern void rmixl_obio_el_bus_mem_init(bus_space_tag_t, void *);
    152  1.2.10.1  bouyer extern void rmixl_pci_cfg_bus_mem_init(bus_space_tag_t, void *);
    153  1.2.10.1  bouyer extern void rmixl_pci_ecfg_bus_mem_init(bus_space_tag_t, void *);
    154  1.2.10.1  bouyer extern void rmixl_pci_bus_mem_init(bus_space_tag_t, void *);
    155  1.2.10.1  bouyer extern void rmixl_pci_bus_io_init(bus_space_tag_t, void *);
    156       1.2    matt 
    157       1.2    matt extern void rmixl_addr_error_init(void);
    158       1.2    matt extern int  rmixl_addr_error_check(void);
    159       1.2    matt 
    160       1.2    matt extern uint64_t rmixl_mfcr(u_int);
    161       1.2    matt extern void rmixl_mtcr(uint64_t, u_int);
    162       1.2    matt 
    163  1.2.10.1  bouyer 
    164  1.2.10.1  bouyer /*
    165  1.2.10.1  bouyer  * rmixl_cache_err_dis:
    166  1.2.10.1  bouyer  * - disable Cache, Data ECC, Snoop Tag Parity, Tag Parity errors
    167  1.2.10.1  bouyer  * - clear the cache error log
    168  1.2.10.1  bouyer  * - return previous value from RMIXL_PCR_L1D_CONFIG0
    169  1.2.10.1  bouyer  */
    170  1.2.10.1  bouyer static inline uint64_t
    171  1.2.10.1  bouyer rmixl_cache_err_dis(void)
    172  1.2.10.1  bouyer {
    173  1.2.10.1  bouyer 	uint64_t r;
    174  1.2.10.1  bouyer 
    175  1.2.10.1  bouyer 	r = rmixl_mfcr(RMIXL_PCR_L1D_CONFIG0);
    176  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r & ~0x2e);
    177  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG, 0);
    178  1.2.10.1  bouyer 	return r;
    179  1.2.10.1  bouyer }
    180  1.2.10.1  bouyer 
    181  1.2.10.1  bouyer /*
    182  1.2.10.1  bouyer  * rmixl_cache_err_restore:
    183  1.2.10.1  bouyer  * - clear the cache error log, cache error overflow log,
    184  1.2.10.1  bouyer  *   and cache interrupt registers
    185  1.2.10.1  bouyer  * - restore previous value to RMIXL_PCR_L1D_CONFIG0
    186  1.2.10.1  bouyer  */
    187  1.2.10.1  bouyer static inline void
    188  1.2.10.1  bouyer rmixl_cache_err_restore(uint64_t r)
    189  1.2.10.1  bouyer {
    190  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG, 0);
    191  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_ERROR_OVF_LO, 0);
    192  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CACHE_INTERRUPT, 0);
    193  1.2.10.1  bouyer 	rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r);
    194  1.2.10.1  bouyer }
    195  1.2.10.1  bouyer 
    196  1.2.10.1  bouyer static inline uint64_t
    197  1.2.10.1  bouyer rmixl_cache_err_check(void)
    198  1.2.10.1  bouyer {
    199  1.2.10.1  bouyer 	return rmixl_mfcr(RMIXL_PCR_L1D_CACHE_ERROR_LOG);
    200  1.2.10.1  bouyer }
    201  1.2.10.1  bouyer 
    202  1.2.10.1  bouyer static inline int
    203  1.2.10.1  bouyer rmixl_probe_4(volatile uint32_t *va)
    204  1.2.10.1  bouyer {
    205  1.2.10.1  bouyer 	uint32_t tmp;
    206  1.2.10.1  bouyer 	uint32_t r;
    207  1.2.10.1  bouyer 	int err;
    208  1.2.10.1  bouyer 	int s;
    209  1.2.10.1  bouyer 
    210  1.2.10.1  bouyer 	s = splhigh();
    211  1.2.10.1  bouyer 	r = rmixl_cache_err_dis();
    212  1.2.10.1  bouyer 	tmp = *va;			/* probe */
    213  1.2.10.1  bouyer 	err = rmixl_cache_err_check();
    214  1.2.10.1  bouyer 	rmixl_cache_err_restore(r);
    215  1.2.10.1  bouyer 	splx(s);
    216  1.2.10.1  bouyer 
    217  1.2.10.1  bouyer 	return (err == 0);
    218  1.2.10.1  bouyer }
    219  1.2.10.1  bouyer 
    220       1.2    matt #endif	/* _MIPS_RMI_RMIXLVAR_H_ */
    221