linux/drivers/hwtracing/stm/dummy_stm.c
<<
>>
Prefs
   1/*
   2 * A dummy STM device for stm/stm_source class testing.
   3 * Copyright (c) 2014, Intel Corporation.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms and conditions of the GNU General Public License,
   7 * version 2, as published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  12 * more details.
  13 *
  14 * STM class implements generic infrastructure for  System Trace Module devices
  15 * as defined in MIPI STPv2 specification.
  16 */
  17
  18#undef DEBUG
  19#include <linux/kernel.h>
  20#include <linux/module.h>
  21#include <linux/slab.h>
  22#include <linux/stm.h>
  23#include <uapi/linux/stm.h>
  24
  25static ssize_t notrace
  26dummy_stm_packet(struct stm_data *stm_data, unsigned int master,
  27                 unsigned int channel, unsigned int packet, unsigned int flags,
  28                 unsigned int size, const unsigned char *payload)
  29{
  30#ifdef DEBUG
  31        u64 pl = 0;
  32
  33        if (payload)
  34                pl = *(u64 *)payload;
  35
  36        if (size < 8)
  37                pl &= (1ull << (size * 8)) - 1;
  38        trace_printk("[%u:%u] [pkt: %x/%x] (%llx)\n", master, channel,
  39                     packet, size, pl);
  40#endif
  41        return size;
  42}
  43
  44#define DUMMY_STM_MAX 32
  45
  46static struct stm_data dummy_stm[DUMMY_STM_MAX];
  47
  48static int nr_dummies = 4;
  49
  50module_param(nr_dummies, int, 0400);
  51
  52static unsigned int fail_mode;
  53
  54module_param(fail_mode, int, 0600);
  55
  56static unsigned int master_min;
  57
  58module_param(master_min, int, 0400);
  59
  60static unsigned int master_max = STP_MASTER_MAX;
  61
  62module_param(master_max, int, 0400);
  63
  64static unsigned int nr_channels = STP_CHANNEL_MAX;
  65
  66module_param(nr_channels, int, 0400);
  67
  68static int dummy_stm_link(struct stm_data *data, unsigned int master,
  69                          unsigned int channel)
  70{
  71        if (fail_mode && (channel & fail_mode))
  72                return -EINVAL;
  73
  74        return 0;
  75}
  76
  77static int dummy_stm_init(void)
  78{
  79        int i, ret = -ENOMEM;
  80
  81        if (nr_dummies < 0 || nr_dummies > DUMMY_STM_MAX)
  82                return -EINVAL;
  83
  84        if (master_min > master_max ||
  85            master_max > STP_MASTER_MAX ||
  86            nr_channels > STP_CHANNEL_MAX)
  87                return -EINVAL;
  88
  89        for (i = 0; i < nr_dummies; i++) {
  90                dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i);
  91                if (!dummy_stm[i].name)
  92                        goto fail_unregister;
  93
  94                dummy_stm[i].sw_start           = master_min;
  95                dummy_stm[i].sw_end             = master_max;
  96                dummy_stm[i].sw_nchannels       = nr_channels;
  97                dummy_stm[i].packet             = dummy_stm_packet;
  98                dummy_stm[i].link               = dummy_stm_link;
  99
 100                ret = stm_register_device(NULL, &dummy_stm[i], THIS_MODULE);
 101                if (ret)
 102                        goto fail_free;
 103        }
 104
 105        return 0;
 106
 107fail_unregister:
 108        for (i--; i >= 0; i--) {
 109                stm_unregister_device(&dummy_stm[i]);
 110fail_free:
 111                kfree(dummy_stm[i].name);
 112        }
 113
 114        return ret;
 115
 116}
 117
 118static void dummy_stm_exit(void)
 119{
 120        int i;
 121
 122        for (i = 0; i < nr_dummies; i++) {
 123                stm_unregister_device(&dummy_stm[i]);
 124                kfree(dummy_stm[i].name);
 125        }
 126}
 127
 128module_init(dummy_stm_init);
 129module_exit(dummy_stm_exit);
 130
 131MODULE_LICENSE("GPL v2");
 132MODULE_DESCRIPTION("dummy_stm device");
 133MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");
 134