The Pedigree Project  0.1
Dma.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef DMA_H
21 #define DMA_H
22 
23 #include "nv_macros.h"
24 #include "pedigree/kernel/processor/MemoryMappedIo.h"
25 #include "pedigree/kernel/processor/MemoryRegion.h"
26 
27 /* FIFO channels */
28 #define NV_GENERAL_FIFO_CH0 0x0000
29 #define NV_GENERAL_FIFO_CH1 0x2000
30 #define NV_GENERAL_FIFO_CH2 0x4000
31 #define NV_GENERAL_FIFO_CH3 0x6000
32 #define NV_GENERAL_FIFO_CH4 0x8000
33 #define NV_GENERAL_FIFO_CH5 0xa000
34 #define NV_GENERAL_FIFO_CH6 0xc000
35 #define NV_GENERAL_FIFO_CH7 0xe000
36 
37 /* sub-command offsets within FIFO channels */
38 #define NV_GENERAL_DMAPUT 0x0040
39 #define NV_GENERAL_DMAGET 0x0044
40 #define NV_ROP5_SOLID_SETROP5 0x0300
41 #define NV_IMAGE_BLACK_RECTANGLE_TOPLEFT 0x0300
42 #define NV_IMAGE_PATTERN_SETCOLORFORMAT 0x0300
43 #define NV_IMAGE_PATTERN_SETSHAPE 0x0308
44 #define NV_IMAGE_PATTERN_SETCOLOR0 0x0310
45 #define NV_IMAGE_BLIT_SOURCEORG 0x0300
46 #define NV4_GDI_RECTANGLE_TEXT_SETCOLORFORMAT 0x0300
47 #define NV4_GDI_RECTANGLE_TEXT_COLOR1A 0x03fc
48 #define NV4_GDI_RECTANGLE_TEXT_UCR0_LEFTTOP 0x0400
49 #define NV4_SURFACE_FORMAT 0x0300
50 #define NV_SCALED_IMAGE_FROM_MEMORY_SETCOLORFORMAT 0x0300
51 #define NV_SCALED_IMAGE_FROM_MEMORY_SOURCEORG 0x0308
52 #define NV_SCALED_IMAGE_FROM_MEMORY_SOURCESIZE 0x0400
53 
54 /* handles to pre-defined engine commands */
55 #define NV_ROP5_SOLID 0x00000000 /* 2D */
56 #define NV_IMAGE_BLACK_RECTANGLE 0x00000001 /* 2D/3D */
57 #define NV_IMAGE_PATTERN 0x00000002 /* 2D */
58 #define NV_SCALED_IMAGE_FROM_MEMORY 0x00000003 /* 2D */
59 #define NV_TCL_PRIMITIVE_3D 0x00000004 /* 3D */ // 2007
60 #define NV4_SURFACE 0x00000010 /* 2D */
61 #define NV10_CONTEXT_SURFACES_2D 0x00000010 /* 2D */
62 #define NV_IMAGE_BLIT 0x00000011 /* 2D */
63 #define NV12_IMAGE_BLIT 0x00000011 /* 2D */
64 #define NV4_GDI_RECTANGLE_TEXT 0x00000012 /* 2D */
65 #define NV4_CONTEXT_SURFACES_ARGB_ZS 0x00000013 /* 3D */
66 #define NV10_CONTEXT_SURFACES_ARGB_ZS 0x00000013 /* 3D */
67 #define NV4_DX5_TEXTURE_TRIANGLE 0x00000014 /* 3D */
68 #define NV10_DX5_TEXTURE_TRIANGLE 0x00000014 /* 3D */
69 #define NV4_DX6_MULTI_TEXTURE_TRIANGLE 0x00000015 /* unused (yet?) */
70 #define NV10_DX6_MULTI_TEXTURE_TRIANGLE 0x00000015 /* unused (yet?) */
71 #define NV1_RENDER_SOLID_LIN 0x00000016 /* 2D: unused */
72 
73 /* card_type in order of date of NV chip design */
74 enum NvType
75 {
76  NV04 = 0,
77  NV05,
78  NV05M64,
79  NV06,
80  NV10,
81  NV11,
82  NV11M,
83  NV15,
84  NV17,
85  NV17M,
86  NV18,
87  NV18M,
88  NV20,
89  NV25,
90  NV28,
91  NV30,
92  NV31,
93  NV34,
94  NV35,
95  NV36,
96  NV38,
97  NV40,
98  NV41,
99  NV43,
100  NV44,
101  NV45,
102  G70,
103  G71,
104  G72,
105  G73
106 };
107 
108 /* card_arch in order of date of NV chip design */
109 enum NvCard
110 {
111  NV04A = 0,
112  NV10A,
113  NV20A,
114  NV30A,
115  NV40A
116 };
117 
118 class Dma
119 {
120  public:
121  Dma(IoBase *pRegs, IoBase *pFb, NvCard card, NvType type,
122  uintptr_t ramSize);
123  ~Dma();
124  void init();
125  void screenToScreenBlit(
126  uint16_t src_x, uint16_t src_y, uint16_t dest_x, uint16_t dest_y,
127  uint16_t h, uint16_t w);
128  void fillRectangle(uint16_t x, uint16_t y, uint16_t h, uint16_t w);
129 
130  private:
131  Dma(const Dma &);
132  Dma &operator=(const Dma &);
133 
134  void dmaCmd(uint32_t cmd, uint32_t offset, uint16_t size);
135  void writeBuffer(uint32_t arg);
136  void start();
137  void ensureFree(uint16_t cmd_size);
138  void initFifo(uint32_t ch, uint32_t handle);
139  void setUpReverseEngineeredMagicRegs();
140 
141  IoBase *m_pRegs;
142  IoBase *m_pFramebuffer;
143  NvCard m_Card;
144  NvType m_Type;
145  uintptr_t m_nRamSize;
146 
147  uint32_t m_pFifos[32];
148  uint32_t m_pFifoPtrs[32];
149 
150  uintptr_t m_nDmaBuffer;
151  uint32_t *m_pDmaBuffer;
152  MemoryRegion m_DmaBuffer;
153  uintptr_t m_nPut;
154  uintptr_t m_nCurrent;
155  uintptr_t m_nMax;
156  uintptr_t m_nFree;
157 };
158 
159 #endif
Definition: cmd.h:30
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
Definition: Dma.h:118
Special memory entity in the kernel's virtual address space.
Definition: MemoryRegion.h:35