ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
dma.c File Reference
#include <errno.h>
#include <stdio.h>
#include <kernel.h>
#include <libgs.h>
#include "internal.h"
+ Include dependency graph for dma.c:

Go to the source code of this file.

Data Structures

struct  DMA_CHCR
 

Macros

#define gif_chcr   0x1000a000
 
#define gif_madr   0x1000a010
 
#define gif_qwc   0x1000a020
 
#define gif_tadr   0x1000a030
 
#define DMA_TAG_REFE   0x00
 
#define DMA_TAG_CNT   0x01
 
#define DMA_TAG_NEXT   0x02
 
#define DMA_TAG_REF   0x03
 
#define DMA_TAG_REFS   0x04
 
#define DMA_TAG_CALL   0x05
 
#define DMA_TAG_RET   0x06
 
#define DMA_TAG_END   0x07
 

Functions

void GsDmaInit (void)
 
void GsDmaSend (const void *addr, u32 qwords)
 
void GsDmaSend_tag (const void *addr, u32 qwords, const GS_GIF_DMACHAIN_TAG *tag)
 
void GsDmaWait (void)
 

Macro Definition Documentation

◆ DMA_TAG_CALL

#define DMA_TAG_CALL   0x05

Definition at line 33 of file dma.c.

◆ DMA_TAG_CNT

#define DMA_TAG_CNT   0x01

Definition at line 29 of file dma.c.

◆ DMA_TAG_END

#define DMA_TAG_END   0x07

Definition at line 35 of file dma.c.

◆ DMA_TAG_NEXT

#define DMA_TAG_NEXT   0x02

Definition at line 30 of file dma.c.

◆ DMA_TAG_REF

#define DMA_TAG_REF   0x03

Definition at line 31 of file dma.c.

◆ DMA_TAG_REFE

#define DMA_TAG_REFE   0x00

Definition at line 28 of file dma.c.

◆ DMA_TAG_REFS

#define DMA_TAG_REFS   0x04

Definition at line 32 of file dma.c.

◆ DMA_TAG_RET

#define DMA_TAG_RET   0x06

Definition at line 34 of file dma.c.

◆ gif_chcr

#define gif_chcr   0x1000a000

GIF Channel Control Register

Definition at line 21 of file dma.c.

◆ gif_madr

#define gif_madr   0x1000a010

Transfer Address Register

Definition at line 23 of file dma.c.

◆ gif_qwc

#define gif_qwc   0x1000a020

Transfer Size Register (in qwords)

Definition at line 25 of file dma.c.

◆ gif_tadr

#define gif_tadr   0x1000a030

Definition at line 26 of file dma.c.

Function Documentation

◆ GsDmaInit()

void GsDmaInit ( void  )

Definition at line 58 of file dma.c.

59 {
60  /* This appears to have been based on code from Sony that initializes DMA channels 0-9, in bulk.
61  Reset/init DMA CH 2 (GIF) only. */
62  __asm__(
63  "li $2,0x1000A000 \n"
64  "sw $0,0x80($2) \n" // D2_SADR = 0. Documented to not exist, but is done.
65  "sw $0,0($2) \n" // D2_CHCR = 0
66  "sw $0,0x30($2) \n" // D2_TADR = 0
67  "sw $0,0x10($2) \n" // D2_MADR = 0
68  "sw $0,0x50($2) \n" // D2_ASR1 = 0
69  "sw $0,0x40($2) \n" // D2_ASR0 = 0
70  "li $2,0xFF1F \n" // Clear all interrupt status under D_STAT, other than SIF0, SIF1 & SIF2.
71  "sw $2,0x1000E010 \n"
72  "lw $2,0x1000E010 \n"
73  "lui $3,0xFF1F \n" // Clear all interrupt masks under D_STAT, other SIF0, SIF1 & SIF2. Writing a 1 reverses the bit.
74  "and $2,$3 \n"
75  "sw $2,0x1000E010 \n"
76  "sw $0,0x1000E000 \n" // D_CTRL = 0
77  "sw $0,0x1000E020 \n" // D_PCR = 0
78  "sw $0,0x1000E030 \n" // D_SQWC = 0
79  "sw $0,0x1000E050 \n" // D_RBOR = 0
80  "sw $0,0x1000E040 \n" // D_RBSR = 0
81  "li $3,1 \n"
82  "lw $2,0x1000E000 \n"
83  "ori $3,$2,1 \n" // D_CTRL (DMAE 1)
84  "sw $3,0x1000E000 \n"
85  );
86 }

Referenced by GsResetGraph().

◆ GsDmaSend()

void GsDmaSend ( const void *  addr,
u32  qwords 
)

Definition at line 88 of file dma.c.

89 {
90  DMA_CHCR chcr;
91  static char spr;
92 
93  if((u32)addr >= 0x70000000 && (u32)addr <= 0x70003fff)
94  {
95  spr = 1;
96  }
97  else
98  {
99  spr = 0;
100  }
101 
102  *((vu32 *)(gif_madr)) = ( u32 )((( u32 )addr) & 0x7FFFFFFF) << 0 | (u32)((spr) & 0x00000001) << 31;;
103 
104  *((vu32 *)(gif_qwc)) = qwords;
105 
106  chcr.direction =1;
107  chcr.mode =0;
108  chcr.asp =0;
109  chcr.tte =0;
110  chcr.tie =0;
111  chcr.start_flag =1;
112  chcr.tag =0;
113  chcr.pad1 =0;
114  chcr.pad2 =0;
115  *((volatile DMA_CHCR *)(gif_chcr)) = chcr;
116 }
#define gif_madr
Definition: dma.c:23
#define gif_chcr
Definition: dma.c:21
#define gif_qwc
Definition: dma.c:25
Definition: dma.c:37
unsigned direction
Definition: dma.c:39
unsigned tag
Definition: dma.c:55
unsigned tte
Definition: dma.c:47
unsigned pad1
Definition: dma.c:41
unsigned tie
Definition: dma.c:49
unsigned start_flag
Definition: dma.c:51
unsigned mode
Definition: dma.c:43
unsigned pad2
Definition: dma.c:53
unsigned asp
Definition: dma.c:45
unsigned int u32
Definition: tamtypes.h:30
volatile u32 vu32
Definition: tamtypes.h:38

References DMA_CHCR::asp, DMA_CHCR::direction, gif_chcr, gif_madr, gif_qwc, DMA_CHCR::mode, DMA_CHCR::pad1, DMA_CHCR::pad2, DMA_CHCR::start_flag, DMA_CHCR::tag, DMA_CHCR::tie, and DMA_CHCR::tte.

Referenced by GsClearDrawEnv1(), GsClearDrawEnv2(), GsEnableAlphaBlending1(), GsEnableAlphaBlending2(), GsEnableAlphaTransparency1(), GsEnableAlphaTransparency2(), GsEnableColorClamp(), GsEnableDithering(), GsLoadImage(), GsOverridePrimAttributes(), GsPutZBufferEnv1(), GsPutZBufferEnv2(), GsSelectTexure1(), GsSelectTexure2(), GsSetFogColor(), GsSetFrame1(), GsSetFrame2(), GsSetPixelTest1(), GsSetPixelTest2(), GsSetScissor1(), GsSetScissor2(), GsSetXYOffset1(), GsSetXYOffset2(), and GsTextureFlush().

◆ GsDmaSend_tag()

void GsDmaSend_tag ( const void *  addr,
u32  qwords,
const GS_GIF_DMACHAIN_TAG tag 
)

Definition at line 118 of file dma.c.

119 {
120  DMA_CHCR chcr;
121  static char spr;
122 
123  if((u32)addr >= 0x70000000 && (u32)addr <= 0x70003fff)
124  {
125  spr = 1;
126  }
127  else
128  {
129  spr = 0;
130  }
131 
132  *((vu32 *)(gif_madr)) = ( u32 )((( u32 )addr) & 0x7FFFFFFF) << 0 | (u32)((spr) & 0x00000001) << 31;
133  *((vu32 *)(gif_qwc)) = qwords;
134  *((vu32 *)(gif_tadr)) = ( u32 )((( u32 )tag) & 0x7FFFFFFF) << 0 | (u32)((0) & 0x00000001) << 31;
135 
136  chcr.direction =1;
137  chcr.mode =1; //chain
138  chcr.asp =0;
139  chcr.tte =0;
140  chcr.tie =0;
141  chcr.start_flag =1;
142  chcr.tag =0;
143  chcr.pad1 =0;
144  chcr.pad2 =0;
145  *((volatile DMA_CHCR *)(gif_chcr)) = chcr;
146 }
#define gif_tadr
Definition: dma.c:26

References DMA_CHCR::asp, DMA_CHCR::direction, gif_chcr, gif_madr, gif_qwc, gif_tadr, DMA_CHCR::mode, DMA_CHCR::pad1, DMA_CHCR::pad2, DMA_CHCR::start_flag, DMA_CHCR::tag, DMA_CHCR::tie, and DMA_CHCR::tte.

Referenced by GsGifPacketsExecute().

◆ GsDmaWait()