drm/nv50: fix iommu errors caused by device reading from address 0
[safe/jmp/linux-2.6] / drivers / ieee1394 / csr1212.h
index 86f23d6..a892d92 100644 (file)
 #ifndef __CSR1212_H__
 #define __CSR1212_H__
 
-
-/* Compatibility layer */
-#ifdef __KERNEL__
-
 #include <linux/types.h>
 #include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/vmalloc.h>
-#include <asm/pgalloc.h>
-
-#define CSR1212_MALLOC(size)           vmalloc((size))
-#define CSR1212_FREE(ptr)              vfree(ptr)
-#define CSR1212_BE16_TO_CPU(quad)      be16_to_cpu(quad)
-#define CSR1212_CPU_TO_BE16(quad)      cpu_to_be16(quad)
-#define CSR1212_BE32_TO_CPU(quad)      be32_to_cpu(quad)
-#define CSR1212_CPU_TO_BE32(quad)      cpu_to_be32(quad)
-#define CSR1212_BE64_TO_CPU(quad)      be64_to_cpu(quad)
-#define CSR1212_CPU_TO_BE64(quad)      cpu_to_be64(quad)
-
-#define CSR1212_LE16_TO_CPU(quad)      le16_to_cpu(quad)
-#define CSR1212_CPU_TO_LE16(quad)      cpu_to_le16(quad)
-#define CSR1212_LE32_TO_CPU(quad)      le32_to_cpu(quad)
-#define CSR1212_CPU_TO_LE32(quad)      cpu_to_le32(quad)
-#define CSR1212_LE64_TO_CPU(quad)      le64_to_cpu(quad)
-#define CSR1212_CPU_TO_LE64(quad)      cpu_to_le64(quad)
-
-#include <linux/errno.h>
-#define CSR1212_SUCCESS (0)
-#define CSR1212_EINVAL (-EINVAL)
-#define CSR1212_ENOMEM (-ENOMEM)
-#define CSR1212_ENOENT (-ENOENT)
-#define CSR1212_EIO    (-EIO)
-#define CSR1212_EBUSY  (-EBUSY)
-
-#else  /* Userspace */
-
-#include <sys/types.h>
-#include <malloc.h>
-#define CSR1212_MALLOC(size)           malloc(size)
-#define CSR1212_FREE(ptr)              free(ptr)
-#include <endian.h>
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#include <byteswap.h>
-#define CSR1212_BE16_TO_CPU(quad)      bswap_16(quad)
-#define CSR1212_CPU_TO_BE16(quad)      bswap_16(quad)
-#define CSR1212_BE32_TO_CPU(quad)      bswap_32(quad)
-#define CSR1212_CPU_TO_BE32(quad)      bswap_32(quad)
-#define CSR1212_BE64_TO_CPU(quad)      bswap_64(quad)
-#define CSR1212_CPU_TO_BE64(quad)      bswap_64(quad)
-
-#define CSR1212_LE16_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_LE16(quad)      (quad)
-#define CSR1212_LE32_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_LE32(quad)      (quad)
-#define CSR1212_LE64_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_LE64(quad)      (quad)
-#else
-#define CSR1212_BE16_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_BE16(quad)      (quad)
-#define CSR1212_BE32_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_BE32(quad)      (quad)
-#define CSR1212_BE64_TO_CPU(quad)      (quad)
-#define CSR1212_CPU_TO_BE64(quad)      (quad)
-
-#define CSR1212_LE16_TO_CPU(quad)      bswap_16(quad)
-#define CSR1212_CPU_TO_LE16(quad)      bswap_16(quad)
-#define CSR1212_LE32_TO_CPU(quad)      bswap_32(quad)
-#define CSR1212_CPU_TO_LE32(quad)      bswap_32(quad)
-#define CSR1212_LE64_TO_CPU(quad)      bswap_64(quad)
-#define CSR1212_CPU_TO_LE64(quad)      bswap_64(quad)
-#endif
-
-#include <errno.h>
-#define CSR1212_SUCCESS (0)
-#define CSR1212_EINVAL (EINVAL)
-#define CSR1212_ENOMEM (ENOMEM)
-#define CSR1212_ENOENT (ENOENT)
-#define CSR1212_EIO    (EIO)
-#define CSR1212_EBUSY  (EBUSY)
+#include <asm/atomic.h>
 
-#endif
+#define CSR1212_MALLOC(size)   kmalloc((size), GFP_KERNEL)
+#define CSR1212_FREE(ptr)      kfree(ptr)
+
+#define CSR1212_SUCCESS (0)
 
 
 /* CSR 1212 key types */
 
 /* Config ROM image structures */
 struct csr1212_bus_info_block_img {
-       u_int8_t length;
-       u_int8_t crc_length;
-       u_int16_t crc;
+       u8 length;
+       u8 crc_length;
+       u16 crc;
 
        /* Must be last */
-       u_int32_t data[0];      /* older gcc can't handle [] which is standard */
+       u32 data[0];    /* older gcc can't handle [] which is standard */
 };
 
-typedef u_int32_t csr1212_quad_t;
-
 struct csr1212_leaf {
        int len;
-       u_int32_t *data;
+       u32 *data;
 };
 
 struct csr1212_dentry {
@@ -215,29 +140,29 @@ struct csr1212_directory {
 
 struct csr1212_keyval {
        struct {
-               u_int8_t type;
-               u_int8_t id;
+               u8 type;
+               u8 id;
        } key;
        union {
-               u_int32_t immediate;
-               u_int32_t csr_offset;
+               u32 immediate;
+               u32 csr_offset;
                struct csr1212_leaf leaf;
                struct csr1212_directory directory;
        } value;
        struct csr1212_keyval *associate;
-       int refcnt;
+       atomic_t refcnt;
 
        /* used in generating and/or parsing CSR image */
        struct csr1212_keyval *next, *prev;     /* flat list of CSR elements */
-       u_int32_t offset;       /* position in CSR from 0xffff f000 0000 */
-       u_int8_t valid;         /* flag indicating keyval has valid data*/
+       u32 offset;     /* position in CSR from 0xffff f000 0000 */
+       u8 valid;       /* flag indicating keyval has valid data*/
 };
 
 
 struct csr1212_cache_region {
        struct csr1212_cache_region *next, *prev;
-       u_int32_t offset_start;         /* inclusive */
-       u_int32_t offset_end;           /* exclusive */
+       u32 offset_start;       /* inclusive */
+       u32 offset_end;         /* exclusive */
 };
 
 struct csr1212_csr_rom_cache {
@@ -245,18 +170,18 @@ struct csr1212_csr_rom_cache {
        struct csr1212_cache_region *filled_head, *filled_tail;
        struct csr1212_keyval *layout_head, *layout_tail;
        size_t size;
-       u_int32_t offset;
+       u32 offset;
        struct csr1212_keyval *ext_rom;
        size_t len;
 
        /* Must be last */
-       u_int32_t data[0];      /* older gcc can't handle [] which is standard */
+       u32 data[0];    /* older gcc can't handle [] which is standard */
 };
 
 struct csr1212_csr {
        size_t bus_info_len;    /* bus info block length in bytes */
        size_t crc_len;         /* crc length in bytes */
-       u_int32_t *bus_info_data;       /* bus info data incl bus name and EUI */
+       __be32 *bus_info_data;  /* bus info data incl bus name and EUI */
 
        void *private;          /* private, bus specific data */
        struct csr1212_bus_ops *ops;
@@ -274,37 +199,31 @@ struct csr1212_bus_ops {
         * from remote nodes when parsing a Config ROM (i.e., read Config ROM
         * entries located in the Units Space.  Must return 0 on success
         * anything else indicates an error. */
-       int (*bus_read) (struct csr1212_csr *csr, u_int64_t addr,
-                        u_int16_t length, void *buffer, void *private);
+       int (*bus_read) (struct csr1212_csr *csr, u64 addr,
+                        void *buffer, void *private);
 
        /* This function is used by csr1212 to allocate a region in units space
         * in the event that Config ROM entries don't all fit in the predefined
         * 1K region.  The void *private parameter is private member of struct
         * csr1212_csr. */
-       u_int64_t (*allocate_addr_range) (u_int64_t size, u_int32_t alignment,
-                                         void *private);
-
+       u64 (*allocate_addr_range) (u64 size, u32 alignment, void *private);
 
        /* This function is used by csr1212 to release a region in units space
         * that is no longer needed. */
-       void (*release_addr) (u_int64_t addr, void *private);
-
-       /* This function is used by csr1212 to determine the max read request
-        * supported by a remote node when reading the ConfigROM space.  Must
-        * return 0, 1, or 2 per IEEE 1212.  */
-       int (*get_max_rom) (u_int32_t *bus_info, void *private);
+       void (*release_addr) (u64 addr, void *private);
 };
 
 
 /* Descriptor Leaf manipulation macros */
 #define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24
 #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff
-#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t))
+#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
 
 #define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \
-       (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[0]) >> CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
+       (be32_to_cpu((kv)->value.leaf.data[0]) >> \
+        CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
 #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \
-       (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[0]) & \
+       (be32_to_cpu((kv)->value.leaf.data[0]) & \
         CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)
 
 
@@ -314,17 +233,17 @@ struct csr1212_bus_ops {
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff  /* after shift */
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff
-#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t))
+#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
 
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \
-       (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) >> \
+       (be32_to_cpu((kv)->value.leaf.data[1]) >> \
         CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT)
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \
-       ((CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) >> \
-                            CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \
-                           CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK)
+       ((be32_to_cpu((kv)->value.leaf.data[1]) >> \
+         CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \
+        CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK)
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \
-       (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) & \
+       (be32_to_cpu((kv)->value.leaf.data[1]) & \
         CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)
 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \
        (&((kv)->value.leaf.data[2]))
@@ -338,7 +257,7 @@ extern struct csr1212_csr *csr1212_create_csr(struct csr1212_bus_ops *ops,
                                              size_t bus_info_size,
                                              void *private);
 extern void csr1212_init_local_csr(struct csr1212_csr *csr,
-                                  const u_int32_t *bus_info_data, int max_rom);
+                                  const u32 *bus_info_data, int max_rom);
 
 
 /* Destroy a Configuration ROM tree and release all memory taken by the tree. */
@@ -349,8 +268,8 @@ extern void csr1212_destroy_csr(struct csr1212_csr *csr);
  * a Configuration ROM tree.  Code that creates new keyvals with these functions
  * must release those keyvals with csr1212_release_keyval() when they are no
  * longer needed. */
-extern struct csr1212_keyval *csr1212_new_immediate(u_int8_t key, u_int32_t value);
-extern struct csr1212_keyval *csr1212_new_directory(u_int8_t key);
+extern struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value);
+extern struct csr1212_keyval *csr1212_new_directory(u8 key);
 extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
 
 
@@ -361,8 +280,8 @@ extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
  * Take care with subsequent ROM modifications:  There is no function to remove
  * previously specified associations.
  */
-extern int csr1212_associate_keyval(struct csr1212_keyval *kv,
-                                   struct csr1212_keyval *associate);
+extern void csr1212_associate_keyval(struct csr1212_keyval *kv,
+                                    struct csr1212_keyval *associate);
 
 
 /* The following functions manage the association of a keyval and directories.
@@ -380,8 +299,8 @@ extern int csr1212_generate_csr_image(struct csr1212_csr *csr);
 
 /* This is a convience function for reading a block of data out of one of the
  * caches in the csr->cache_head list. */
-extern int csr1212_read(struct csr1212_csr *csr, u_int32_t offset, void *buffer,
-                       u_int32_t len);
+extern int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer,
+                       u32 len);
 
 
 /* The following functions are in place for parsing Configuration ROM images.
@@ -391,15 +310,11 @@ extern int csr1212_parse_keyval(struct csr1212_keyval *kv,
                                struct csr1212_csr_rom_cache *cache);
 extern int csr1212_parse_csr(struct csr1212_csr *csr);
 
-/* These are internal functions referenced by inline functions below. */
-extern int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
-extern void _csr1212_destroy_keyval(struct csr1212_keyval *kv);
-
 
 /* This function allocates a new cache which may be used for either parsing or
  * generating sub-sets of Configuration ROM images. */
-static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t offset,
-                                                                    size_t size)
+static inline struct csr1212_csr_rom_cache *
+csr1212_rom_cache_malloc(u32 offset, size_t size)
 {
        struct csr1212_csr_rom_cache *cache;
 
@@ -423,23 +338,16 @@ static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t o
 
 /* This function ensures that a keyval contains data when referencing a keyval
  * created by parsing a Configuration ROM. */
-static inline struct csr1212_keyval *csr1212_get_keyval(struct csr1212_csr *csr,
-                                                       struct csr1212_keyval *kv)
-{
-       if (!kv)
-               return NULL;
-       if (!kv->valid)
-               if (_csr1212_read_keyval(csr, kv) != CSR1212_SUCCESS)
-                       return NULL;
-       return kv;
-}
+extern struct csr1212_keyval *
+csr1212_get_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
 
 
 /* This function increments the reference count for a keyval should there be a
  * need for code to retain a keyval that has been parsed. */
 static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
 {
-       kv->refcnt++;
+       atomic_inc(&kv->refcnt);
+       smp_mb__after_atomic_inc();
 }
 
 
@@ -447,37 +355,29 @@ static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
  * keyval when there are no more users of the keyval.  This should be called by
  * any code that calls csr1212_keep_keyval() or any of the keyval creation
  * routines csr1212_new_*(). */
-static inline void csr1212_release_keyval(struct csr1212_keyval *kv)
-{
-       if (kv->refcnt > 1)
-               kv->refcnt--;
-       else
-               _csr1212_destroy_keyval(kv);
-}
+extern void csr1212_release_keyval(struct csr1212_keyval *kv);
 
 
 /*
  * This macro allows for looping over the keyval entries in a directory and it
  * ensures that keyvals from remote ConfigROMs are parsed properly.
  *
- * _csr is a struct csr1212_csr * that points to CSR associated with dir.
- * _kv is a struct csr1212_keyval * that'll point to the current keyval (loop index).
- * _dir is a struct csr1212_keyval * that points to the directory to be looped.
- * _pos is a struct csr1212_dentry * that is used internally for indexing.
+ * struct csr1212_csr *_csr points to the CSR associated with dir.
+ * struct csr1212_keyval *_kv points to the current keyval (loop index).
+ * struct csr1212_keyval *_dir points to the directory to be looped.
+ * struct csr1212_dentry *_pos is used internally for indexing.
  *
  * kv will be NULL upon exit of the loop.
  */
-#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos)                      \
-       for (csr1212_get_keyval((_csr), (_dir)),                                \
-            _pos = (_dir)->value.directory.dentries_head,                      \
-            _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL;        \
-            (_kv) && (_pos);                                                   \
-            (_kv->associate == NULL) ?                                         \
-                    ((_pos = _pos->next),                                      \
-                     (_kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) :    \
-                          NULL)) :                                             \
+#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos)              \
+       for (csr1212_get_keyval((_csr), (_dir)),                        \
+            _pos = (_dir)->value.directory.dentries_head,              \
+            _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL;\
+            (_kv) && (_pos);                                           \
+            (_kv->associate == NULL) ?                                 \
+                    ((_pos = _pos->next), (_kv = (_pos) ?              \
+                               csr1212_get_keyval((_csr), _pos->kv) :  \
+                               NULL)) :                                \
                     (_kv = csr1212_get_keyval((_csr), _kv->associate)))
 
-
-
 #endif /* __CSR1212_H__ */