Path: blob/master/arch/powerpc/platforms/cell/cbe_regs.c
10818 views
/*1* cbe_regs.c2*3* Accessor routines for the various MMIO register blocks of the CBE4*5* (c) 2006 Benjamin Herrenschmidt <[email protected]>, IBM Corp.6*/78#include <linux/percpu.h>9#include <linux/types.h>10#include <linux/module.h>11#include <linux/of_device.h>12#include <linux/of_platform.h>1314#include <asm/io.h>15#include <asm/pgtable.h>16#include <asm/prom.h>17#include <asm/ptrace.h>18#include <asm/cell-regs.h>1920/*21* Current implementation uses "cpu" nodes. We build our own mapping22* array of cpu numbers to cpu nodes locally for now to allow interrupt23* time code to have a fast path rather than call of_get_cpu_node(). If24* we implement cpu hotplug, we'll have to install an appropriate norifier25* in order to release references to the cpu going away26*/27static struct cbe_regs_map28{29struct device_node *cpu_node;30struct device_node *be_node;31struct cbe_pmd_regs __iomem *pmd_regs;32struct cbe_iic_regs __iomem *iic_regs;33struct cbe_mic_tm_regs __iomem *mic_tm_regs;34struct cbe_pmd_shadow_regs pmd_shadow_regs;35} cbe_regs_maps[MAX_CBE];36static int cbe_regs_map_count;3738static struct cbe_thread_map39{40struct device_node *cpu_node;41struct device_node *be_node;42struct cbe_regs_map *regs;43unsigned int thread_id;44unsigned int cbe_id;45} cbe_thread_map[NR_CPUS];4647static cpumask_t cbe_local_mask[MAX_CBE] = { [0 ... MAX_CBE-1] = {CPU_BITS_NONE} };48static cpumask_t cbe_first_online_cpu = { CPU_BITS_NONE };4950static struct cbe_regs_map *cbe_find_map(struct device_node *np)51{52int i;53struct device_node *tmp_np;5455if (strcasecmp(np->type, "spe")) {56for (i = 0; i < cbe_regs_map_count; i++)57if (cbe_regs_maps[i].cpu_node == np ||58cbe_regs_maps[i].be_node == np)59return &cbe_regs_maps[i];60return NULL;61}6263if (np->data)64return np->data;6566/* walk up path until cpu or be node was found */67tmp_np = np;68do {69tmp_np = tmp_np->parent;70/* on a correct devicetree we wont get up to root */71BUG_ON(!tmp_np);72} while (strcasecmp(tmp_np->type, "cpu") &&73strcasecmp(tmp_np->type, "be"));7475np->data = cbe_find_map(tmp_np);7677return np->data;78}7980struct cbe_pmd_regs __iomem *cbe_get_pmd_regs(struct device_node *np)81{82struct cbe_regs_map *map = cbe_find_map(np);83if (map == NULL)84return NULL;85return map->pmd_regs;86}87EXPORT_SYMBOL_GPL(cbe_get_pmd_regs);8889struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu)90{91struct cbe_regs_map *map = cbe_thread_map[cpu].regs;92if (map == NULL)93return NULL;94return map->pmd_regs;95}96EXPORT_SYMBOL_GPL(cbe_get_cpu_pmd_regs);9798struct cbe_pmd_shadow_regs *cbe_get_pmd_shadow_regs(struct device_node *np)99{100struct cbe_regs_map *map = cbe_find_map(np);101if (map == NULL)102return NULL;103return &map->pmd_shadow_regs;104}105106struct cbe_pmd_shadow_regs *cbe_get_cpu_pmd_shadow_regs(int cpu)107{108struct cbe_regs_map *map = cbe_thread_map[cpu].regs;109if (map == NULL)110return NULL;111return &map->pmd_shadow_regs;112}113114struct cbe_iic_regs __iomem *cbe_get_iic_regs(struct device_node *np)115{116struct cbe_regs_map *map = cbe_find_map(np);117if (map == NULL)118return NULL;119return map->iic_regs;120}121122struct cbe_iic_regs __iomem *cbe_get_cpu_iic_regs(int cpu)123{124struct cbe_regs_map *map = cbe_thread_map[cpu].regs;125if (map == NULL)126return NULL;127return map->iic_regs;128}129130struct cbe_mic_tm_regs __iomem *cbe_get_mic_tm_regs(struct device_node *np)131{132struct cbe_regs_map *map = cbe_find_map(np);133if (map == NULL)134return NULL;135return map->mic_tm_regs;136}137138struct cbe_mic_tm_regs __iomem *cbe_get_cpu_mic_tm_regs(int cpu)139{140struct cbe_regs_map *map = cbe_thread_map[cpu].regs;141if (map == NULL)142return NULL;143return map->mic_tm_regs;144}145EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);146147u32 cbe_get_hw_thread_id(int cpu)148{149return cbe_thread_map[cpu].thread_id;150}151EXPORT_SYMBOL_GPL(cbe_get_hw_thread_id);152153u32 cbe_cpu_to_node(int cpu)154{155return cbe_thread_map[cpu].cbe_id;156}157EXPORT_SYMBOL_GPL(cbe_cpu_to_node);158159u32 cbe_node_to_cpu(int node)160{161return cpumask_first(&cbe_local_mask[node]);162163}164EXPORT_SYMBOL_GPL(cbe_node_to_cpu);165166static struct device_node *cbe_get_be_node(int cpu_id)167{168struct device_node *np;169170for_each_node_by_type (np, "be") {171int len,i;172const phandle *cpu_handle;173174cpu_handle = of_get_property(np, "cpus", &len);175176/*177* the CAB SLOF tree is non compliant, so we just assume178* there is only one node179*/180if (WARN_ON_ONCE(!cpu_handle))181return np;182183for (i=0; i<len; i++)184if (of_find_node_by_phandle(cpu_handle[i]) == of_get_cpu_node(cpu_id, NULL))185return np;186}187188return NULL;189}190191void __init cbe_fill_regs_map(struct cbe_regs_map *map)192{193if(map->be_node) {194struct device_node *be, *np;195196be = map->be_node;197198for_each_node_by_type(np, "pervasive")199if (of_get_parent(np) == be)200map->pmd_regs = of_iomap(np, 0);201202for_each_node_by_type(np, "CBEA-Internal-Interrupt-Controller")203if (of_get_parent(np) == be)204map->iic_regs = of_iomap(np, 2);205206for_each_node_by_type(np, "mic-tm")207if (of_get_parent(np) == be)208map->mic_tm_regs = of_iomap(np, 0);209} else {210struct device_node *cpu;211/* That hack must die die die ! */212const struct address_prop {213unsigned long address;214unsigned int len;215} __attribute__((packed)) *prop;216217cpu = map->cpu_node;218219prop = of_get_property(cpu, "pervasive", NULL);220if (prop != NULL)221map->pmd_regs = ioremap(prop->address, prop->len);222223prop = of_get_property(cpu, "iic", NULL);224if (prop != NULL)225map->iic_regs = ioremap(prop->address, prop->len);226227prop = of_get_property(cpu, "mic-tm", NULL);228if (prop != NULL)229map->mic_tm_regs = ioremap(prop->address, prop->len);230}231}232233234void __init cbe_regs_init(void)235{236int i;237unsigned int thread_id;238struct device_node *cpu;239240/* Build local fast map of CPUs */241for_each_possible_cpu(i) {242cbe_thread_map[i].cpu_node = of_get_cpu_node(i, &thread_id);243cbe_thread_map[i].be_node = cbe_get_be_node(i);244cbe_thread_map[i].thread_id = thread_id;245}246247/* Find maps for each device tree CPU */248for_each_node_by_type(cpu, "cpu") {249struct cbe_regs_map *map;250unsigned int cbe_id;251252cbe_id = cbe_regs_map_count++;253map = &cbe_regs_maps[cbe_id];254255if (cbe_regs_map_count > MAX_CBE) {256printk(KERN_ERR "cbe_regs: More BE chips than supported"257"!\n");258cbe_regs_map_count--;259of_node_put(cpu);260return;261}262map->cpu_node = cpu;263264for_each_possible_cpu(i) {265struct cbe_thread_map *thread = &cbe_thread_map[i];266267if (thread->cpu_node == cpu) {268thread->regs = map;269thread->cbe_id = cbe_id;270map->be_node = thread->be_node;271cpumask_set_cpu(i, &cbe_local_mask[cbe_id]);272if(thread->thread_id == 0)273cpumask_set_cpu(i, &cbe_first_online_cpu);274}275}276277cbe_fill_regs_map(map);278}279}280281282283