]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - include/linux/ssb/ssb.h
ssb, b43, b43legacy, b44: Rewrite SSB DMA API
[mirror_ubuntu-artful-kernel.git] / include / linux / ssb / ssb.h
index db53defde5eec14c1238b8a95ccc1e746db35620..0fe5a0ded3eac17f4075d2cbdfcfb88153031238 100644 (file)
@@ -72,10 +72,18 @@ struct ssb_device;
 /* Lowlevel read/write operations on the device MMIO.
  * Internal, don't use that outside of ssb. */
 struct ssb_bus_ops {
+       u8 (*read8)(struct ssb_device *dev, u16 offset);
        u16 (*read16)(struct ssb_device *dev, u16 offset);
        u32 (*read32)(struct ssb_device *dev, u16 offset);
+       void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
        void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
        void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
+#ifdef CONFIG_SSB_BLOCKIO
+       void (*block_read)(struct ssb_device *dev, void *buffer,
+                          size_t count, u16 offset, u8 reg_width);
+       void (*block_write)(struct ssb_device *dev, const void *buffer,
+                           size_t count, u16 offset, u8 reg_width);
+#endif
 };
 
 
@@ -129,9 +137,6 @@ struct ssb_device {
        const struct ssb_bus_ops *ops;
 
        struct device *dev;
-       /* Pointer to the device that has to be used for
-        * any DMA related operation. */
-       struct device *dma_dev;
 
        struct ssb_bus *bus;
        struct ssb_device_id id;
@@ -247,9 +252,9 @@ struct ssb_bus {
        /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
        struct pcmcia_device *host_pcmcia;
 
-#ifdef CONFIG_SSB_PCIHOST
+#ifdef CONFIG_SSB_SPROM
        /* Mutex to protect the SPROM writing. */
-       struct mutex pci_sprom_mutex;
+       struct mutex sprom_mutex;
 #endif
 
        /* ID information about the Chip. */
@@ -262,9 +267,6 @@ struct ssb_bus {
        struct ssb_device devices[SSB_MAX_NR_CORES];
        u8 nr_devices;
 
-       /* Reference count. Number of suspended devices. */
-       u8 suspend_cnt;
-
        /* Software ID number for this bus. */
        unsigned int busnumber;
 
@@ -336,6 +338,13 @@ extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
 
 extern void ssb_bus_unregister(struct ssb_bus *bus);
 
+/* Suspend a SSB bus.
+ * Call this from the parent bus suspend routine. */
+extern int ssb_bus_suspend(struct ssb_bus *bus);
+/* Resume a SSB bus.
+ * Call this from the parent bus resume routine. */
+extern int ssb_bus_resume(struct ssb_bus *bus);
+
 extern u32 ssb_clockspeed(struct ssb_bus *bus);
 
 /* Is the device enabled in hardware? */
@@ -348,6 +357,10 @@ void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
 
 
 /* Device MMIO register read/write functions. */
+static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
+{
+       return dev->ops->read8(dev, offset);
+}
 static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
 {
        return dev->ops->read16(dev, offset);
@@ -356,6 +369,10 @@ static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
 {
        return dev->ops->read32(dev, offset);
 }
+static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
+{
+       dev->ops->write8(dev, offset, value);
+}
 static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
 {
        dev->ops->write16(dev, offset, value);
@@ -364,7 +381,24 @@ static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
 {
        dev->ops->write32(dev, offset, value);
 }
+#ifdef CONFIG_SSB_BLOCKIO
+static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
+                                 size_t count, u16 offset, u8 reg_width)
+{
+       dev->ops->block_read(dev, buffer, count, offset, reg_width);
+}
 
+static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
+                                  size_t count, u16 offset, u8 reg_width)
+{
+       dev->ops->block_write(dev, buffer, count, offset, reg_width);
+}
+#endif /* CONFIG_SSB_BLOCKIO */
+
+
+/* The SSB DMA API. Use this API for any DMA operation on the device.
+ * This API basically is a wrapper that calls the correct DMA API for
+ * the host device type the SSB device is attached to. */
 
 /* Translation (routing) bits that need to be ORed to DMA
  * addresses before they are given to a device. */
@@ -372,7 +406,141 @@ extern u32 ssb_dma_translation(struct ssb_device *dev);
 #define SSB_DMA_TRANSLATION_MASK       0xC0000000
 #define SSB_DMA_TRANSLATION_SHIFT      30
 
-extern int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask);
+extern int ssb_dma_set_mask(struct ssb_device *dev, u64 mask);
+
+extern void * ssb_dma_alloc_consistent(struct ssb_device *dev, size_t size,
+                                      dma_addr_t *dma_handle, gfp_t gfp_flags);
+extern void ssb_dma_free_consistent(struct ssb_device *dev, size_t size,
+                                   void *vaddr, dma_addr_t dma_handle,
+                                   gfp_t gfp_flags);
+
+static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
+{
+#ifdef CONFIG_SSB_DEBUG
+       printk(KERN_ERR "SSB: BUG! Calling DMA API for "
+              "unsupported bustype %d\n", dev->bus->bustype);
+#endif /* DEBUG */
+}
+
+static inline int ssb_dma_mapping_error(struct ssb_device *dev, dma_addr_t addr)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               return pci_dma_mapping_error(addr);
+       case SSB_BUSTYPE_SSB:
+               return dma_mapping_error(addr);
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+       return -ENOSYS;
+}
+
+static inline dma_addr_t ssb_dma_map_single(struct ssb_device *dev, void *p,
+                                           size_t size, enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               return pci_map_single(dev->bus->host_pci, p, size, dir);
+       case SSB_BUSTYPE_SSB:
+               return dma_map_single(dev->dev, p, size, dir);
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+       return 0;
+}
+
+static inline void ssb_dma_unmap_single(struct ssb_device *dev, dma_addr_t dma_addr,
+                                       size_t size, enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               pci_unmap_single(dev->bus->host_pci, dma_addr, size, dir);
+               return;
+       case SSB_BUSTYPE_SSB:
+               dma_unmap_single(dev->dev, dma_addr, size, dir);
+               return;
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+}
+
+static inline void ssb_dma_sync_single_for_cpu(struct ssb_device *dev,
+                                              dma_addr_t dma_addr,
+                                              size_t size,
+                                              enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
+                                           size, dir);
+               return;
+       case SSB_BUSTYPE_SSB:
+               dma_sync_single_for_cpu(dev->dev, dma_addr, size, dir);
+               return;
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+}
+
+static inline void ssb_dma_sync_single_for_device(struct ssb_device *dev,
+                                                 dma_addr_t dma_addr,
+                                                 size_t size,
+                                                 enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
+                                              size, dir);
+               return;
+       case SSB_BUSTYPE_SSB:
+               dma_sync_single_for_device(dev->dev, dma_addr, size, dir);
+               return;
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+}
+
+static inline void ssb_dma_sync_single_range_for_cpu(struct ssb_device *dev,
+                                                    dma_addr_t dma_addr,
+                                                    unsigned long offset,
+                                                    size_t size,
+                                                    enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               /* Just sync everything. That's all the PCI API can do. */
+               pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
+                                           offset + size, dir);
+               return;
+       case SSB_BUSTYPE_SSB:
+               dma_sync_single_range_for_cpu(dev->dev, dma_addr, offset,
+                                             size, dir);
+               return;
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+}
+
+static inline void ssb_dma_sync_single_range_for_device(struct ssb_device *dev,
+                                                       dma_addr_t dma_addr,
+                                                       unsigned long offset,
+                                                       size_t size,
+                                                       enum dma_data_direction dir)
+{
+       switch (dev->bus->bustype) {
+       case SSB_BUSTYPE_PCI:
+               /* Just sync everything. That's all the PCI API can do. */
+               pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
+                                              offset + size, dir);
+               return;
+       case SSB_BUSTYPE_SSB:
+               dma_sync_single_range_for_device(dev->dev, dma_addr, offset,
+                                                size, dir);
+               return;
+       default:
+               __ssb_dma_not_implemented(dev);
+       }
+}
 
 
 #ifdef CONFIG_SSB_PCIHOST
@@ -416,5 +584,12 @@ extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
 extern u32 ssb_admatch_base(u32 adm);
 extern u32 ssb_admatch_size(u32 adm);
 
+/* PCI device mapping and fixup routines.
+ * Called from the architecture pcibios init code.
+ * These are only available on SSB_EMBEDDED configurations. */
+#ifdef CONFIG_SSB_EMBEDDED
+int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
+int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
+#endif /* CONFIG_SSB_EMBEDDED */
 
 #endif /* LINUX_SSB_H_ */