]> www.infradead.org Git - users/willy/xarray.git/commitdiff
slimbus: Convert tid_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Tue, 8 Jan 2019 20:16:04 +0000 (15:16 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:14 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/slimbus/core.c
drivers/slimbus/messaging.c
drivers/slimbus/sched.c
drivers/slimbus/slimbus.h

index 526e3215d8fe18bb7a29ee4a61b86000c8a8ec56..259c55810bc3ef4f2f16fd20cbc78132880b2e86 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/init.h>
-#include <linux/idr.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
@@ -265,11 +264,11 @@ int slim_register_controller(struct slim_controller *ctrl)
                ctrl->max_cg = SLIM_MAX_CLK_GEAR;
 
        ida_init(&ctrl->laddr_ida);
-       idr_init(&ctrl->tid_idr);
+       xa_init_flags(&ctrl->tids, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
+       ctrl->tid_next = 0;
        mutex_init(&ctrl->lock);
        mutex_init(&ctrl->sched.m_reconf);
        init_completion(&ctrl->sched.pause_comp);
-       spin_lock_init(&ctrl->txn_lock);
 
        dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n",
                ctrl->name, ctrl->dev);
index d5879142dbef1c4903f0e7279c46cf2859af80ea..3dc860d50a3e1134b509e8f22299d0a485754526 100644 (file)
@@ -25,12 +25,8 @@ void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
 {
        struct slim_msg_txn *txn;
        struct slim_val_inf *msg;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ctrl->txn_lock, flags);
-       txn = idr_find(&ctrl->tid_idr, tid);
-       spin_unlock_irqrestore(&ctrl->txn_lock, flags);
 
+       txn = xa_load(&ctrl->tids, tid);
        if (txn == NULL)
                return;
 
@@ -63,23 +59,24 @@ EXPORT_SYMBOL_GPL(slim_msg_response);
 int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn)
 {
        unsigned long flags;
-       int ret = 0;
+       int ret;
+       u32 tid;
+
+       xa_lock_irqsave(&ctrl->tids, flags);
+       ret = __xa_alloc_cyclic(&ctrl->tids, &tid, txn,
+                       XA_LIMIT(0, SLIM_TID_MAX), &ctrl->tid_next, GFP_ATOMIC);
+       xa_unlock_irqrestore(&ctrl->tids, flags);
 
-       spin_lock_irqsave(&ctrl->txn_lock, flags);
-       ret = idr_alloc_cyclic(&ctrl->tid_idr, txn, 0,
-                               SLIM_MAX_TIDS, GFP_ATOMIC);
-       if (ret < 0) {
-               spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+       if (ret < 0)
                return ret;
-       }
-       txn->tid = ret;
-       spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+
+       txn->tid = tid;
        return 0;
 }
 EXPORT_SYMBOL_GPL(slim_alloc_txn_tid);
 
 /**
- * slim_free_txn_tid() - Freee tid of txn
+ * slim_free_txn_tid() - Free tid of txn
  *
  * @ctrl: Controller handle
  * @txn: transaction whose tid should be freed
@@ -88,9 +85,9 @@ void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn)
 {
        unsigned long flags;
 
-       spin_lock_irqsave(&ctrl->txn_lock, flags);
-       idr_remove(&ctrl->tid_idr, txn->tid);
-       spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+       xa_lock_irqsave(&ctrl->tids, flags);
+       __xa_erase(&ctrl->tids, txn->tid);
+       xa_unlock_irqrestore(&ctrl->tids, flags);
 }
 EXPORT_SYMBOL_GPL(slim_free_txn_tid);
 
index af84997d27427e7c5dc731648a08037c6825d086..e8b6963b13d920ee4dae2cd5f8feee30f99827a3 100644 (file)
@@ -24,8 +24,7 @@
  */
 int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart)
 {
-       int i, ret = 0;
-       unsigned long flags;
+       int ret = 0;
        struct slim_sched *sched = &ctrl->sched;
        struct slim_val_inf msg = {0, 0, NULL, NULL};
 
@@ -75,16 +74,10 @@ int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart)
                return 0;
        }
 
-       spin_lock_irqsave(&ctrl->txn_lock, flags);
-       for (i = 0; i < SLIM_MAX_TIDS; i++) {
-               /* Pending response for a message */
-               if (idr_find(&ctrl->tid_idr, i)) {
-                       spin_unlock_irqrestore(&ctrl->txn_lock, flags);
-                       mutex_unlock(&sched->m_reconf);
-                       return -EBUSY;
-               }
+       if (!xa_empty(&ctrl->tids)) {
+               mutex_unlock(&sched->m_reconf);
+               return -EBUSY;
        }
-       spin_unlock_irqrestore(&ctrl->txn_lock, flags);
 
        sched->clk_state = SLIM_CLK_ENTERING_PAUSE;
 
index 9be41089edde7385abd89b87385376d730be7d29..921875049ea8535859671fb508d89e5611e39edd 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mutex.h>
 #include <linux/completion.h>
 #include <linux/slimbus.h>
+#include <linux/xarray.h>
 
 /* Standard values per SLIMbus spec needed by controllers and devices */
 #define SLIM_CL_PER_SUPERFRAME         6144
@@ -86,7 +87,7 @@
 /* Manager's logical address is set to 0xFF per spec */
 #define SLIM_LA_MANAGER 0xFF
 
-#define SLIM_MAX_TIDS                  256
+#define SLIM_TID_MAX                   255
 /**
  * struct slim_framer - Represents SLIMbus framer.
  * Every controller may have multiple framers. There is 1 active framer device
@@ -356,8 +357,8 @@ struct slim_stream_runtime {
  * @a_framer: Active framer which is clocking the bus managed by this controller
  * @lock: Mutex protecting controller data structures
  * @devices: Slim device list
- * @tid_idr: tid id allocator
- * @txn_lock: Lock to protect table of transactions
+ * @tids: tid id allocator
+ * @tid_next: Next tid to allocate
  * @sched: scheduler structure used by the controller
  * @xfer_msg: Transfer a message on this controller (this can be a broadcast
  *     control/status message like data channel setup, or a unicast message
@@ -404,12 +405,12 @@ struct slim_controller {
        int                     min_cg;
        int                     max_cg;
        int                     clkgear;
+       u32                     tid_next;
        struct ida              laddr_ida;
        struct slim_framer      *a_framer;
        struct mutex            lock;
        struct list_head        devices;
-       struct idr              tid_idr;
-       spinlock_t              txn_lock;
+       struct xarray           tids;
        struct slim_sched       sched;
        int                     (*xfer_msg)(struct slim_controller *ctrl,
                                            struct slim_msg_txn *tx);