~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/powernv/vas.c

Version: ~ [ linux-5.6.3 ] ~ [ linux-5.5.16 ] ~ [ linux-5.4.31 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.114 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.175 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.218 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.218 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.82 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2016-17 IBM Corp.
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public License
  6  * as published by the Free Software Foundation; either version
  7  * 2 of the License, or (at your option) any later version.
  8  */
  9 
 10 #define pr_fmt(fmt) "vas: " fmt
 11 
 12 #include <linux/module.h>
 13 #include <linux/kernel.h>
 14 #include <linux/export.h>
 15 #include <linux/types.h>
 16 #include <linux/slab.h>
 17 #include <linux/platform_device.h>
 18 #include <linux/of_platform.h>
 19 #include <linux/of_address.h>
 20 #include <linux/of.h>
 21 #include <asm/prom.h>
 22 
 23 #include "vas.h"
 24 
 25 DEFINE_MUTEX(vas_mutex);
 26 static LIST_HEAD(vas_instances);
 27 
 28 static DEFINE_PER_CPU(int, cpu_vas_id);
 29 
 30 static int init_vas_instance(struct platform_device *pdev)
 31 {
 32         int rc, cpu, vasid;
 33         struct resource *res;
 34         struct vas_instance *vinst;
 35         struct device_node *dn = pdev->dev.of_node;
 36 
 37         rc = of_property_read_u32(dn, "ibm,vas-id", &vasid);
 38         if (rc) {
 39                 pr_err("No ibm,vas-id property for %s?\n", pdev->name);
 40                 return -ENODEV;
 41         }
 42 
 43         if (pdev->num_resources != 4) {
 44                 pr_err("Unexpected DT configuration for [%s, %d]\n",
 45                                 pdev->name, vasid);
 46                 return -ENODEV;
 47         }
 48 
 49         vinst = kzalloc(sizeof(*vinst), GFP_KERNEL);
 50         if (!vinst)
 51                 return -ENOMEM;
 52 
 53         INIT_LIST_HEAD(&vinst->node);
 54         ida_init(&vinst->ida);
 55         mutex_init(&vinst->mutex);
 56         vinst->vas_id = vasid;
 57         vinst->pdev = pdev;
 58 
 59         res = &pdev->resource[0];
 60         vinst->hvwc_bar_start = res->start;
 61 
 62         res = &pdev->resource[1];
 63         vinst->uwc_bar_start = res->start;
 64 
 65         res = &pdev->resource[2];
 66         vinst->paste_base_addr = res->start;
 67 
 68         res = &pdev->resource[3];
 69         if (res->end > 62) {
 70                 pr_err("Bad 'paste_win_id_shift' in DT, %llx\n", res->end);
 71                 goto free_vinst;
 72         }
 73 
 74         vinst->paste_win_id_shift = 63 - res->end;
 75 
 76         pr_devel("Initialized instance [%s, %d], paste_base 0x%llx, "
 77                         "paste_win_id_shift 0x%llx\n", pdev->name, vasid,
 78                         vinst->paste_base_addr, vinst->paste_win_id_shift);
 79 
 80         for_each_possible_cpu(cpu) {
 81                 if (cpu_to_chip_id(cpu) == of_get_ibm_chip_id(dn))
 82                         per_cpu(cpu_vas_id, cpu) = vasid;
 83         }
 84 
 85         mutex_lock(&vas_mutex);
 86         list_add(&vinst->node, &vas_instances);
 87         mutex_unlock(&vas_mutex);
 88 
 89         vas_instance_init_dbgdir(vinst);
 90 
 91         dev_set_drvdata(&pdev->dev, vinst);
 92 
 93         return 0;
 94 
 95 free_vinst:
 96         kfree(vinst);
 97         return -ENODEV;
 98 
 99 }
100 
101 /*
102  * Although this is read/used multiple times, it is written to only
103  * during initialization.
104  */
105 struct vas_instance *find_vas_instance(int vasid)
106 {
107         struct list_head *ent;
108         struct vas_instance *vinst;
109 
110         mutex_lock(&vas_mutex);
111 
112         if (vasid == -1)
113                 vasid = per_cpu(cpu_vas_id, smp_processor_id());
114 
115         list_for_each(ent, &vas_instances) {
116                 vinst = list_entry(ent, struct vas_instance, node);
117                 if (vinst->vas_id == vasid) {
118                         mutex_unlock(&vas_mutex);
119                         return vinst;
120                 }
121         }
122         mutex_unlock(&vas_mutex);
123 
124         pr_devel("Instance %d not found\n", vasid);
125         return NULL;
126 }
127 
128 int chip_to_vas_id(int chipid)
129 {
130         int cpu;
131 
132         for_each_possible_cpu(cpu) {
133                 if (cpu_to_chip_id(cpu) == chipid)
134                         return per_cpu(cpu_vas_id, cpu);
135         }
136         return -1;
137 }
138 EXPORT_SYMBOL(chip_to_vas_id);
139 
140 static int vas_probe(struct platform_device *pdev)
141 {
142         return init_vas_instance(pdev);
143 }
144 
145 static const struct of_device_id powernv_vas_match[] = {
146         { .compatible = "ibm,vas",},
147         {},
148 };
149 
150 static struct platform_driver vas_driver = {
151         .driver = {
152                 .name = "vas",
153                 .of_match_table = powernv_vas_match,
154         },
155         .probe = vas_probe,
156 };
157 
158 static int __init vas_init(void)
159 {
160         int found = 0;
161         struct device_node *dn;
162 
163         platform_driver_register(&vas_driver);
164 
165         for_each_compatible_node(dn, NULL, "ibm,vas") {
166                 of_platform_device_create(dn, NULL, NULL);
167                 found++;
168         }
169 
170         if (!found) {
171                 platform_driver_unregister(&vas_driver);
172                 return -ENODEV;
173         }
174 
175         pr_devel("Found %d instances\n", found);
176 
177         return 0;
178 }
179 device_initcall(vas_init);
180 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp