/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2008 Maxime Bizon */ #include #include #include #include #include #include #include "pci-bcm63xx.h" /* * swizzle 32bits data to return only the needed part */ static int postprocess_read(u32 data, int where, unsigned int size) { u32 ret; ret = 0; switch (size) { case 1: ret = (data >> ((where & 3) << 3)) & 0xff; break; case 2: ret = (data >> ((where & 3) << 3)) & 0xffff; break; case 4: ret = data; break; } return ret; } static int preprocess_write(u32 orig_data, u32 val, int where, unsigned int size) { u32 ret; ret = 0; switch (size) { case 1: ret = (orig_data & ~(0xff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); break; case 2: ret = (orig_data & ~(0xffff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); break; case 4: ret = val; break; } return ret; } /* * setup hardware for a configuration cycle with given parameters */ static int bcm63xx_setup_cfg_access(int type, unsigned int busn, unsigned int devfn, int where) { unsigned int slot, func, reg; u32 val; slot = PCI_SLOT(devfn); func = PCI_FUNC(devfn); reg = where >> 2; /* sanity check */ if (slot > (MPI_L2PCFG_DEVNUM_MASK >> MPI_L2PCFG_DEVNUM_SHIFT)) return 1; if (func > (MPI_L2PCFG_FUNC_MASK >> MPI_L2PCFG_FUNC_SHIFT)) return 1; if (reg > (MPI_L2PCFG_REG_MASK >> MPI_L2PCFG_REG_SHIFT)) return 1; /* ok, setup config access */ val = (reg << MPI_L2PCFG_REG_SHIFT); val |= (func << MPI_L2PCFG_FUNC_SHIFT); val |= (slot << MPI_L2PCFG_DEVNUM_SHIFT); val |= MPI_L2PCFG_CFG_USEREG_MASK; val |= MPI_L2PCFG_CFG_SEL_MASK; /* type 0 cycle for local bus, type 1 cycle for anything else */ if (type != 0) { /* FIXME: how to specify bus ??? */ val |= (1 << MPI_L2PCFG_CFG_TYPE_SHIFT); } bcm_mpi_writel(val, MPI_L2PCFG_REG); return 0; } static int bcm63xx_do_cfg_read(int type, unsigned int busn, unsigned int devfn, int where, int size, u32 *val) { u32 data; /* two phase cycle, first we write address, then read data at * another location, caller already has a spinlock so no need * to add one here */ if (bcm63xx_setup_cfg_access(type, busn, devfn, where)) return PCIBIOS_DEVICE_NOT_FOUND; iob(); data = le32_to_cpu(__raw_readl(pci_iospace_start)); /* restore IO space normal behaviour */ bcm_mpi_writel(0, MPI_L2PCFG_REG); *val = postprocess_read(data, where, size); return PCIBIOS_SUCCESSFUL; } static int bcm63xx_do_cfg_write(int type, unsigned int busn, unsigned int devfn, int where, int size, u32 val) { u32 data; /* two phase cycle, first we write address, then write data to * another location, caller already has a spinlock so no need * to add one here */ if (bcm63xx_setup_cfg_access(type, busn, devfn, where)) return PCIBIOS_DEVICE_NOT_FOUND; iob(); data = le32_to_cpu(__raw_readl(pci_iospace_start)); data = preprocess_write(data, val, where, size); __raw_writel(cpu_to_le32(data), pci_iospace_start); wmb(); /* no way to know the access is done, we have to wait */ udelay(500); /* restore IO space normal behaviour */ bcm_mpi_writel(0, MPI_L2PCFG_REG); return PCIBIOS_SUCCESSFUL; } static int bcm63xx_pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val) { int type; type = bus->parent ? 1 : 0; if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL) return PCIBIOS_DEVICE_NOT_FOUND; return bcm63xx_do_cfg_read(type, bus->number, devfn, where, size, val); } static int bcm63xx_pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val) { int type; type = bus->parent ? 1 : 0; if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL) return PCIBIOS_DEVICE_NOT_FOUND; return bcm63xx_do_cfg_write(type, bus->number, devfn, where, size, val); } struct pci_ops bcm63xx_pci_ops = { .read = bcm63xx_pci_read, .write = bcm63xx_pci_write }; #ifdef CONFIG_CARDBUS /* * emulate configuration read access on a cardbus bridge */ #define FAKE_CB_BRIDGE_SLOT 0x1e static int fake_cb_bridge_bus_number = -1; static struct { u16 pci_command; u8 cb_latency; u8 subordinate_busn; u8 cardbus_busn; u8 pci_busn; int bus_assigned; u16 bridge_control; u32 mem_base0; u32 mem_limit0; u32 mem_base1; u32 mem_limit1; u32 io_base0; u32 io_limit0; u32 io_base1; u32 io_limit1; } fake_cb_bridge_regs; static int fake_cb_bridge_read(int where, int size, u32 *val) { unsigned int reg; u32 data; data = 0; reg = where >> 2; switch (reg) { case (PCI_VENDOR_ID >> 2): case (PCI_CB_SUBSYSTEM_VENDOR_ID >> 2): /* create dummy vendor/device id from our cpu id */ data = (bcm63xx_get_cpu_id() << 16) | PCI_VENDOR_ID_BROADCOM; break; case (PCI_COMMAND >> 2): data = (PCI_STATUS_DEVSEL_SLOW << 16); data |= fake_cb_bridge_regs.pci_command; break; case (PCI_CLASS_REVISION >> 2): data = (PCI_CLASS_BRIDGE_CARDBUS << 16); break; case (PCI_CACHE_LINE_SIZE >> 2): data = (PCI_HEADER_TYPE_CARDBUS << 16); break; case (PCI_INTERRUPT_LINE >> 2): /* bridge control */ data = (fake_cb_bridge_regs.bridge_control << 16); /* pin:intA line:0xff */ data |= (0x1 << 8) | 0xff; break; case (PCI_CB_PRIMARY_BUS >> 2): data = (fake_cb_bridge_regs.cb_latency << 24); data |= (fake_cb_bridge_regs.subordinate_busn << 16); data |= (fake_cb_bridge_regs.cardbus_busn << 8); data |= fake_cb_bridge_regs.pci_busn; break; case (PCI_CB_MEMORY_BASE_0 >> 2): data = fake_cb_bridge_regs.mem_base0; break; case (PCI_CB_MEMORY_LIMIT_0 >> 2): data = fake_cb_bridge_regs.mem_limit0; break; case (PCI_CB_MEMORY_BASE_1 >> 2): data = fake_cb_bridge_regs.mem_base1; break; case (PCI_CB_MEMORY_LIMIT_1 >> 2): data = fake_cb_bridge_regs.mem_limit1; break; case (PCI_CB_IO_BASE_0 >> 2): /* | 1 for 32bits io support */ data = fake_cb_bridge_regs.io_base0 | 0x1; break; case (PCI_CB_IO_LIMIT_0 >> 2): data = fake_cb_bridge_regs.io_limit0; break; case (PCI_CB_IO_BASE_1 >> 2): /* | 1 for 32bits io support */ data = fake_cb_bridge_regs.io_base1 | 0x1; break; case (PCI_CB_IO_LIMIT_1 >> 2): data = fake_cb_bridge_regs.io_limit1; break; } *val = postprocess_read(data, where, size); return PCIBIOS_SUCCESSFUL; } /* * emulate configuration write access on a cardbus bridge */ static int fake_cb_bridge_write(int where, int size, u32 val) { unsigned int reg; u32 data, tmp; int ret; ret = fake_cb_bridge_read((where & ~0x3), 4, &data); if (ret != PCIBIOS_SUCCESSFUL) return ret; data = preprocess_write(data, val, where, size); reg = where >> 2; switch (reg) { case (PCI_COMMAND >> 2): fake_cb_bridge_regs.pci_command = (data & 0xffff); break; case (PCI_CB_PRIMARY_BUS >> 2): fake_cb_bridge_regs.cb_latency = (data >> 24) & 0xff; fake_cb_bridge_regs.subordinate_busn = (data >> 16) & 0xff; fake_cb_bridge_regs.cardbus_busn = (data >> 8) & 0xff; fake_cb_bridge_regs.pci_busn = data & 0xff; if (fake_cb_bridge_regs.cardbus_busn) fake_cb_bridge_regs.bus_assigned = 1; break; case (PCI_INTERRUPT_LINE >> 2): tmp = (data >> 16) & 0xffff; /* disable memory prefetch support */ tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0; tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1; fake_cb_bridge_regs.bridge_control = tmp; break; case (PCI_CB_MEMORY_BASE_0 >> 2): fake_cb_bridge_regs.mem_base0 = data; break; case (PCI_CB_MEMORY_LIMIT_0 >> 2): fake_cb_bridge_regs.mem_limit0 = data; break; case (PCI_CB_MEMORY_BASE_1 >> 2): fake_cb_bridge_regs.mem_base1 = data; break; case (PCI_CB_MEMORY_LIMIT_1 >> 2): fake_cb_bridge_regs.mem_limit1 = data; break; case (PCI_CB_IO_BASE_0 >> 2): fake_cb_bridge_regs.io_base0 = data; break; case (PCI_CB_IO_LIMIT_0 >> 2): fake_cb_bridge_regs.io_limit0 = data; break; case (PCI_CB_IO_BASE_1 >> 2): fake_cb_bridge_regs.io_base1 = data; break; case (PCI_CB_IO_LIMIT_1 >> 2): fake_cb_bridge_regs.io_limit1 = data; break; } return PCIBIOS_SUCCESSFUL; } static int bcm63xx_cb_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val) { /* snoop access to slot 0x1e on root bus, we fake a cardbus * bridge at this location */ if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) { fake_cb_bridge_bus_number = bus->number; return fake_cb_bridge_read(where, size, val); } /* a configuration cycle for the device behind the cardbus * bridge is actually done as a type 0 cycle on the primary * bus. This means that only one device can be on the cardbus * bus */ if (fake_cb_bridge_regs.bus_assigned && bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(devfn) == 0) return bcm63xx_do_cfg_read(0, 0, PCI_DEVFN(CARDBUS_PCI_IDSEL, 0), where, size, val); return PCIBIOS_DEVICE_NOT_FOUND; } static int bcm63xx_cb_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val) { if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) { fake_cb_bridge_bus_number = bus->number; return fake_cb_bridge_write(where, size, val); } if (fake_cb_bridge_regs.bus_assigned && bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(devfn) == 0) return bcm63xx_do_cfg_write(0, 0, PCI_DEVFN(CARDBUS_PCI_IDSEL, 0), where, size, val); return PCIBIOS_DEVICE_NOT_FOUND; } struct pci_ops bcm63xx_cb_ops = { .read = bcm63xx_cb_read, .write = bcm63xx_cb_write, }; /* * only one IO window, so it cannot be shared by PCI and cardbus, use * fixup to choose and detect unhandled configuration */ static void bcm63xx_fixup(struct pci_dev *dev) { static int io_window = -1; int i, found, new_io_window; u32 val; /* look for any io resource */ found = 0; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { if (pci_resource_flags(dev, i) & IORESOURCE_IO) { found = 1; break; } } if (!found) return; /* skip our fake bus with only cardbus bridge on it */ if (dev->bus->number == fake_cb_bridge_bus_number) return; /* find on which bus the device is */ if (fake_cb_bridge_regs.bus_assigned && dev->bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(dev->devfn) == 0) new_io_window = 1; else new_io_window = 0; if (new_io_window == io_window) return; if (io_window != -1) { printk(KERN_ERR "bcm63xx: both PCI and cardbus devices " "need IO, which hardware cannot do\n"); return; } printk(KERN_INFO "bcm63xx: PCI IO window assigned to %s\n", (new_io_window == 0) ? "PCI" : "cardbus"); val = bcm_mpi_readl(MPI_L2PIOREMAP_REG); if (io_window) val |= MPI_L2PREMAP_IS_CARDBUS_MASK; else val &= ~MPI_L2PREMAP_IS_CARDBUS_MASK; bcm_mpi_writel(val, MPI_L2PIOREMAP_REG); io_window = new_io_window; } DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, bcm63xx_fixup); #endif 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
/*
 * Runtime locking correctness validator
 *
 *  Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
 *  Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
 *
 * see Documentation/lockdep-design.txt for more details.
 */
#ifndef __LINUX_LOCKDEP_H
#define __LINUX_LOCKDEP_H

struct task_struct;
struct lockdep_map;

#ifdef CONFIG_LOCKDEP

#include <linux/linkage.h>
#include <linux/list.h>
#include <linux/debug_locks.h>
#include <linux/stacktrace.h>

/*
 * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
 * the total number of states... :-(
 */
#define XXX_LOCK_USAGE_STATES		(1+3*4)

#define MAX_LOCKDEP_SUBCLASSES		8UL

/*
 * Lock-classes are keyed via unique addresses, by embedding the
 * lockclass-key into the kernel (or module) .data section. (For
 * static locks we use the lock address itself as the key.)
 */
struct lockdep_subclass_key {
	char __one_byte;
} __attribute__ ((__packed__));

struct lock_class_key {
	struct lockdep_subclass_key	subkeys[MAX_LOCKDEP_SUBCLASSES];
};

#define LOCKSTAT_POINTS		4

/*
 * The lock-class itself:
 */
struct lock_class {
	/*
	 * class-hash:
	 */
	struct list_head		hash_entry;

	/*
	 * global list of all lock-classes:
	 */
	struct list_head		lock_entry;

	struct lockdep_subclass_key	*key;
	unsigned int			subclass;
	unsigned int			dep_gen_id;

	/*
	 * IRQ/softirq usage tracking bits:
	 */
	unsigned long			usage_mask;
	struct stack_trace		usage_traces[XXX_LOCK_USAGE_STATES];

	/*
	 * These fields represent a directed graph of lock dependencies,
	 * to every node we attach a list of "forward" and a list of
	 * "backward" graph nodes.
	 */
	struct list_head		locks_after, locks_before;

	/*
	 * Generation counter, when doing certain classes of graph walking,
	 * to ensure that we check one node only once:
	 */
	unsigned int			version;

	/*
	 * Statistics counter:
	 */
	unsigned long			ops;

	const char			*name;
	int				name_version;

#ifdef CONFIG_LOCK_STAT
	unsigned long			contention_point[LOCKSTAT_POINTS];
	unsigned long			contending_point[LOCKSTAT_POINTS];
#endif
};

#ifdef CONFIG_LOCK_STAT
struct lock_time {
	s64				min;
	s64				max;
	s64				total;
	unsigned long			nr;
};

enum bounce_type {
	bounce_acquired_write,
	bounce_acquired_read,
	bounce_contended_write,
	bounce_contended_read,
	nr_bounce_types,

	bounce_acquired = bounce_acquired_write,
	bounce_contended = bounce_contended_write,
};

struct lock_class_stats {
	unsigned long			contention_point[4];
	unsigned long			contending_point[4];
	struct lock_time		read_waittime;
	struct lock_time		write_waittime;
	struct lock_time		read_holdtime;
	struct lock_time		write_holdtime;
	unsigned long			bounces[nr_bounce_types];
};

struct lock_class_stats lock_stats(struct lock_class *class);
void clear_lock_stats(struct lock_class *class);
#endif

/*
 * Map the lock object (the lock instance) to the lock-class object.
 * This is embedded into specific lock instances:
 */
struct lockdep_map {
	struct lock_class_key		*key;
	struct lock_class		*class_cache;
	const char			*name;
#ifdef CONFIG_LOCK_STAT
	int				cpu;
	unsigned long			ip;
#endif
};

/*
 * Every lock has a list of other locks that were taken after it.
 * We only grow the list, never remove from it:
 */
struct lock_list {
	struct list_head		entry;
	struct lock_class		*class;
	struct stack_trace		trace;
	int				distance;

	/*
	 * The parent field is used to implement breadth-first search, and the
	 * bit 0 is reused to indicate if the lock has been accessed in BFS.
	 */
	struct lock_list		*parent;
};

/*
 * We record lock dependency chains, so that we can cache them:
 */
struct lock_chain {
	u8				irq_context;
	u8				depth;
	u16				base;
	struct list_head		entry;
	u64				chain_key;
};

#define MAX_LOCKDEP_KEYS_BITS		13
/*
 * Subtract one because we offset hlock->class_idx by 1 in order
 * to make 0 mean no class. This avoids overflowing the class_idx
 * bitfield and hitting the BUG in hlock_class().
 */
#define MAX_LOCKDEP_KEYS		((1UL << MAX_LOCKDEP_KEYS_BITS) - 1)

struct held_lock {
	/*
	 * One-way hash of the dependency chain up to this point. We
	 * hash the hashes step by step as the dependency chain grows.
	 *
	 * We use it for dependency-caching and we skip detection
	 * passes and dependency-updates if there is a cache-hit, so
	 * it is absolutely critical for 100% coverage of the validator
	 * to have a unique key value for every unique dependency path
	 * that can occur in the system, to make a unique hash value
	 * as likely as possible - hence the 64-bit width.
	 *
	 * The task struct holds the current hash value (initialized
	 * with zero), here we store the previous hash value:
	 */
	u64				prev_chain_key;
	unsigned long			acquire_ip;
	struct lockdep_map		*instance;
	struct lockdep_map		*nest_lock;
#ifdef CONFIG_LOCK_STAT
	u64 				waittime_stamp;
	u64				holdtime_stamp;
#endif
	unsigned int			class_idx:MAX_LOCKDEP_KEYS_BITS;
	/*
	 * The lock-stack is unified in that the lock chains of interrupt
	 * contexts nest ontop of process context chains, but we 'separate'
	 * the hashes by starting with 0 if we cross into an interrupt
	 * context, and we also keep do not add cross-context lock
	 * dependencies - the lock usage graph walking covers that area
	 * anyway, and we'd just unnecessarily increase the number of
	 * dependencies otherwise. [Note: hardirq and softirq contexts
	 * are separated from each other too.]
	 *
	 * The following field is used to detect when we cross into an
	 * interrupt context:
	 */
	unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
	unsigned int trylock:1;						/* 16 bits */

	unsigned int read:2;        /* see lock_acquire() comment */
	unsigned int check:2;       /* see lock_acquire() comment */
	unsigned int hardirqs_off:1;
	unsigned int references:11;					/* 32 bits */
};

/*
 * Initialization, self-test and debugging-output methods:
 */
extern void lockdep_init(void);
extern void lockdep_info(void);
extern void lockdep_reset(void);
extern void lockdep_reset_lock(struct lockdep_map *lock);
extern void lockdep_free_key_range(void *start, unsigned long size);
extern void lockdep_sys_exit(void);

extern void lockdep_off(void);
extern void lockdep_on(void);

/*
 * These methods are used by specific locking variants (spinlocks,
 * rwlocks, mutexes and rwsems) to pass init/acquire/release events
 * to lockdep:
 */

extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
			     struct lock_class_key *key, int subclass);

/*
 * To initialize a lockdep_map statically use this macro.
 * Note that _name must not be NULL.
 */
#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
	{ .name = (_name), .key = (void *)(_key), }

/*
 * Reinitialize a lock key - for cases where there is special locking or
 * special initialization of locks so that the validator gets the scope
 * of dependencies wrong: they are either too broad (they need a class-split)
 * or they are too narrow (they suffer from a false class-split):
 */
#define lockdep_set_class(lock, key) \
		lockdep_init_map(&(lock)->dep_map, #key, key, 0)
#define lockdep_set_class_and_name(lock, key, name) \
		lockdep_init_map(&(lock)->dep_map, name, key, 0)
#define lockdep_set_class_and_subclass(lock, key, sub) \
		lockdep_init_map(&(lock)->dep_map, #key, key, sub)
#define lockdep_set_subclass(lock, sub)	\
		lockdep_init_map(&(lock)->dep_map, #lock, \
				 (lock)->dep_map.key, sub)
/*
 * Compare locking classes
 */
#define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)

static inline int lockdep_match_key(struct lockdep_map *lock,
				    struct lock_class_key *key)
{
	return lock->key == key;
}

/*
 * Acquire a lock.
 *
 * Values for "read":
 *
 *   0: exclusive (write) acquire
 *   1: read-acquire (no recursion allowed)
 *   2: read-acquire with same-instance recursion allowed
 *
 * Values for check:
 *
 *   0: disabled
 *   1: simple checks (freeing, held-at-exit-time, etc.)
 *   2: full validation
 */
extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
			 int trylock, int read, int check,
			 struct lockdep_map *nest_lock, unsigned long ip);

extern void lock_release(struct lockdep_map *lock, int nested,
			 unsigned long ip);

#define lockdep_is_held(lock)	lock_is_held(&(lock)->dep_map)

extern int lock_is_held(struct lockdep_map *lock);

extern void lock_set_class(struct lockdep_map *lock, const char *name,
			   struct lock_class_key *key, unsigned int subclass,
			   unsigned long ip);

static inline void lock_set_subclass(struct lockdep_map *lock,
		unsigned int subclass, unsigned long ip)
{
	lock_set_class(lock, lock->name, lock->key, subclass, ip);
}

extern void lockdep_set_current_reclaim_state(gfp_t gfp_mask);
extern void lockdep_clear_current_reclaim_state(void);
extern void lockdep_trace_alloc(gfp_t mask);

# define INIT_LOCKDEP				.lockdep_recursion = 0, .lockdep_reclaim_gfp = 0,

#define lockdep_depth(tsk)	(debug_locks ? (tsk)->lockdep_depth : 0)

#define lockdep_assert_held(l)	WARN_ON(debug_locks && !lockdep_is_held(l))

#else /* !LOCKDEP */

static inline void lockdep_off(void)
{
}

static inline void lockdep_on(void)
{
}

# define lock_acquire(l, s, t, r, c, n, i)	do { } while (0)
# define lock_release(l, n, i)			do { } while (0)
# define lock_set_class(l, n, k, s, i)		do { } while (0)
# define lock_set_subclass(l, s, i)		do { } while (0)
# define lockdep_set_current_reclaim_state(g)	do { } while (0)
# define lockdep_clear_current_reclaim_state()	do { } while (0)
# define lockdep_trace_alloc(g)			do { } while (0)
# define lockdep_init()				do { } while (0)
# define lockdep_info()				do { } while (0)
# define lockdep_init_map(lock, name, key, sub) \
		do { (void)(name); (void)(key); } while (0)
# define lockdep_set_class(lock, key)		do { (void)(key); } while (0)
# define lockdep_set_class_and_name(lock, key, name) \
		do { (void)(key); (void)(name); } while (0)
#define lockdep_set_class_and_subclass(lock, key, sub) \
		do { (void)(key); } while (0)
#define lockdep_set_subclass(lock, sub)		do { } while (0)
/*
 * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
 * case since the result is not well defined and the caller should rather
 * #ifdef the call himself.
 */

# define INIT_LOCKDEP
# define lockdep_reset()		do { debug_locks = 1; } while (0)
# define lockdep_free_key_range(start, size)	do { } while (0)
# define lockdep_sys_exit() 			do { } while (0)
/*
 * The class key takes no space if lockdep is disabled:
 */
struct lock_class_key { };

#define lockdep_depth(tsk)	(0)

#define lockdep_assert_held(l)			do { } while (0)

#endif /* !LOCKDEP */

#ifdef CONFIG_LOCK_STAT

extern void lock_contended(struct lockdep_map *lock, unsigned long ip);
extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);

#define LOCK_CONTENDED(_lock, try, lock)			\
do {								\
	if (!try(_lock)) {					\
		lock_contended(&(_lock)->dep_map, _RET_IP_);	\
		lock(_lock);					\
	}							\
	lock_acquired(&(_lock)->dep_map, _RET_IP_);			\
} while (0)

#else /* CONFIG_LOCK_STAT */

#define lock_contended(lockdep_map, ip) do {} while (0)
#define lock_acquired(lockdep_map, ip) do {} while (0)

#define LOCK_CONTENDED(_lock, try, lock) \
	lock(_lock)

#endif /* CONFIG_LOCK_STAT */

#ifdef CONFIG_LOCKDEP

/*
 * On lockdep we dont want the hand-coded irq-enable of
 * _raw_*_lock_flags() code, because lockdep assumes
 * that interrupts are not re-enabled during lock-acquire:
 */
#define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
	LOCK_CONTENDED((_lock), (try), (lock))

#else /* CONFIG_LOCKDEP */

#define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
	lockfl((_lock), (flags))

#endif /* CONFIG_LOCKDEP */

#ifdef CONFIG_GENERIC_HARDIRQS
extern void early_init_irq_lock_class(void);
#else
static inline void early_init_irq_lock_class(void)
{
}
#endif

#ifdef CONFIG_TRACE_IRQFLAGS
extern void early_boot_irqs_off(void);
extern void early_boot_irqs_on(void);
extern void print_irqtrace_events(struct task_struct *curr);
#else
static inline void early_boot_irqs_off(void)
{
}
static inline void early_boot_irqs_on(void)
{
}
static inline void print_irqtrace_events(struct task_struct *curr)
{
}
#endif

/*
 * For trivial one-depth nesting of a lock-class, the following
 * global define can be used. (Subsystems with multiple levels
 * of nesting should define their own lock-nesting subclasses.)
 */
#define SINGLE_DEPTH_NESTING			1

/*
 * Map the dependency ops to NOP or to real lockdep ops, depending
 * on the per lock-class debug mode:
 */

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define spin_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
#  define spin_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 2, n, i)
# else
#  define spin_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
#  define spin_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 1, NULL, i)
# endif
# define spin_release(l, n, i)			lock_release(l, n, i)
#else
# define spin_acquire(l, s, t, i)		do { } while (0)
# define spin_release(l, n, i)			do { } while (0)
#endif

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define rwlock_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
#  define rwlock_acquire_read(l, s, t, i)	lock_acquire(l, s, t, 2, 2, NULL, i)
# else
#  define rwlock_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
#  define rwlock_acquire_read(l, s, t, i)	lock_acquire(l, s, t, 2, 1, NULL, i)
# endif
# define rwlock_release(l, n, i)		lock_release(l, n, i)
#else
# define rwlock_acquire(l, s, t, i)		do { } while (0)
# define rwlock_acquire_read(l, s, t, i)	do { } while (0)
# define rwlock_release(l, n, i)		do { } while (0)
#endif

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define mutex_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
# else
#  define mutex_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
# endif
# define mutex_release(l, n, i)			lock_release(l, n, i)
#else
# define mutex_acquire(l, s, t, i)		do { } while (0)
# define mutex_release(l, n, i)			do { } while (0)
#endif

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define rwsem_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
#  define rwsem_acquire_read(l, s, t, i)	lock_acquire(l, s, t, 1, 2, NULL, i)
# else
#  define rwsem_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
#  define rwsem_acquire_read(l, s, t, i)	lock_acquire(l, s, t, 1, 1, NULL, i)
# endif
# define rwsem_release(l, n, i)			lock_release(l, n, i)
#else
# define rwsem_acquire(l, s, t, i)		do { } while (0)
# define rwsem_acquire_read(l, s, t, i)		do { } while (0)
# define rwsem_release(l, n, i)			do { } while (0)
#endif

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define lock_map_acquire(l)		lock_acquire(l, 0, 0, 0, 2, NULL, _THIS_IP_)
# else
#  define lock_map_acquire(l)		lock_acquire(l, 0, 0, 0, 1, NULL, _THIS_IP_)
# endif
# define lock_map_release(l)			lock_release(l, 1, _THIS_IP_)
#else
# define lock_map_acquire(l)			do { } while (0)
# define lock_map_release(l)			do { } while (0)
#endif

#ifdef CONFIG_PROVE_LOCKING
# define might_lock(lock) 						\
do {									\
	typecheck(struct lockdep_map *, &(lock)->dep_map);		\
	lock_acquire(&(lock)->dep_map, 0, 0, 0, 2, NULL, _THIS_IP_);	\
	lock_release(&(lock)->dep_map, 0, _THIS_IP_);			\
} while (0)
# define might_lock_read(lock) 						\
do {									\
	typecheck(struct lockdep_map *, &(lock)->dep_map);		\
	lock_acquire(&(lock)->dep_map, 0, 0, 1, 2, NULL, _THIS_IP_);	\
	lock_release(&(lock)->dep_map, 0, _THIS_IP_);			\
} while (0)
#else
# define might_lock(lock) do { } while (0)
# define might_lock_read(lock) do { } while (0)
#endif

#endif /* __LINUX_LOCKDEP_H */