bus.c (d200781ef237a354d918ceff5cee350d88a93d42) bus.c (730926c3b0998943654019f00296cf8e3b02277e)
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */
3#include <linux/memremap.h>
4#include <linux/device.h>
5#include <linux/mutex.h>
6#include <linux/list.h>
7#include <linux/slab.h>
8#include <linux/dax.h>
9#include "dax-private.h"
10#include "bus.h"
11
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */
3#include <linux/memremap.h>
4#include <linux/device.h>
5#include <linux/mutex.h>
6#include <linux/list.h>
7#include <linux/slab.h>
8#include <linux/dax.h>
9#include "dax-private.h"
10#include "bus.h"
11
12static struct class *dax_class;
13
12static DEFINE_MUTEX(dax_bus_lock);
13
14#define DAX_NAME_LEN 30
15struct dax_id {
16 struct list_head list;
17 char dev_name[DAX_NAME_LEN];
18};
19

--- 285 unchanged lines hidden (view full) ---

305
306 dev_dbg(dev, "%s\n", __func__);
307
308 kill_dev_dax(dev_dax);
309 device_del(dev);
310 put_device(dev);
311}
312
14static DEFINE_MUTEX(dax_bus_lock);
15
16#define DAX_NAME_LEN 30
17struct dax_id {
18 struct list_head list;
19 char dev_name[DAX_NAME_LEN];
20};
21

--- 285 unchanged lines hidden (view full) ---

307
308 dev_dbg(dev, "%s\n", __func__);
309
310 kill_dev_dax(dev_dax);
311 device_del(dev);
312 put_device(dev);
313}
314
313struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, int id,
314 struct dev_pagemap *pgmap)
315struct dev_dax *__devm_create_dev_dax(struct dax_region *dax_region, int id,
316 struct dev_pagemap *pgmap, enum dev_dax_subsys subsys)
315{
316 struct device *parent = dax_region->dev;
317 struct dax_device *dax_dev;
318 struct dev_dax *dev_dax;
319 struct inode *inode;
320 struct device *dev;
321 int rc = -ENOMEM;
322

--- 22 unchanged lines hidden (view full) ---

345 device_initialize(dev);
346
347 dev_dax->dax_dev = dax_dev;
348 dev_dax->region = dax_region;
349 kref_get(&dax_region->kref);
350
351 inode = dax_inode(dax_dev);
352 dev->devt = inode->i_rdev;
317{
318 struct device *parent = dax_region->dev;
319 struct dax_device *dax_dev;
320 struct dev_dax *dev_dax;
321 struct inode *inode;
322 struct device *dev;
323 int rc = -ENOMEM;
324

--- 22 unchanged lines hidden (view full) ---

347 device_initialize(dev);
348
349 dev_dax->dax_dev = dax_dev;
350 dev_dax->region = dax_region;
351 kref_get(&dax_region->kref);
352
353 inode = dax_inode(dax_dev);
354 dev->devt = inode->i_rdev;
353 dev->bus = &dax_bus_type;
355 if (subsys == DEV_DAX_BUS)
356 dev->bus = &dax_bus_type;
357 else
358 dev->class = dax_class;
354 dev->parent = parent;
355 dev->groups = dax_attribute_groups;
356 dev->release = dev_dax_release;
357 dev_set_name(dev, "dax%d.%d", dax_region->id, id);
358
359 rc = device_add(dev);
360 if (rc) {
361 kill_dev_dax(dev_dax);

--- 7 unchanged lines hidden (view full) ---

369
370 return dev_dax;
371
372 err:
373 kfree(dev_dax);
374
375 return ERR_PTR(rc);
376}
359 dev->parent = parent;
360 dev->groups = dax_attribute_groups;
361 dev->release = dev_dax_release;
362 dev_set_name(dev, "dax%d.%d", dax_region->id, id);
363
364 rc = device_add(dev);
365 if (rc) {
366 kill_dev_dax(dev_dax);

--- 7 unchanged lines hidden (view full) ---

374
375 return dev_dax;
376
377 err:
378 kfree(dev_dax);
379
380 return ERR_PTR(rc);
381}
377EXPORT_SYMBOL_GPL(devm_create_dev_dax);
382EXPORT_SYMBOL_GPL(__devm_create_dev_dax);
378
379static int match_always_count;
380
381int __dax_driver_register(struct dax_device_driver *dax_drv,
382 struct module *module, const char *mod_name)
383{
384 struct device_driver *drv = &dax_drv->drv;
385 int rc = 0;

--- 16 unchanged lines hidden (view full) ---

402 if (rc)
403 return rc;
404 return driver_register(drv);
405}
406EXPORT_SYMBOL_GPL(__dax_driver_register);
407
408void dax_driver_unregister(struct dax_device_driver *dax_drv)
409{
383
384static int match_always_count;
385
386int __dax_driver_register(struct dax_device_driver *dax_drv,
387 struct module *module, const char *mod_name)
388{
389 struct device_driver *drv = &dax_drv->drv;
390 int rc = 0;

--- 16 unchanged lines hidden (view full) ---

407 if (rc)
408 return rc;
409 return driver_register(drv);
410}
411EXPORT_SYMBOL_GPL(__dax_driver_register);
412
413void dax_driver_unregister(struct dax_device_driver *dax_drv)
414{
415 struct device_driver *drv = &dax_drv->drv;
410 struct dax_id *dax_id, *_id;
411
412 mutex_lock(&dax_bus_lock);
413 match_always_count -= dax_drv->match_always;
414 list_for_each_entry_safe(dax_id, _id, &dax_drv->ids, list) {
415 list_del(&dax_id->list);
416 kfree(dax_id);
417 }
418 mutex_unlock(&dax_bus_lock);
416 struct dax_id *dax_id, *_id;
417
418 mutex_lock(&dax_bus_lock);
419 match_always_count -= dax_drv->match_always;
420 list_for_each_entry_safe(dax_id, _id, &dax_drv->ids, list) {
421 list_del(&dax_id->list);
422 kfree(dax_id);
423 }
424 mutex_unlock(&dax_bus_lock);
425 driver_unregister(drv);
419}
420EXPORT_SYMBOL_GPL(dax_driver_unregister);
421
422int __init dax_bus_init(void)
423{
426}
427EXPORT_SYMBOL_GPL(dax_driver_unregister);
428
429int __init dax_bus_init(void)
430{
424 return bus_register(&dax_bus_type);
431 int rc;
432
433 if (IS_ENABLED(CONFIG_DEV_DAX_PMEM_COMPAT)) {
434 dax_class = class_create(THIS_MODULE, "dax");
435 if (IS_ERR(dax_class))
436 return PTR_ERR(dax_class);
437 }
438
439 rc = bus_register(&dax_bus_type);
440 if (rc)
441 class_destroy(dax_class);
442 return rc;
425}
426
427void __exit dax_bus_exit(void)
428{
429 bus_unregister(&dax_bus_type);
443}
444
445void __exit dax_bus_exit(void)
446{
447 bus_unregister(&dax_bus_type);
448 class_destroy(dax_class);
430}
449}